Does anyone know how to see the output from a console.log()
call in a background script? I can see the output from the same in a content script. Here is a simple script that I am testing this with:
Here is my background.js:
console.log("Message from background.js");
Here is my manifest.json:
{
"name": "TestBed",
"manifest_version": 2,
"version": "1.0",
"background": {
"scripts": ["background.js"]
},
"browser_action": {
"default_title": "Click"
},
"applications": {
"gecko": {
"id": "testbed@example.com",
"strict_min_version": "48.0a1"
}
}
}
I've also tried this in the background script:
chrome.browserAction.onClicked.addListener(function() {
console.log('Message from background.js onclicked handler');
});
I have even uninstalled Firebug as some other posts have suggested, but that made no difference either (note that the console.log
in content scripts works).
For a more general answer about seeing extension output in the console, please see my answer to: Google Chrome / Firefox do not see extension output in console.
You can see the output of
console.log()
from you background scripts in the Browser Console. You can open the Browser Console by either using the keyboard shortcut, Ctrl-Shift-J, or Cmd-Shift-J on OSX, or from the Firefox menu bar: Tools➞Web Developer➞Browser Console.When testing WebExtensions in versions greater than or equal to 49,1 I routinely abuse a misfeature to cause the extension to open the Browser Console. The
alert()
function is not supported in background scripts, but will open the Browser Console and output the alert text in the console.2 Doing so will work in Firefox versions greater than or equal to 49.0. However, it throws an error in earlier versions of Firefox.For testing, I often include in my background scripts something like:
alert()
, it will also output on a separate line: "alert() is not supported in background windows; please use console.log instead."