Debugging Content Scripts for Chrome Extension

六眼飞鱼酱① 提交于 2019-11-28 08:52:28

Content scripts' console.log messages are shown in the web page's console instead of the background page's inspector.

Adding debugger; works if the Developer Tool (for the web page where your content script is injected) is opened.

Therefore, in this case, you should first activate the Developer Tool (of the web page) before clicking the browser action icon and everything should work just fine.

I tried to use the debuggermethod, but it doesn't not work well because the project is using require.js to bundle javascript files.

If you are also using require.js for chrome extension development, you can try adding something like this to the code base, AND change eval(xhr.responseText) to eval(xhr.responseText + "\n//@ sourceURL=" + url);. (like this question)

Then you can see the source file in your dev tool (but not the background html window)

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