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.
Go to the screen where you are experiencing the error. In Chrome, navigate to View > Developer > JavaScript Console or More Tools > JavaScript Console or press Ctrl + Shift + J. The error console will open. If you don't see any errors try reloading the page.
Press Command+Option+J (Mac) or Control+Shift+J (Windows, Linux, Chrome OS) to jump straight into the Console panel of Chrome DevTools. Or, navigate to More Tools > Developer Tools from Chrome menu, and click Console tab. The error console will open.
console. log() is the method we use most often in our work, and you can use it anywhere in JavaScript. But when the amount of printed information becomes very large, the information becomes unintuitive . Because we don't know what it refers to!
To avoid such syntax errors, you should spend time learning the grammatical rules of the JavaScript programming language. With extensive coding practice, you can spot the grammatical mistakes easily and avoid shipping them with your developed application.
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
I think the reason is content scripts are treated like extra frame for webpage and their error is shown there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With