-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core: append sourceURL comment to eval code #13754
Merged
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5d61156
core: append sourceURL comment to eval code
connorjclark 2c5cf1e
fix
connorjclark 5cd3157
test
connorjclark f4db822
Merge remote-tracking branch 'origin/master' into eval-source-url
connorjclark c038569
Merge remote-tracking branch 'origin/master' into eval-source-url
connorjclark 561f791
comments
connorjclark ffa8908
update
connorjclark 3b93d68
Merge remote-tracking branch 'origin/master' into eval-source-url
connorjclark 49fc01c
Merge remote-tracking branch 'origin/master' into eval-source-url
connorjclark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,22 @@ async function runInSeriesOrParallel(values, promiseMapper, runInSeries) { | |
} | ||
} | ||
|
||
/** | ||
* Returns true if the script was created via our own calls | ||
* to Runtime.evaluate. | ||
* @param {LH.Crdp.Debugger.ScriptParsedEvent} script | ||
*/ | ||
function isLighthouseRuntimeEvaluateScript(script) { | ||
// Scripts created by Runtime.evaluate that run on the main session/frame | ||
// result in an empty string for the embedderName. | ||
if (!script.embedderName) return true; | ||
connorjclark marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Otherwise, when running our own code inside other frames, the embedderName | ||
// is set to the frame's url. In that case, we rely on the special sourceURL that | ||
// we set. | ||
return script.hasSourceURL && script.url === 'lighthouse-eval.js'; | ||
} | ||
|
||
/** | ||
* @fileoverview Gets JavaScript file contents. | ||
*/ | ||
|
@@ -68,8 +84,9 @@ class Scripts extends FRGatherer { | |
// it also blocks scripts from the same origin but that happen to run in a different process, | ||
// like a worker. | ||
if (event.method === 'Debugger.scriptParsed' && !sessionId) { | ||
// Events without an embedderName (read: a url) are for JS that we ran over the protocol. | ||
if (event.params.embedderName) this._scriptParsedEvents.push(event.params); | ||
if (!isLighthouseRuntimeEvaluateScript(event.params)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: now can we add to the condition above ;) |
||
this._scriptParsedEvents.push(event.params); | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a few underscores to this guy? I feel like someone is using
lighthouse-eval.js
as their script name somewhere out in the web.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that's the case, then the url property will be the full absolute URL ending with this name. But when we set it via sourceURL it's exactly this string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think
//# sourceURL=lighthouse-eval.js
is within the realm of possibilities and it can't hurt to add a few underscores or something.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok will do