Chrome devtools extension console

孤人 提交于 2019-12-04 18:58:22

问题


I included this in my chrome extension manifest

"devtools_page": "devtools.html"

And in devtools.html I include a devtools.js file which creates a panel

chrome.devtools.panels.create("Panel", "icon.png", "panel.html", function(panel){});

The panel is indeed created. And in panel.html I include a panel.js file in which I added a listener

chrome.devtools.network.onRequestFinished.addListener(function(details){
    console.log(details);
});

But where can I see the console output of the panel? Or how can I redirect it to the devtools console?


回答1:


This message will be logged in the console of the developer tools. To view this console, detach the developer tools from the window, and press Ctrl + Shift + J.

Here's an picture:

1. Page (http://host/)
2. + Devtools instance for http://host
3.   + Devtools instance for chrome-devtools://devtools/devtools.html?... )

Your message is currently logged to 3 (the console of the devtools instance) instead of 2 (the console of the page). To log the string to the page, use the chrome.experimental.devtools.console API.

An alternative is to JSON-serialize your object, and use chrome.devtools.inspectedWindow.eval to log the result:

var obj = ...;
var str = JSON.stringify( obj );
chrome.devtools.inspectedWindow.eval('console.log(' + str + ');');



回答2:


Another way to do it is to open the chrome devtools in a separate window (not on the side of the browser) and then press CMD + Shift + i (for Mac) and then you get another devtools for that devtools. There you can debug and see console logs easier :)



来源:https://stackoverflow.com/questions/16801693/chrome-devtools-extension-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!