browser_check.py

back to table · edit · history · where entries came from · files · download

3314 bytes, as of the version from 2026-11-18 20:44 (current). Recorded here, not run.

"""Inspect every part of the server-rendered stored document, without a key."""
import asyncio,json,os,hashlib,importlib.metadata
from pathlib import Path
from playwright.async_api import async_playwright
w=Path(os.environ['TMPDIR'])
async def main():
 async with async_playwright() as p:
  browser=await p.chromium.launch(headless=True,args=['--no-sandbox'])
  page=await browser.new_page(viewport={'width':1440,'height':1100},device_scale_factor=1)
  errors=[];page.on('pageerror',lambda e:errors.append(str(e)))
  await page.set_content((w/'rendered-complete.html').read_text(),wait_until='networkidle')
  await page.evaluate('''async()=>{if(window.MathJax && MathJax.typesetPromise) await MathJax.typesetPromise(); else if(window.MathJax && MathJax.Hub) await new Promise(r=>MathJax.Hub.Queue(r));}''')
  await page.evaluate("document.querySelectorAll('details').forEach(x=>x.open=true)")
  text=await page.locator('body').inner_text();(w/'rendered-complete.txt').write_text(text)
  (w/'browser-dom.html').write_text(await page.content())
  await page.locator('#table-title').scroll_into_view_if_needed()
  await page.screenshot(path=str(w/'render-top.png'),full_page=False)
  for label,heading in [('formulas','Formulas'),('relations','Similar tables'),('programs','Programs'),('properties','Data properties')]:
   loc=page.get_by_text(heading,exact=True).first;await loc.scroll_into_view_if_needed();await page.screenshot(path=str(w/('render-'+label+'.png')),full_page=False)
  await page.locator('[id="1-1-1"]').scroll_into_view_if_needed();await page.screenshot(path=str(w/'render-first-rows.png'),full_page=False)
  await page.locator('[id="65-72-97"]').scroll_into_view_if_needed();await page.screenshot(path=str(w/'render-last-rows.png'),full_page=False)
  visible_numbers=await page.locator('.table-cell-right.table-number').evaluate_all('(a)=>a.filter(x=>x.innerText.trim().length>40 && x.offsetHeight>0).length')
  row_count=await page.locator('.table-cell-right.table-number').count()
  doc=json.loads((w/'stored.json').read_text());ids=list(doc['Numbers'])
  missing_ids=[x for x in ids if await page.locator('[id="'+x+'"]').count()!=1]
  links=await page.locator('a').evaluate_all('(a)=>a.map(x=>({text:x.innerText,href:x.getAttribute("href")}))')
  relations=[x for x in links if x['href'] and any(x['href'].lstrip('/').split('?')[0]==tid for tid in ('T283','T730','T175','T153','T685','T686','T522'))]
  r={'visible_number_rows':visible_numbers,'fontconfig_file':os.environ.get('FONTCONFIG_FILE'),'row_count':row_count,'missing_identities':missing_ids,'relations':relations,'mathjax_errors':await page.locator('mjx-merror,.mjx-merror,.katex-error').count(),'page_errors':errors,'playwright':importlib.metadata.version('playwright'),'browser':browser.version,'method':'Live server preview by exact stored sections and row batches, combined into a full local page after the full GET preview was refused with HTTP 414. No authenticated draft page chrome was inspected.','stored_sha256':hashlib.sha256((w/'stored.json').read_bytes()).hexdigest()}
  (w/'browser-results.json').write_text(json.dumps(r,indent=2));print(json.dumps(r,indent=2));assert visible_numbers==84 and row_count==84 and not missing_ids and len(relations)>=7 and r['mathjax_errors']==0
  await browser.close()
asyncio.run(main())