问题描述
我正在尝试开发一个 chrome 扩展,在这个扩展中,我需要与目标相关的事件 (targetCreated/targetInfoChanged/targetDestroyed)。
为了实现该目标,我通过 setDiscoverTargets API 使用了 devtools 协议中的 chrome.debugger 方法。这是我使用的伪代码:
// 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)}`);
}
根据执行上面的代码,我总是收到 not allowed
错误
错误在 setdiscoverTargetsHandler:{"code":-32000,"message":"Not 允许"}
并且不会触发与目标相关的事件。我还需要做些什么才能获得这些事件?
谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)