Closed Bug 1175637 Opened 5 years ago Closed 4 years ago

Error when clicking log link in Browser Console if there is a syntax error in browser.js - "browserWin.BrowserViewSourceOfDocument is not a function"

Categories

(DevTools :: Console, defect)

defect
Not set

Tracking

(firefox41 fixed)

RESOLVED FIXED
Firefox 41
Tracking Status
firefox41 --- fixed

People

(Reporter: bgrins, Assigned: bgrins)

Details

Attachments

(1 file, 1 obsolete file)

STR:

Open the browser with the Browser Console
Look for a warning or error message (there should be at least one in the list)
Click the link next to the file name and line number

Expected:
The source opens up in a new window

Actual:
See an error show up in the console: 'TypeError: browserWin.BrowserViewSourceOfDocument is not a function'
Ryan, could this be related to the recent work with 'view source in a tab'?
Flags: needinfo?(jryans)
(In reply to Brian Grinstead [:bgrins] from comment #1)
> Ryan, could this be related to the recent work with 'view source in a tab'?

Yes, it does sound related.

I tried to reproduce, but for me the source appears correctly in a new browser tab, when choosing some random message in Browser Console (mine was from an add-on).

Can you describe your steps more precisely?

Are you in a mode where there is no active browser window?
Flags: needinfo?(jryans) → needinfo?(bgrinstead)
If I close the browser window then I get a different error:

NS_ERROR_NOT_AVAILABLE:  viewSourceUtils.js:148:0

Leaving the ni? until I can investigate the original problem more closely.
The browser console should go through |viewSource|[1] in hudservice.js for this.

(In reply to Brian Grinstead [:bgrins] from comment #3)
> If I close the browser window then I get a different error:
> 
> NS_ERROR_NOT_AVAILABLE:  viewSourceUtils.js:148:0
> 
> Leaving the ni? until I can investigate the original problem more closely.

Hmm, that's interesting... looking at the line, it's a call to |openDialog|, to open the "old" view source window since there's no browser window now.

Not immediately sure when that could fail...

[1]: https://dxr.mozilla.org/mozilla-central/source/browser/devtools/webconsole/hudservice.js#439
Attached patch browser-console-link-error.patch (obsolete) — Splinter Review
This should trigger the error if you apply the patch and then run `./mach run --jsconsole`.

Then click on the SyntaxError: missing } after property list browser.js:15525:2 line in the Browser Console.

I see `TypeError: browserWin.BrowserViewSourceOfDocument is not a function hudservice.js:444:1`
Flags: needinfo?(bgrinstead) → needinfo?(jryans)
(In reply to Brian Grinstead [:bgrins] from comment #5)
> Created attachment 8624943 [details] [diff] [review]
> browser-console-link-error.patch
> 
> This should trigger the error if you apply the patch and then run `./mach
> run --jsconsole`.
> 
> Then click on the SyntaxError: missing } after property list
> browser.js:15525:2 line in the Browser Console.
> 
> I see `TypeError: browserWin.BrowserViewSourceOfDocument is not a function
> hudservice.js:444:1`

Ah, interesting!  

BrowserViewSourceOfDocument is *defined* in browser.js as well[1].  I guess your syntax error in the same file caused it to no longer be defined.

So, seems pretty specific to your particular patch...  We could change hudservice.js to check for the function as well[2], assuming it's still possible to open the older style window.

Though, when I apply your patch and rebuild /browser, I get many errors, and can't open the browser console, so I am not sure how you are getting further...

[1]: https://dxr.mozilla.org/mozilla-central/source/browser/base/content/browser.js#2324
[2]: https://dxr.mozilla.org/mozilla-central/source/browser/devtools/webconsole/hudservice.js#444
Flags: needinfo?(jryans)
(In reply to J. Ryan Stinnett [:jryans] (use ni?) from comment #6)
> Ah, interesting!  
> 
> BrowserViewSourceOfDocument is *defined* in browser.js as well[1].  I guess
> your syntax error in the same file caused it to no longer be defined.
> 
> So, seems pretty specific to your particular patch...  We could change
> hudservice.js to check for the function as well[2], assuming it's still
> possible to open the older style window.
> 
> Though, when I apply your patch and rebuild /browser, I get many errors, and
> can't open the browser console, so I am not sure how you are getting
> further...

Yeah it breaks pretty much everything, so you have to find the syntax error before you can get anything done.  It's just really hard to try and track down the source of the problem because that file is heavily preprocessed, so the line number corresponding to the error doesn't match what you see in your editor.  Obviously this is a pretty specific problem, but I've bumped into it a few times when working on files that compile into browser.js.  If there were an easy way around it (even if it meant opening a popup window) it would be great.
Summary: Error when clicking log link in Browser Console - "browserWin.BrowserViewSourceOfDocument is not a function" → Error when clicking log link in Browser Console if there is a syntax error in browser.js - "browserWin.BrowserViewSourceOfDocument is not a function"
Ah, just checking for existence of the function fixes my problem!  I'll submit a patch
Can't really think of a reasonable way to test this edge case.  Should be safe to just add this extra check though.

Try push: https://treeherder.mozilla.org/#/jobs?repo=try&revision=3dffab74d6f1
Assignee: nobody → bgrinstead
Attachment #8624943 - Attachment is obsolete: true
Status: NEW → ASSIGNED
Attachment #8624987 - Flags: review?(jryans)
Comment on attachment 8624987 [details] [diff] [review]
browser-console-error-in-browser-js.patch

Review of attachment 8624987 [details] [diff] [review]:
-----------------------------------------------------------------

Seems fine to me.
Attachment #8624987 - Flags: review?(jryans) → review+
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/5e376b895220
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 41
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.