Console doesn't log js errors from content script

Viewed 483

I know that to debug content script use normal web developer tools (https://developer.mozilla.org/en/docs/Mozilla/Add-ons/WebExtensions/Debugging#Debugging_content_scripts), and this works perfect. debugger keyword works as intended.

But in this exact situation things get broken:

addon.id = "123-568-485"; // I never define `addon` before this line, so this cause: ReferenceError: "addon is not defined". We aren't aware of this mistake.

// Some more code
// Some more code
// Some more code
// Some more code

debugger; // Here we want to stop execution and inspect, some other stuff. Remember that we aren't aware of earlier mistake.

What we would expect, that in console error about Reference error will appear, but it doesn't. Console get silent, and we don't know why our debugger keyword doesn't work.

This kind of silent error, happened to me when I misspell variable name. In result couldn't figure out what's wrong.

2 Answers

The errors in the content script are not reported in the tab's Web Console due to Firefox bug 1410932, which is not fixed (as of Firefox 79, released on 2020-07-28).

I listed possible workarounds in another answer:

  • use try..catch with logging,
  • check the Browser Console (which does show errors from the content script)
  • use the Debugger's "pause on exceptions" option.

Content scripts are executed in webpage, So as you know to see it's output you should open up console menu in that specific web page (ctrl+shift+e then go to console).
But if something is wrong with content script and cause it to throw exception, The error log would be shown in debug area of your extension in: about:debugging

enter image description here

I think the reason is content scripts are treated like extra frame for webpage and their error is shown there.

Related