Devtools error console link to debugger shows invalid link
Categories
(DevTools :: Console, defect, P2)
Tracking
(firefox67 fixed)
Tracking | Status | |
---|---|---|
firefox67 | --- | fixed |
People
(Reporter: joshunger1, Assigned: bhackett1024)
References
(Blocks 2 open bugs)
Details
(Whiteboard: [good first verify] [bugday-20190327])
User Story
**Steps to reproduce** 1. Go to https://devtools-console-eval-throw-link-dbg.glitch.me/ 2. Open the console 3. There should be an error message, click on its location ( script.js line 2 > eval:1:7) 4. Click on the location **Expected results** This opens the debugger **Actual results** A new tab is open `view-source:https://devtools-console-eval-throw-link-dbg.glitch.me/script.js%20line%202%20%3E%20eval`, only displaying "Not Found" in the content page. ---
Attachments
(13 files, 10 obsolete files)
49.03 KB,
image/png
|
Details | |
23.79 KB,
image/png
|
Details | |
50.09 KB,
image/png
|
Details | |
6.32 KB,
patch
|
loganfsmyth
:
review+
|
Details | Diff | Splinter Review |
4.84 KB,
patch
|
loganfsmyth
:
review+
|
Details | Diff | Splinter Review |
60.46 KB,
patch
|
Details | Diff | Splinter Review | |
1.85 KB,
patch
|
jimb
:
review+
|
Details | Diff | Splinter Review |
11.92 KB,
patch
|
jimb
:
review+
|
Details | Diff | Splinter Review |
15.87 KB,
patch
|
jimb
:
review+
|
Details | Diff | Splinter Review |
2.32 KB,
patch
|
jimb
:
review+
|
Details | Diff | Splinter Review |
12.69 KB,
patch
|
smaug
:
review+
|
Details | Diff | Splinter Review |
3.42 KB,
patch
|
loganfsmyth
:
review+
|
Details | Diff | Splinter Review |
4.94 KB,
patch
|
loganfsmyth
:
review+
|
Details | Diff | Splinter Review |
Reporter | ||
Comment 1•7 years ago
|
||
Reporter | ||
Updated•7 years ago
|
Updated•7 years ago
|
Updated•6 years ago
|
Comment 2•6 years ago
|
||
Reporter | ||
Comment 3•6 years ago
|
||
Reporter | ||
Comment 4•6 years ago
|
||
Reporter | ||
Comment 5•6 years ago
|
||
Comment 6•6 years ago
|
||
Reporter | ||
Comment 7•6 years ago
|
||
Let me know if you can reproduce with https://bug-1447244.glitch.me/?
Comment 8•6 years ago
|
||
Indeed I can, thanks!
Reporter | ||
Comment 9•6 years ago
|
||
Excellent, I'll upload to Glitch going forward. That works well!
Updated•6 years ago
|
Updated•6 years ago
|
Updated•6 years ago
|
Assignee | ||
Comment 10•6 years ago
|
||
I think the fundamental problem here is that location information associated with console messages (the location of the message and any stack trace) only refers to URLs, and not the script sources which would precisely identify the location of interest. URLs can't be used when the location is in code generated from an eval or something similar.
If we can determine the source for these locations, we can easily map them back to tabs in the debugger. Referring to the sources directly from the console messages wouldn't be good I think, because the messages can live a long time and we don't to prevent the sources themselves from being GC'ed. An alternative would be to assign a unique, process-wide ID/tag to each source, and refer to those from the message. As long as the source hasn't been GC'ed by the time the console is opened, we could map the tag back to that source.
Similar to bug 1503422, having the console or debugger open when the page is loaded will prevent sources from being GC'ed. If we find that a source in a message has already been GC'ed we could show something to the user for generated sources (make the link non-clickable, with a description when hovering?) instead of letting them click and get weird behavior.
Comment 11•6 years ago
|
||
(In reply to Brian Hackett (:bhackett) from comment #10)
An alternative would be to assign a unique, process-wide ID/tag to each source, and refer to those from the message.
This would also be useful if done for style sheets, see https://bugzilla.mozilla.org/show_bug.cgi?id=880831#c11. I think there are other dependencies of the source maps meta bug (bug 1339970) that touch on these problems as well.
Assignee | ||
Comment 12•6 years ago
|
||
WIP to add unique tags to script sources and retain them in error messages and error message stacks. The devtools server can convert the tags into actor IDs before sending them to the client, and the client can then go straight to the source to display after a link is clicked instead of just using a URL. This works for links in error message stacks in the console, but I got hung up getting this to work for the location of the error message itself. This information originates from the nsIScriptError, and when modifying the initialization methods for nsIScriptError to include a source tag I found the patch turned a lot of code pretty ugly due to having to pass yet another source-related bit of information around (there are four already). I tried creating a SourceLocation class to encapsulate this, but there are a ton of places this needs to be used and I don't think this bug is the place for a large-scale cleanup/refactoring of how the browser handles error messages.
I'm going to try a different approach where the source tag is not specified when initializing an nsIScriptError, but can be optionally specified afterwards. This should avoid having to make a lot of code changes and keep this bug more narrowly focused.
Updated•6 years ago
|
Assignee | ||
Comment 13•6 years ago
|
||
Complete patch, requiring source tags to be separately specified on nsIScriptErrors to avoid many of the changes in the last patch (though lots of C++ changes are still required). I'll split this up for review shortly.
Assignee | ||
Comment 14•6 years ago
|
||
Add a tag to each created ScriptSource which is unique within the process. The source's tag is essentially a weak reference that can only be used in equality comparisons and is easy to pass around without getting the GC involved.
Assignee | ||
Comment 15•6 years ago
|
||
Keep track of source tags in saved frames along with other location information. Devtools server code will be able to access the source tags in these saved frames directly, e.g. in stacks associated with page errors.
Assignee | ||
Comment 16•6 years ago
|
||
Source tags need to be tracked in exception information so that they can be used when generating nsIScriptErrors (which the devtools server will then consume).
Assignee | ||
Comment 17•6 years ago
|
||
Debugger.Source provides the tag of the underlying ScriptSource so that the devtools server can create a map from tags to sources.
Assignee | ||
Comment 18•6 years ago
|
||
Propagate the source tag from JSErrorReports and saved frames to nsIScriptError and webidl ConsoleEvents, for use by devtools server code.
Assignee | ||
Comment 19•6 years ago
|
||
The devtools server uses DebuggerSource.tag to create a map from tags to any source actors it has created. This map is used to include source actor IDs when possible when informing the client about page errors and console API calls.
Assignee | ||
Comment 20•6 years ago
|
||
The devtools client never learns about source tags, but it has to cope with the source actor IDs now being transmitted for incoming messages. This patch passes those IDs around in various places and uses them to open sources in the debugger by their ID instead of by URL if the ID is available.
Assignee | ||
Comment 21•6 years ago
|
||
Add a test for the new functionality.
Assignee | ||
Comment 22•6 years ago
|
||
(In reply to Tom Tromey :tromey from comment #11)
(In reply to Brian Hackett (:bhackett) from comment #10)
An alternative would be to assign a unique, process-wide ID/tag to each source, and refer to those from the message.
This would also be useful if done for style sheets, see https://bugzilla.mozilla.org/show_bug.cgi?id=880831#c11. I think there are other dependencies of the source maps meta bug (bug 1339970) that touch on these problems as well.
Yeah, the approach in these patches is very similar to what you suggest in that comment. This bug adds the plumbing necessary for adding an identifying tag to page errors and console messages (though it is a uint32 instead of a string), which should be reusable for errors/messages related to style sheets.
Assignee | ||
Comment 23•6 years ago
|
||
Oops, forgot this part. In order for the tag -> actor map in the server to work, the source actor needs to have already been created at the time we process a message that is being sent to the client.
Currently, this is not guaranteed to be the case: the console will usually request the sources for a page, but not until it has a message with a generated location which it needs to map back to an original location.
This patch ensures the above property by making sure the console client requests the sources for a page before it requests the cached messages. This reordering is rather fragile (though any breakage should be caught by the new test) though it is simple.
Comment 24•6 years ago
|
||
Assignee | ||
Comment 25•6 years ago
|
||
(In reply to Jan de Mooij [:jandem] from comment #24)
Comment on attachment 9037032 [details] [diff] [review]
Part 1 - Add unique tag to ScriptSource.Review of attachment 9037032 [details] [diff] [review]:
::: js/src/vm/JSScript.h
@@ +584,5 @@
- // A tag for this source that is unique across the process. This can be used
- // to refer to this source from places that don't want to hold a strong
- // reference on the source itself.
- uint32_t tag_;
Drive-by comment: uint32_t is prone to overflow, at least considering a
malicious website using Function or eval in a tight loop. Maybe safer to use
uint64_t.
Yeah, I considered this, though the only bad effects that can arise from overflow are bogus equality comparisons and incorrectly behaving devtools. When the devtools are open, all ScriptSources are kept alive by the devtools server and we'll choke long before 2^32 of them can be allocated. I don't have a strong preference, but uint32_t reduces the memory impact and can be straightforwardly converted to a JS value.
Comment 26•6 years ago
|
||
Updated•6 years ago
|
Updated•6 years ago
|
Updated•6 years ago
|
Comment 27•6 years ago
|
||
Assignee | ||
Comment 28•6 years ago
|
||
(In reply to Olli Pettay [:smaug] from comment #27)
Comment on attachment 9037042 [details] [diff] [review]
Part 5 - Add source tag to nsIScriptError and ConsoleEvent.I'm having great trouble to understand what 'tag' means. Some magical
uint32_t value.
Could you please document the added attribute in .idl files and possibly
rename to something more descriptive?Is tag more like scriptSourceId ?
Yeah, the tag is a unique ID for a script source. I'll rename it to scriptSourceId; I called it a tag instead to distinguish it from the script source IDs used in devtools code, but there is little overlap between the places where the two kinds of IDs are used so I don't think it would cause much confusion.
Assignee | ||
Comment 29•6 years ago
|
||
This updated complete patch replaces 'tag' with 'id' throughout, and adds some comments and minor fixes.
Assignee | ||
Comment 30•6 years ago
|
||
Updated patch for s/tag/id.
Assignee | ||
Comment 31•6 years ago
|
||
Updated patch for s/tag/id.
Assignee | ||
Updated•6 years ago
|
Assignee | ||
Comment 32•6 years ago
|
||
Updated patch for s/tag/id. This also fixes a bug where frame iteration scripts were not null checked --- they will be null for wasm frames.
Assignee | ||
Comment 33•6 years ago
|
||
Updated patch for s/tag/id.
Assignee | ||
Comment 34•6 years ago
|
||
Updated patch for s/tag/id. I went with sourceId instead of scriptSourceId in IDL files, in case we use these IDs for other sources like CSS files.
Assignee | ||
Comment 35•6 years ago
|
||
Updated patch for s/tag/id. Since this is the only place where the internal source IDs and the actor source IDs interact, this patch uses extra-cumbersome names like getSourceActorByInternalSourceId to avoid ambiguity / accidental misuse.
Updated•6 years ago
|
Comment 36•6 years ago
|
||
Comment 37•6 years ago
|
||
Updated•6 years ago
|
Updated•6 years ago
|
Updated•6 years ago
|
Assignee | ||
Comment 38•6 years ago
|
||
Updated patch per comments.
Updated•6 years ago
|
Comment 39•6 years ago
|
||
Comment 40•6 years ago
|
||
Updated•6 years ago
|
Updated•6 years ago
|
Updated•6 years ago
|
Comment 41•6 years ago
|
||
(In reply to Brian Hackett (:bhackett) from comment #25)
Yeah, I considered this, though the only bad effects that can arise from overflow are bogus equality comparisons and incorrectly behaving devtools. When the devtools are open, all ScriptSources are kept alive by the devtools server and we'll choke long before 2^32 of them can be allocated. I don't have a strong preference, but uint32_t reduces the memory impact and can be straightforwardly converted to a JS value.
OK but in that case please document this better or rename things to make it clearer. The comment now says "An id for this source that is unique across the process." but it's not necessarily unique.
Sorry to be pedantic, but even though the current uses are safe, people will use this for other things in the future and introduce security bugs.
Assignee | ||
Comment 42•6 years ago
|
||
There have been a bunch of changes to how sources work in the debugger since these patches were posted, and some followup work is needed. This patch fixes a couple issues:
-
We can't guarantee that the client will ask for all sources before asking for cached messages, and in any case we probably shouldn't require this. This uses a different design where the server lazily generates a map from internal source id -> debugger source, and generates source actors for those sources when needed by the console instead of requiring them to already exist.
-
Some changes to the view-source code in the client are needed because the actor ID used here is no longer the ID for the source itself.
Comment 43•6 years ago
|
||
Assignee | ||
Comment 44•6 years ago
|
||
(In reply to Logan Smyth [:loganfsmyth] from comment #43)
Comment on attachment 9045816 [details] [diff] [review]
followupReview of attachment 9045816 [details] [diff] [review]:
::: devtools/client/shared/view-source.js
@@ +60,5 @@
- } else if (await toolbox.sourceMapService.hasOriginalURL(sourceURL)) {
- // We have seen a source map for the URL but no source. The debugger will
- // still be able to load the source.
- await toolbox.selectTool("jsdebugger", reason);
- dbg.selectSourceURL(sourceURL, sourceLine);
Should we be concerned about cases here where we saw the URL in
sources
,
but then failed to load the file, or doeshasOriginalURL
only return true
if the original code was loaded?
hasOriginalURL indicates whether the URL was found as an original URL in a source map. It will still be there if we weren't able to fetch the original URL, but in that case I don't think it matters much whether we try to open the URL in the debugger or a view-source tab. In any case, the patches here don't change the existing behavior when we make this hasOriginalURL call. We just need some extra logic to deal with the fact that sometimes we are opening things in the debugger by SourceId instead of by URL.
Comment 45•6 years ago
|
||
Comment 46•6 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/4d1b48923635
https://hg.mozilla.org/mozilla-central/rev/37828dbf6749
https://hg.mozilla.org/mozilla-central/rev/320d791829e2
https://hg.mozilla.org/mozilla-central/rev/5adb94d8c8e0
https://hg.mozilla.org/mozilla-central/rev/3538cdbdb944
https://hg.mozilla.org/mozilla-central/rev/dcd062ed8466
https://hg.mozilla.org/mozilla-central/rev/15b57a09f35f
https://hg.mozilla.org/mozilla-central/rev/72038435352d
https://hg.mozilla.org/mozilla-central/rev/8891e6a6c18b
https://hg.mozilla.org/mozilla-central/rev/aa7d1cc3ef70
Updated•6 years ago
|
Comment 47•6 years ago
|
||
I have reproduced this bug with Nightly 61.0a1 (2018-03-20) on Windows 7, 64 Bit.
The fix of this bug is verified with latest Beta 67.0b6!
Build ID : 20190328152334
User Agent : Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0
Description
•