"""Capture read-only online entry evidence and approved original reference states.""" import argparse import hashlib import json import os from pathlib import Path from playwright.sync_api import sync_playwright p=argparse.ArgumentParser() p.add_argument('--output',type=Path,required=True) p.add_argument('--references',type=Path,required=True) a=p.parse_args();out=a.output.resolve();refs=a.references.resolve() report={'blocked':[],'online':[],'reference':[],'errors':[]} with sync_playwright() as pw: b=pw.chromium.launch(args=['--no-sandbox'],env={**os.environ,'LD_LIBRARY_PATH':'/home/xiaomo/pwlibs/root/usr/lib/x86_64-linux-gnu'}) try: ctx=b.new_context(viewport={'width':1440,'height':900}) ctx.add_init_script("localStorage.setItem('aigc-theme','night');localStorage.setItem('aigc-motion','off');localStorage.setItem('aigc-lang','zh')") def guard(route): r=route.request if r.method not in ['GET','HEAD'] or '/api/canvas' in r.url or not r.url.startswith('http://192.168.200.15:8080/'): report['blocked'].append({'method':r.method,'url':r.url});route.abort() else:route.continue_() ctx.route('**/*',guard) page=ctx.new_page();page.on('pageerror',lambda e:report['errors'].append(str(e))) for name,path,ready in [('create','/create?kind=image','#desk-prompt'),('library','/library','.lib-body')]: page.goto('http://192.168.200.15:8080'+path);page.locator(ready).wait_for();page.wait_for_timeout(1000) page.screenshot(path=str(out/f'online-{name}-night-1440.png')) report['online'].append({'name':name,'url':page.url,'theme':page.locator('html').get_attribute('data-theme'),'motion':page.locator('html').get_attribute('data-motion'),'resources':page.evaluate('performance.getEntriesByType("resource").filter(r=>r.initiatorType==="script"||r.initiatorType==="link").map(r=>r.name)')}) ctx.close() ctx=b.new_context();ctx.route('https://**/*',lambda r:r.abort());s=ctx.new_page() originals=[('desk',refs/'夜片场-多主题交互样本.html','?still=1#create/image'),('library',refs/'extracted/HEL-837-交互样本-v2.html','?still=1#library'),('canvas',refs/'canvas-sample.html','?chrome=0&reduce=1')] for label,file,query in originals: for width,height in [(1440,900),(1366,768),(1280,720)]: s.set_viewport_size({'width':width,'height':height}) for theme in ['night','day','grade','bluehour']: s.goto(file.as_uri()+query) s.evaluate('(t)=>document.documentElement.dataset.theme=t',theme) if label=='desk': # Map only the empty-result state, never alter reference CSS. s.evaluate("st.hist.image=[];st.fills={};st.viewing=null;renderCreate()") s.wait_for_timeout(300) s.screenshot(path=str(out/f'approved-{label}-{theme}-{width}.png'),animations='disabled') tokens=s.evaluate("()=>Object.fromEntries(['--bg-0','--bg-1','--bg-2','--tx-1','--tx-2','--board-bg','--board-dot','--rail','--head'].map(t=>[t,getComputedStyle(document.documentElement).getPropertyValue(t).trim()]))") report['reference'].append({'label':label,'theme':theme,'width':width,'file_sha256':hashlib.sha256(file.read_bytes()).hexdigest(),'tokens':tokens,'state':'empty result/history' if label=='desk' else 'original demonstration data'}) ctx.close() finally:b.close() (out/'readonly-report.json').write_text(json.dumps(report,ensure_ascii=False,indent=2)) print('online entries',len(report['online']),'approved screenshots',len(report['reference']),'JS errors',report['errors'])