Chrome 调试器命令不影响子帧

w41d8nur  于 2023-03-27  发布在  Go
关注(0)|答案(1)|浏览(104)

我正在尝试做一个chrome扩展,它将使用chrome.debugger API('Log.enable '),但是我发现iframe不受chrome.debugger命令的影响。

清单.json

{
  "name": "test",
  "version": "1.0",
  "manifest_version": 3,
  "background": {
    "service_worker": "service_worker.js"
  },
  "host_permissions": ["*://*/*"],
  "permissions": ["debugger", "tabs"]
}

service_worker.js

//enable Log domain
const onDebuggerAttach = async tabId => {
  await chrome.debugger.sendCommand({ tabId: tabId}, 'Log.enable');
  chrome.debugger.onEvent.addListener(onDebugEvent);
};

//get console messages
const onDebugEvent = (debuggeeId = {}, message, params = {}) => {
  switch (message) {
    case 'Log.entryAdded':
      handleConsoleMessage(debuggeeId.tabId, params);
      break;     
    default:
      break;
  }
};

// tabId is current tab id
chrome.debugger.attach({ tabId }, '1.3', onDebuggerAttach.bind(null, tabId));
chrome.debugger.sendCommand({ tabId: tabId}, 'Log.enable');

我如何使chrome.debugger命令在所有标签框上工作?

oyjwcjzk

oyjwcjzk1#

进程外iframe是单独的目标。您需要使用autoAttachRelated或setAutoAttach来处理子目标。请参阅https://chromedevtools.github.io/devtools-protocol/tot/Target/#method-autoAttachRelated

相关问题