browser_check.py

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

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

import os,pathlib,json,hashlib
from playwright.sync_api import sync_playwright
w=pathlib.Path(os.environ['TMPDIR']);parts=json.loads((w/'preview-fetch.json').read_text())
results={'method':'Live NumberDB preview renderer on exact stored document sections; no browser credentials',
         'private_table_anonymous_status':404,'request_line_limit':4094,'parts':{},'failures':[]}
with sync_playwright() as p:
    browser=p.chromium.launch(headless=True,args=['--no-sandbox'])
    page=browser.new_page(viewport={'width':1500,'height':1000},device_scale_factor=1)
    errors=[]
    page.on('pageerror',lambda e:errors.append(str(e)))
    for name in parts:
        raw=(w/('preview-'+name+'.html')).read_text()
        page.route('https://numberdb.org/preview',lambda route,request,body=raw:route.fulfill(status=200,content_type='text/html',body=body))
        page.goto('https://numberdb.org/preview',wait_until='networkidle')
        page.wait_for_function('window.MathJax && MathJax.startup && MathJax.startup.promise')
        page.evaluate('MathJax.startup.promise.then(() => MathJax.typesetPromise())')
        # The preview form precedes the actual rendered table. Scroll to it.
        page.locator('#preview-header').scroll_into_view_if_needed()
        screenshot=w/('preview-'+name+'.png');page.screenshot(path=str(screenshot),full_page=True)
        visible=page.locator('body').inner_text()
        (w/('preview-'+name+'.txt')).write_text(visible)
        result={'math_errors':page.locator('mjx-merror').count(),'math_objects':page.locator('mjx-container').count(),
                'javascript_errors':list(errors),'screenshot_sha256':hashlib.sha256(screenshot.read_bytes()).hexdigest()}
        if name=='relations':
            result['companion_links']={tid:page.locator('a.HREF[href="'+tid+'"]').count() for tid in ['T31','T34','T16','T757']}
            result['relations_visible']=all(text in visible for text in ['gamma-factor trend','finite signed binomial transform','regularized function','distinct finite transform'])
            result['cited_references_present']=all(page.locator('#'+key).count()==1 for key in ['Maslanka','Coffey'])
            if not all(result['companion_links'].values()) or not result['relations_visible'] or not result['cited_references_present']:results['failures'].append('Missing relationship/reference')
        if result['math_errors']:results['failures'].append(name+' MathJax error')
        results['parts'][name]=result
        page.unroute('https://numberdb.org/preview')
    browser.close()
(w/'presentation-results.json').write_text(json.dumps(results,indent=2))
print(json.dumps(results))
assert not results['failures']