Closed Bug 1439666 Opened 7 years ago Closed 5 years ago

Errors in content script are not visible in console

Categories

(DevTools :: Console, defect, P3)

59 Branch
defect

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 1410932

People

(Reporter: juraj.masiar, Unassigned)

Details

Attachments

(1 file)

8.46 KB, application/x-zip-compressed
Details
Attached file missing_erros.zip
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0 Build ID: 20180215111455 Steps to reproduce: 1) extract the "missing_errors.zip" 2) load the web-extension using "web-ext run" command 3) new tab will be opened with page "https://developer.mozilla.org/en-US/aaaaaaaaaaa" 4) open developer tools and look for the TypeError in the console Actual results: There is no error! Expected results: There should be a TypeError - Cannot read property 'hide' of undefined. But there is no error! The execution of the file just stops and there are no error printed in any console, not even add-on debugging console.
Summary: Errors in content script are now visible in console → Errors in content script are not visible in console
Component: Untriaged → Developer Tools: Console
I reproduce. (if you don't have web-ext, you can load the folder as a temporary addon using about:debugging) For some reason, the error message is displayed only in the browser console. If I wrap the faulty expression in a try/catch , the catch block is indeed executed (I console.warning(err) and saw : TypeError: browser.tabs is undefined Stack trace: @moz-extension://4ae566b9-97e3-5646-b3ea-56029d731f8d/content_script.js:5:9)
Sounds like we aren't seeing ConsoleService messages from the content script. Nicolas, does this function end up getting called in the failure case? https://searchfox.org/mozilla-central/rev/bd05e3853c6e982e2a35c1cc404b987b2bc914d6/devtools/server/actors/webconsole/listeners.js#79
Flags: needinfo?(nchevobbe)
(In reply to Brian Grinstead [:bgrins] from comment #2) > Sounds like we aren't seeing ConsoleService messages from the content > script. Nicolas, does this function end up getting called in the failure > case? > https://searchfox.org/mozilla-central/rev/ > bd05e3853c6e982e2a35c1cc404b987b2bc914d6/devtools/server/actors/webconsole/ > listeners.js#79 Yes, we do hit the function, but we fail early: message is indeed an instance of Ci.nsIScriptError, but message.outerWindowId is 0 (https://searchfox.org/mozilla-central/rev/bd05e3853c6e982e2a35c1cc404b987b2bc914d6/devtools/server/actors/webconsole/listeners.js#80-81,83). Now, I don't know if the `!message.outerWindowID` is supposed to catch 0 ?
Flags: needinfo?(nchevobbe) → needinfo?(bgrinstead)
(In reply to Nicolas Chevobbe [:nchevobbe] from comment #3) > (In reply to Brian Grinstead [:bgrins] from comment #2) > > Sounds like we aren't seeing ConsoleService messages from the content > > script. Nicolas, does this function end up getting called in the failure > > case? > > https://searchfox.org/mozilla-central/rev/ > > bd05e3853c6e982e2a35c1cc404b987b2bc914d6/devtools/server/actors/webconsole/ > > listeners.js#79 > > Yes, we do hit the function, but we fail early: message is indeed an > instance of Ci.nsIScriptError, but message.outerWindowId is 0 > (https://searchfox.org/mozilla-central/rev/ > bd05e3853c6e982e2a35c1cc404b987b2bc914d6/devtools/server/actors/webconsole/ > listeners.js#80-81,83). > > Now, I don't know if the `!message.outerWindowID` is supposed to catch 0 ? I'm not sure. I guess the risk to allowing 0 would be that we accidentally show messages coming from a content script in the same process but running in a different window? Andrea, do you know if there's a way to associate a message from a content script with a given window? Nicolas, can you post a stringified version of the console service message we are receiving in this case?
Flags: needinfo?(nchevobbe)
Flags: needinfo?(bgrinstead)
Flags: needinfo?(amarchesini)
Here's the message: ```json { "logLevel": 3, "timeStamp": 1519407198173, "message": "[JavaScript Error: \"TypeError: browser.tabs is undefined\" {file: \"moz-extension://4ae566b9-97e3-5646-b3ea-56029d731f8d/content_script.js\" line: 9}]", "debug": 0, "info": 1, "warn": 2, "error": 3, "errorMessage": "TypeError: browser.tabs is undefined", "sourceName": "moz-extension://4ae566b9-97e3-5646-b3ea-56029d731f8d/content_script.js", "sourceLine": "", "lineNumber": 9, "columnNumber": 7, "flags": 2, "category": "chrome javascript", "outerWindowID": 0, "innerWindowID": 0, "isFromPrivateWindow": false, "errorMessageName": "JSMSG_UNEXPECTED_TYPE", "notes": { "length": 0 }, "errorFlag": 0, "warningFlag": 1, "exceptionFlag": 2, "strictFlag": 4, "infoFlag": 8 } ```
Flags: needinfo?(nchevobbe)
Is there any (planned) progress here? I don't know how other add-on developers work but this is quite a big issue for me. I mean, programming in JavaScript is all about runtime errors and if you don't see them, then you have a problem.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P3
Product: Firefox → DevTools

I also keep running into this which makes debugging webextensions extremely difficult as sometimes they simply fail without errors and it takes a long time to figure out why.

As others have noted, wrapping the specific cases in a catch block does work, but considering that similar code in the regular context does output errors to the console that shouldn't be needed.

(In reply to creesch.r from comment #7)

I also keep running into this which makes debugging webextensions extremely difficult as sometimes they simply fail without errors and it takes a long time to figure out why.

As others have noted, wrapping the specific cases in a catch block does work, but considering that similar code in the regular context does output errors to the console that shouldn't be needed.

Would just like to echo this. I prefer using firefox for creating web extensions because of how easy it easy to make edits and have the extension automatically reload with npm scrips but this bug is making me slowly go insane because every so often I forget that errors are completely silent and end up placing millions of console.log()s all over my content script only to - hours later - find that I forgot to declare a single variable. I can't imagine how confusing this must be to someone building a web extension for the first time.

Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → DUPLICATE
Flags: needinfo?(amarchesini)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: