import asyncio, json
from playwright.async_api import async_playwright
URL='http://localhost:8090/DOZIKWORKS_OS_v5_locked.dc.html'
async def main():
    async with async_playwright() as p:
        br=await p.chromium.launch(channel='msedge',headless=True)
        pg=await br.new_page(viewport={'width':1536,'height':864})
        await pg.goto(URL); await pg.wait_for_timeout(30000)
        info=await pg.evaluate("""()=>{const a=window.__dzw,T=a._T;
          a.setJoints({S:0,L:25,U:-25,R:0,B:-55,T:0}); a._grp.updateMatrixWorld(true);
          const w=new T.Vector3(); a._tcpMarker.getWorldPosition(w);
          const o=a.orbit;
          const grpW=new T.Vector3(); a._grp.getWorldPosition(grpW);
          return {tgt:o?{x:o.tgt.x,y:o.tgt.y,z:o.tgt.z,r:o.r,phi:o.phi,theta:o.theta}:null,
                  marker_world:[w.x,w.y,w.z], grp_worldpos:[grpW.x,grpW.y,grpW.z], grpScale:a._grp.scale.x};
        }""")
        print(json.dumps(info,indent=2))
        await br.close()
asyncio.run(main())
