如何使用 chrome 扩展在 iframe 或页面中打开当前网站的控制台日志,我为此使用 chrome 调试器协议,但我能够计算日志
chrome.tabs.query({ currentWindow: true, active: true }, function (tabs) {
console.log("tabs--->", tabs);
console.log("tabs[0].id", tabs[0].id);
chrome.debugger.attach({ tabId: tabs[0].id }, "1.1", () => {
if (chrome.runtime.lastError) {
console.log("runtime.lastError", chrome.runtime.lastError.message);
return;
}
console.log("Debugger attached");
});
chrome.debugger.sendCommand({ tabId: tabs[0].id }, "Console.enable", () => {
if (chrome.runtime.lastError) {
console.log("runtime.lastError", chrome.runtime.lastError.message);
return;
}
console.log("Log enabled and result");
});
const config = {
source: "javascript",
level: "log",
text: "console.log('hello world')",
};
chrome.debugger.sendCommand({ tabId: tabs[0].id }, "Console.ConsoleMessage", config, () => {
if (chrome.runtime.lastError) {
console.log("runtime.lastError", chrome.runtime.lastError.message);
return;
}
console.log("Log enabled and result");
});
});
我已经尝试了上面的代码,它抛出了一个Console.ConsoleMessage
未找到的错误