import asyncio,sys,time from playwright.async_api import async_playwright wav,sound,usemic=sys.argv[1],sys.argv[2],sys.argv[3]=='1' async def main(): async with async_playwright() as p: b=await p.chromium.launch(args=['--autoplay-policy=no-user-gesture-required','--use-fake-device-for-media-stream','--use-fake-ui-for-media-stream',f'--use-file-for-fake-audio-capture=/tmp/fakemic/{wav}.wav']) pg=await b.new_page(viewport={'width':393,'height':700}) errs=[];pg.on('pageerror',lambda e:errs.append(str(e))) await pg.goto('http://localhost:8771/index.html') await pg.evaluate(f"localStorage.clear();localStorage.setItem('squad1_sounds',JSON.stringify(['{sound}']));localStorage.setItem('squad1_mic',{'true' if usemic else 'false'})") await pg.reload();await pg.wait_for_timeout(300) await pg.evaluate("document.getElementById('startBtn').click()");await pg.wait_for_timeout(1200) await pg.evaluate("document.getElementById('playBtn').click()") t0=time.time();last=None;log=[] while time.time()-t0<420: await pg.wait_for_timeout(500) st=await pg.evaluate("[J.round,J.station,($('.screen.on')||{}).id,$('#cap').textContent,mic.state]") if st[:3]!=last: log.append((round(time.time()-t0,1),st[:3],st[3][:50]));last=st[:3] if st[0]>=1: break await pg.evaluate("""(()=>{const d=$('#door.wiggle');if(d)d.click();const bx=$('#box.shake');if(bx)bx.click(); const h=$('.whoBtn.hint');if(h)h.click();else{const bs=$$('.whoBtn');if(bs.length&&whoPick)bs[Math.random()*bs.length|0].click()} const c=$$('#mirrorCtl .btn,#feedCtl .btn');if(c.length)c[0].click();})()""") if not usemic: await pg.evaluate("(()=>{const t=$('#turn');})()") # hold button for power play when no mic on=await pg.evaluate("PW.active&&!speaking") if on: await pg.evaluate("PW.holding=true") for l in log: print(l) print('errors',errs[:5],'stars',await pg.evaluate("state.stars"),'time',round(time.time()-t0)) await b.close() asyncio.run(main())