"""One confirmation of disconnected-SSR-node measurements and viewport zoom captures.""" from pathlib import Path import json from playwright.sync_api import sync_playwright from browser_zoom import zoom_browser,set_browser_zoom ORIGIN='http://127.0.0.1:5199' OUT=Path(__file__).parent/'scadabridge-confirmation';OUT.mkdir(exist_ok=True) results=[] with sync_playwright() as p: with zoom_browser(p,width=1440,height=1000) as (context,worker): for width,scheme,kind,zoom in [(w,s,'root',1) for w in (1440,1024,390) for s in ('light','dark')]+[(1440,s,'login',1) for s in ('light','dark')]+[(1440,s,'root',2) for s in ('light','dark')]: page=context.new_page();page.set_viewport_size({'width':width,'height':1000});page.emulate_media(reduced_motion='reduce',color_scheme=scheme) route='/login' if kind=='login' else '/';page.goto(ORIGIN+route,wait_until='domcontentloaded') # Selecting the current element and reading styles in one synchronous JS call # avoids holding a prerender node while Blazor swaps it during hydration. motion=page.evaluate('''s=>{const e=document.querySelector(s);if(!e)return {missing:true};const c=getComputedStyle(e);return {connected:e.isConnected,animationName:c.animationName,animationDuration:c.animationDuration,opacity:c.opacity,transform:c.transform,reduced:matchMedia('(prefers-reduced-motion: reduce)').matches};}''','.login-wrap.rise' if kind=='login' else '#canary-rise') page.wait_for_load_state('networkidle');page.evaluate('s=>window.sbTheme.set(s)',scheme) record={'width':width,'scheme':scheme,'kind':kind,'zoom':zoom,'immediateMotion':motion,'passed':motion.get('connected') and motion.get('reduced') and motion.get('opacity')=='1' and motion.get('animationName')=='none'} if zoom==2: record['browserZoom']=set_browser_zoom(worker,page,2) record['actualLayout']=page.evaluate('({innerWidth,scrollWidth:document.documentElement.scrollWidth,DPR:devicePixelRatio})') record['passed']=record['passed'] and record['actualLayout']=={'innerWidth':720,'scrollWidth':720,'DPR':2} record['screenshot']=f'{kind}-{scheme}-{width}-zoom2-viewport.png' page.screenshot(path=str(OUT/record['screenshot']),full_page=False) if kind=='root': record['actualPairs']=page.evaluate('''()=>{let pairs={};for(const [name,s] of Object.entries({primary:'#canary-busy-success',hint:'#canary-field-hint',error:'#canary-field-error'})){const e=document.querySelector(s);const c=getComputedStyle(e);let p=e,bg;while(p){const pc=getComputedStyle(p);if(pc.backgroundColor!=='rgba(0, 0, 0, 0)'&&pc.backgroundColor!=='transparent'){bg=pc.backgroundColor;break;}p=p.parentElement;}pairs[name]={color:c.color,background:bg,opacity:c.opacity};}return pairs;}''') results.append(record) if zoom==2:set_browser_zoom(worker,page,1) page.close() (OUT/'results.json').write_text(json.dumps({'reason':'First-pass nine empty CSS results came from detached SSR nodes; no product/UI code change. Full-page capture at real zoom replaced by viewport capture.','results':results,'allPassed':all(x['passed'] for x in results)},indent=2)+'\n') print('Confirmation cases',len(results),'passed',sum(x['passed'] for x in results),'failed',sum(not x['passed'] for x in results))