I am trying to develop a chrome extension and in this extension, I need the target related events (targetCreated/targetInfoChanged/targetDestroyed).
To achieve that goal I am using setDiscoverTargets method from the devtools protocol by means of chrome.debugger API. Here is the pseudocode that I am using:
// attach the debugger
chrome.debugger.attach(debuggeeId, version, onAttach);
// when attach is successful send setAuthAttach to make setDiscoverTargets command work
const onAttach = (debuggeeId) => {
if (chrome.runtime.lastError) {
alert(chrome.runtime.lastError.message);
return;
}
console.log(`onAttach: ${JSON.stringify(debuggeeId)}`);
chrome.debugger.sendCommand({ tabId: myTabId }, "Target.setAutoAttach", { autoAttach: false, waitForDebuggerOnStart: false, flatten: true }, setAutoAttachHandler);
}
// when auto attach handler is successful send setDiscoverTargets method
// to enable targetCreated/targetInfoChanged/targetDestroyed events
const setAutoAttachHandler = (result) => {
if (chrome.runtime.lastError) {
console.log("error in setAutoAttachHandler:" + chrome.runtime.lastError.message);
return;
}
console.log(`setAutoAttachHandler result: ${JSON.stringify(result)}`);
chrome.debugger.sendCommand({ tabId: myTabId }, 'Target.setDiscoverTargets', { discover: true }, setDiscoverTargetsHandler);
}
// see the result of command
const setDiscoverTargetsHandler = (result) => {
if (chrome.runtime.lastError) {
console.log("error in setDiscoverTargetsHandler:" + chrome.runtime.lastError.message);
return;
}
console.log(`setDiscoverTargets result: ${JSON.stringify(result)}`);
}
As per execute the code above I am always getting not allowed
error
error in setDiscoverTargetsHandler:{"code":-32000,"message":"Not
allowed"}
And the events related to the target are not fired. Is there anything else I should do to get those events?
thank you.
question from:
https://stackoverflow.com/questions/65540994/setdiscovertargets-is-not-allowed-for-chrome-extension 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…