Accessing console and devtools of extension's background.js

后端 未结 7 2396
粉色の甜心
粉色の甜心 2020-11-21 04:17

I just started out with Google Chrome extensions and I can\'t seem to log to console from my background js. When an error occurs (because of a syntax error, for example), I

相关标签:
7条回答
  • 2020-11-21 04:46

    I had the same problem, in my case the logging was set to "Hide all" in the console tab in Chrome Developer tools. I had not even realised this was an option, and I can't remember turning it off

    0 讨论(0)
  • 2020-11-21 04:46

    Similar to the answer of Michiel i also had a funny console configuration: A filter i dont remember setting:

    After clearing the filter i saw the messages.

    0 讨论(0)
  • 2020-11-21 04:49

    additionally

    if you want to see content_script js file ( when "background" property is not set ) in manifest.json

    "content_scripts": [{
        "matches": ["<all_urls>"],
        "js": ["popup.js"],
      }]
    
    "browser_action": {
        "default_icon": "icon_32.png",
        "default_popup": "popup.html"
      }
    

    then right click on extension icon and click on Inspect popup and developer window opens with popup.html opened , there you see console tab.

    0 讨论(0)
  • 2020-11-21 04:54

    You're looking at the wrong place. Logged console messages do not appear in the web page, but in the (invisible) background page. To see these messages in the console, follow these steps:

    Visit chrome://extensions/.
    You can also right-click the extension icon, then click "Manage extensions".

    1. Enable developer mode
    2. Click on the link of your background page (at "Inspect views").
    3. The developer console opens for this page.

    New UI:

    Old UI:

    0 讨论(0)
  • 2020-11-21 04:54

    I had this problem as well. It seems as though my webpage was not updating to the newly saved script. This was solved by pressing Ctrl + refresh (or Ctrl + F5) in the chrome browser.

    0 讨论(0)
  • 2020-11-21 05:00

    For followers who wish to see the debug console for a "content script" of their chrome extension, it is available by doing a normal "show developer console" then use the dropdown arrow to selects its "javascript environment" then you'll have access to its methods, etc.

    0 讨论(0)
提交回复
热议问题