Add inspected agent viewport export with policy-bound final release
This commit is contained in:
1 parent
c8b6ff9cdd
commit
e7d778aeac
24 files changed
+483
-32
No files matched your search
@@ -52,4 +52,23 @@ function disposePageClipboardGuard(contents){
|
||||
owners.delete(contents);owner.healthy=false;owner.api.removeListener('detach',owner.detached);
|
||||
if(owner.api.isAttached())owner.api.detach();
|
||||
}
|
||||
module.exports={attachPageClipboardGuard,guardedScreenshot,disposePageClipboardGuard};
|
||||
async function guardedVisualStructure(contents){
|
||||
const owner=owners.get(contents);
|
||||
if(!owner?.healthy||!owner.api.isAttached()||contents.isDestroyed())throw Error('Managed visual export refused');
|
||||
// Native DOM data detects closed/declarative roots that isolated DOM queries
|
||||
// cannot see. It is consumed privately and never logged or returned to agents.
|
||||
const result=await deadline(owner.api.sendCommand('DOM.getDocument',{depth:-1,pierce:true}));
|
||||
if(owners.get(contents)!==owner||!owner.healthy||!owner.api.isAttached())throw Error('Managed visual export refused');
|
||||
const queue=[result?.root];let nodes=0,characters=0;
|
||||
while(queue.length){
|
||||
const node=queue.pop();if(!node||++nodes>20000)throw Error('Managed visual export refused');
|
||||
for(const text of [node.nodeName,node.nodeValue,...(node.attributes||[])]){if(typeof text!=='string'||(characters+=text.length)>1024*1024)throw Error('Managed visual export refused');}
|
||||
const shadows=node.shadowRoots||[],children=node.children||[];
|
||||
if(!Array.isArray(shadows)||!Array.isArray(children)||nodes+queue.length+shadows.length+children.length>20000)throw Error('Managed visual export refused');
|
||||
for(const root of shadows){if(root.shadowRootType==='closed')throw Error('Managed visual export refused');queue.push(root);}
|
||||
if(node.contentDocument)throw Error('Managed visual export refused');
|
||||
queue.push(...children);
|
||||
}
|
||||
return {safe:true,nodes};
|
||||
}
|
||||
module.exports={attachPageClipboardGuard,guardedScreenshot,guardedVisualStructure,disposePageClipboardGuard};
|
||||
Reference in new issue
Block a user