feat(dsh): add durable supervision, scheduling and operations dock
This commit is contained in:
1 parent
f861a3d386
commit
736b582bc1
46 files changed
+4122
-93
No files matched your search
+7
-4
@@ -24,7 +24,7 @@ export async function connect(port=9226) {
|
||||
};
|
||||
const call=(method,params={})=>new Promise((resolve,reject)=>{
|
||||
const id=++sequence;
|
||||
const timer=setTimeout(()=>{pending.delete(id);reject(Error('CDP timeout: '+method));},10000);
|
||||
const timer=setTimeout(()=>{pending.delete(id);reject(Error('CDP timeout: '+method));},method==='Runtime.evaluate'?30000:10000);
|
||||
pending.set(id,{resolve,reject,timer});
|
||||
socket.send(JSON.stringify({id,method,params}));
|
||||
});
|
||||
@@ -35,16 +35,19 @@ export async function connect(port=9226) {
|
||||
};
|
||||
return {call,evaluate,
|
||||
async click(expression) {
|
||||
let rect;
|
||||
await evaluate(`(()=>{const e=${expression};if(!e)throw Error('Missing click target');e.scrollIntoView({block:'center',inline:'nearest'});})()`);
|
||||
await evaluate('new Promise(resolve=>{setTimeout(resolve,150);requestAnimationFrame(()=>requestAnimationFrame(resolve));})');
|
||||
let rect,ready=false;
|
||||
const end=Date.now()+4000;
|
||||
while(Date.now()<end) {
|
||||
rect=await evaluate(`(()=>{const e=${expression};if(!e)throw Error('Missing click target');const r=e.getBoundingClientRect();return {x:r.x+r.width/2,y:r.y+r.height/2};})()`);
|
||||
await call('Input.dispatchMouseEvent',{type:'mouseMoved',...rect});
|
||||
await evaluate('new Promise(resolve=>requestAnimationFrame(()=>requestAnimationFrame(resolve)))');
|
||||
const ready=await evaluate(`(()=>{const e=${expression};if(!e)return false;const r=e.getBoundingClientRect(),top=document.elementFromPoint(r.x+r.width/2,r.y+r.height/2);return r.width>0 && r.height>0 && (e===top || e.contains(top));})()`);
|
||||
await evaluate('new Promise(resolve=>{setTimeout(resolve,150);requestAnimationFrame(()=>requestAnimationFrame(resolve));})');
|
||||
ready=await evaluate(`(()=>{const e=${expression};if(!e)return false;const r=e.getBoundingClientRect(),top=document.elementFromPoint(r.x+r.width/2,r.y+r.height/2);return r.width>0 && r.height>0 && (e===top || e.contains(top));})()`);
|
||||
if(ready)break;
|
||||
await new Promise(resolve=>setTimeout(resolve,80));
|
||||
}
|
||||
if(!ready)throw Error('Click target is not visible or is covered: '+expression);
|
||||
await call('Input.dispatchMouseEvent',{type:'mousePressed',button:'left',clickCount:1,...rect});
|
||||
await call('Input.dispatchMouseEvent',{type:'mouseReleased',button:'left',clickCount:1,...rect});
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user