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.

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!