I am trying to make a chrome extension that will use the chrome.debugger api('Log.enable'), but I found that iframes are not affected by the chrome.debugger commands.
manifest.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');
How do I make the chrome.debugger commands work on all the tab frames?
Out-of-process iframes are separate targets. You need to use autoAttachRelated or setAutoAttach to work with subtargets. See https://chromedevtools.github.io/devtools-protocol/tot/Target/#method-autoAttachRelated