4

My Chrome extension doesn't seem to execute console.log in any way. It skips it.

console.log works: I can open the Console, type console.log('test'); and it works. It works from other scripts, i.e. a JS script loaded in a HTML page locally, but not from my extension.

My background.js that I run through manifest.json below. It executes alert(), but not console.log

chrome.browserAction.onClicked.addListener(function(tab) {
  chrome.tabs.executeScript(null, { file: "jquery-3.0.0.min.js" }, function() {

      console.log('----');

      alert('Hello!);

  });
});

I've tried:

  • delete console.log, delete window.console and delete window[console] as suggested by Restoring console.log() and JavaScript console log in Magento, but no success.
  • loaded the extension in Incognito mode, with no other extensions loaded, but no success.
  • updated background.js to consist of only a single line - console.log('----'); - still doesn't work.
  • making sure that the console reports "All", not just errors.

My manifest.json:

{

  "manifest_version": 2,

  "name": "My Chrome Extension",
  "description": "This extension will you save time.",
  "version": "1.0",

  "permissions": [
    "http://*/*",
    "https://*/*",
    "tabs"
  ],

  "browser_action": {
    "name": "Click to start the extension"
  },

  "background": {
    "scripts": ["background.js"]
  }

}
Community
  • 1
  • 1
Max
  • 841
  • 1
  • 12
  • 25
  • 3
    Background page, popup page, web page all are separate windows and have their own console. Background page console can be opened on chrome://extensions page when [x] Developer mode is enabled. I believe this question was asked many times. – wOxxOm Jun 30 '16 at 12:19
  • @wOxxOm _"I believe this question was asked many times."_ You are not wrong. – Xan Jun 30 '16 at 14:57
  • Actually the issue was from not running the `executeScipts` in my background.js. By doing so, I've included console logs in the active window console. – Max Jun 30 '16 at 15:36

1 Answers1

5

The console for your extension is in a separate window.You can inspect your console.log() messages by:

  1. Go to chrome://extension

  2. Enable developer mode

  3. Click on the "background page" link at the "Inspect views" line

  4. The developer console for your extension will open here.

Credits to: Where to read console messages from background.js in a Chrome extension?

Alex Susanu
  • 163
  • 1
  • 9