import asyncio,json
from pathlib import Path
from playwright.async_api import async_playwright
async def main():
 async with async_playwright() as p:
  browser=await p.chromium.launch(headless=True,args=['--no-sandbox','--use-angle=swiftshader','--enable-webgl','--ignore-gpu-blocklist'])
  page=await browser.new_page(viewport={'width':1600,'height':1000},device_scale_factor=1)
  errors=[];page.on('pageerror',lambda e:errors.append(str(e)))
  import sys
  file=sys.argv[1] if len(sys.argv)>1 else 'tideglass-ruin-arch-portal.glb'
  await page.goto('http://127.0.0.1:8846/jobs/tideglass-ruin-arch-portal-v2/runtime-check.html?file='+file)
  await page.wait_for_function('window.ready===true',timeout=120000)
  for mode in ['hero','rear','close']:
   await page.evaluate('(m)=>window.view(m)',mode);await page.screenshot(path='runtime-'+mode+'.png')
  result=await page.evaluate('window.result');result['errors']=errors
  Path('runtime-check.json').write_text(json.dumps(result,indent=2));print(result)
  await browser.close()
asyncio.run(main())
