core: gather source maps#9101
Conversation
|
WIP b/c no tests, and: I want to put source maps in a new artifact, because gathering them is a lot of network requests and parsing that should only be done if an audit explicitly needs it - which, right now, does not exist. It could be in a new gatherer, but I'd like to use the Is there a nice way to pass the driver to a computed artifact? Or is it better to forgo |
Sadly, no. Computed artifacts are firmly in audit phase territory and there's no way to have dependencies between artifacts unless one is a
I'm not sure I understand the decision here, since it sounds like if you needed a separate gatherer either way you could have the separate one listen on |
Failed to realize it's not required to do that in the |
| const a = 1; | ||
| // Use this obnoxious URL because using a non-existent url from localhost will return a | ||
| // bunch of HTML, which will be parsed, and no fetch error occurs. | ||
| //# sourceMappingURL=http://www.this-will-not-exist-blah-go-rockets.com/some-map.js.map |
There was a problem hiding this comment.
i guess i could do http://localhost:1234 ...
There was a problem hiding this comment.
go-rockets
😱
haha 😉 to your actual point though, :1234 is the default for parcel which I tend to have running so that might cause something unexpected too ;) haha
how about an entirely invalid URL? or is that then testing something different you're not concerned about?
There was a problem hiding this comment.
i suppose anything that results in a fetch error will work, including a malformed URL.
There was a problem hiding this comment.
go-rockets
Did that just to get a rise out of you ;)
Codecov Report
@@ Coverage Diff @@
## master #9101 +/- ##
==========================================
- Coverage 91.44% 91.43% -0.02%
==========================================
Files 291 292 +1
Lines 9929 9981 +52
==========================================
+ Hits 9080 9126 +46
- Misses 849 855 +6
Continue to review full report at Codecov.
|
| sourceMapUrl: isSourceMapADataUri ? undefined : sourceMapUrl, | ||
| // map is undefined, unless there wasn't an error. | ||
| map: undefined, | ||
| ...sourceMapOrError, |
There was a problem hiding this comment.
idk is this a sin?
There was a problem hiding this comment.
it's definitely approaching "hard to follow" :)
Something like this might be a little easier to follow, possibly:
/**
* @param {Driver} driver
* @param {LH.Crdp.Debugger.ScriptParsedEvent} event
* @return {Promise<LH.Artifacts.SourceMap>}
*/
async _retrieveMapFromScriptParsedEvent(driver, event) {
if (!event.sourceMapURL) {
throw new Error('precondition failed: event.sourceMapURL should exist');
}
// `sourceMapURL` is simply the URL found in either a magic comment or an x-sourcemap header.
// It has not been resolved to a base url.
const isSourceMapADataUri = event.sourceMapURL.startsWith('data:');
const scriptUrl = event.url;
const rawSourceMapUrl = isSourceMapADataUri ?
event.sourceMapURL :
this._resolveUrl(event.sourceMapURL, scriptUrl);
if (!rawSourceMapUrl) {
return {
scriptUrl,
errorMessage: `Could not resolve map url: ${event.sourceMapURL}`,
};
}
// sourceMapUrl isn't included in the the artifact if it was a data URL.
const sourceMapUrl = isSourceMapADataUri ? undefined : rawSourceMapUrl;
try {
const map = isSourceMapADataUri ?
this.parseSourceMapFromDataUrl(rawSourceMapUrl) :
await this.fetchSourceMapInPage(driver, rawSourceMapUrl);
return {
scriptUrl,
sourceMapUrl,
map,
};
} catch (err) {
return {
scriptUrl,
sourceMapUrl,
errorMessage: err.toString(),
};
}
}|
A Googler has manually verified that the CLAs look good. (Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.) ℹ️ Googlers: Go here for more info. |
|
Considerable work needs to be done to support fetching arbitrary resources outside the page context for each of our environments. We have:
.
Options moving forward: a) land as-is, some maps can't be fetched due to CORs. For the audit that will come after, we can ignore fetch errors. I vote for a) to keep the PR smaller. |
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
|
alternatively, could do a hybrid: support node fully using |
I definitely don't think we should block on that, at worst it's only as bad as if they hadn't published their source maps |
brendankenny
left a comment
There was a problem hiding this comment.
looking good, I think just these last things (+ axing the logging)
| sourceMapUrl: isSourceMapADataUri ? undefined : sourceMapUrl, | ||
| // map is undefined, unless there wasn't an error. | ||
| map: undefined, | ||
| ...sourceMapOrError, |
There was a problem hiding this comment.
it's definitely approaching "hard to follow" :)
Something like this might be a little easier to follow, possibly:
/**
* @param {Driver} driver
* @param {LH.Crdp.Debugger.ScriptParsedEvent} event
* @return {Promise<LH.Artifacts.SourceMap>}
*/
async _retrieveMapFromScriptParsedEvent(driver, event) {
if (!event.sourceMapURL) {
throw new Error('precondition failed: event.sourceMapURL should exist');
}
// `sourceMapURL` is simply the URL found in either a magic comment or an x-sourcemap header.
// It has not been resolved to a base url.
const isSourceMapADataUri = event.sourceMapURL.startsWith('data:');
const scriptUrl = event.url;
const rawSourceMapUrl = isSourceMapADataUri ?
event.sourceMapURL :
this._resolveUrl(event.sourceMapURL, scriptUrl);
if (!rawSourceMapUrl) {
return {
scriptUrl,
errorMessage: `Could not resolve map url: ${event.sourceMapURL}`,
};
}
// sourceMapUrl isn't included in the the artifact if it was a data URL.
const sourceMapUrl = isSourceMapADataUri ? undefined : rawSourceMapUrl;
try {
const map = isSourceMapADataUri ?
this.parseSourceMapFromDataUrl(rawSourceMapUrl) :
await this.fetchSourceMapInPage(driver, rawSourceMapUrl);
return {
scriptUrl,
sourceMapUrl,
map,
};
} catch (err) {
return {
scriptUrl,
sourceMapUrl,
errorMessage: err.toString(),
};
}
}| } | ||
|
|
||
| const value = fetchError ? | ||
| Object.assign(new Error(), {message: fetchError, __failedInBrowser: true}) : |
There was a problem hiding this comment.
ah, it's because of
lighthouse/lighthouse-core/gather/driver.js
Line 541 in 21d00ac
fetchError.message isn't enumerable when message is set via the Error constructor, so it isn't copied over on that line)
fetchError could be a plain object like is done in the real pageFunctions.wrapRuntimeEvalErrorInBrowserString, but this seems good enough.
| /** Error that occurred during fetching or parsing of source map. */ | ||
| errorMessage: string | ||
| /** No map on account of error. */ | ||
| map: undefined; |
There was a problem hiding this comment.
this can be map?: undefined so it won't have to be set to undefined manually (the code snippet I posted above relies on that, I believe)
…se into gather-source-maps
|
A Googler has manually verified that the CLAs look good. (Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.) ℹ️ Googlers: Go here for more info. |
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
|
A Googler has manually verified that the CLAs look good. (Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.) ℹ️ Googlers: Go here for more info. |
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
|
it seems half of these comments could be @googlebot 👎 |
|
A Googler has manually verified that the CLAs look good. (Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.) ℹ️ Googlers: Go here for more info. |
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
|
@brendankenny @exterkamp ya'll wanna add your personal emails to the CLA thing? click the Googler link above |
|
A Googler has manually verified that the CLAs look good. (Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.) ℹ️ Googlers: Go here for more info. |
#9097
Gather source maps.
Nothing done with them yet.