Console doesn't display content script errors

During an extension development, I noticed that the Firefox debugger console doesn’t display any errors while injecting content scripts, for example, a syntax error, which I reckon would be quite common during development. To test this, I injected pure garbage as a script, and console had no indication of failure. Chrome, on the other hand, would correctly point out errors.

Am I missing something? Normal console.log messages are output as expected.

1 Like

I assume you’re looking in the Web Developer Tools console of the page the script is injected in? https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Debugging#Debugging_content_scripts

Yes, I’m. That’s where I’d expect all content script output anyway!

Iirc load errors of the script (which includes syntax errors) are logged to the browser console/add-on debugger since the script is never actually injected. I’m sure others will correct me if I’m wrong on that.

Well, the script is injected. I could see all console.log messages before a syntax error, for example.

I think the Firefox console only reports uncaught errors. Syntax errors in content scripts injected with tabs.executeScript() are reported to the background page, and are thus not uncaught.

(Which is similar to what Martin Giger said.)

I’m talking about a content script mentioned in the manifest, and not injected from a background page. For example,

  "content_scripts" : [{
      "matches": [ "<all_urls>", "file:///*/*" ],
      "js": [ "test.js" ],
      "run_at": "document_end"
  }]

with test.js containing:

console.log("before");
blahblah;
console.log("after");

Only the “before” will appear on the console, meaning the script terminated thereafter; yet, the console has no indication that it has!

Isn’t this a bug? And no, it’s not reported on the background page debugger either.

Just stumbled on this bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1410932. The error was indeed displayed on the Browser Console!

@jeenuv, could you be more specific as to what you mean by “the browser console”? I have the same problem now and can’t find the error outputs anywhere. Thanks!

There is multiple console windows - sometimes some webextension errors are not logged into Web Console (the one you see when you press F12 or Ctrl + Shift + K), but only in Browser Console (Ctrl + Shift + J). You can find it also through the Firefox main menu / Web Developer.

Related bugreport for missing errors in content scripts:

1 Like

Thanks! found it in the menu

Small mistake, the shortcut for the browser console is Ctrl + Shift + J.

1 Like

Thanks! :smiley:
Oh man, I just wrote the same one twice, lol!

As mentioned earlier, this is a bug. https://bugzilla.mozilla.org/show_bug.cgi?id=1410932

And currently the errors are shown in the browser console instead of the web console.

I noticed the console.log messages show in the web console but not in the browser console. This can be annoying. If you want to show the console.log messages in the browser console, you’ll have to select “Show Content Messages” in the settings. This way you have your console.log and error messages in one place.

For anyone who, like me, opened the Browser Console with Ctrl+Shift+J, and still didn’t see any error messages there:

You have to switch the Browser Console Mode from “Parent process only” to “Multiprocess”. Only there did I start seeing error messages from my content script (and also logs of event handlers of background script).

On Ubuntu Linux, I see the switch as a radio selector at the top of the browser console window:
Screenshot from 2022-10-16 02-25-00

1 Like