-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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(js-usage): normalize url key #11302
Conversation
woah nice find! |
Hm where is that coming from @connorjclark ? we do pickup most of the inline script and the unused bytes doesn't change much |
|
(totally unsure about any of the changes in expectations, verifiying ...) |
(note to self and separate issue: file crbug like https://bugs.chromium.org/p/chromium/issues/detail?id=927464&q=coverage%20reporter%3Ame&can=1 but for unused code behind if ...) https://bugs.chromium.org/p/chromium/issues/detail?id=1120879 |
@@ -147,7 +147,7 @@ const expectations = [ | |||
// the specific ms value here is not meaningful for this smoketest | |||
// *some* savings should be reported | |||
overallSavingsMs: '>0', | |||
overallSavingsBytes: '>=25000', | |||
overallSavingsBytes: '35000 +/- 1000', |
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.
+ / -
is better, and good to be closer to the actual value.
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.
WDYT about adding some assertions against the JsUsage artifact in smokes?
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.
done, like that?
sooooo, full circle this really had no impact on unused-javascript but it's nice to clean up the artifacts for other use cases and clearer understanding anyway? :) |
not exactly. the smoke tests don't change, but we were ignoring coverage (total and wasted bytes) for scripts that for whatever reason had relative urls. |
so it's a relative url when it comes from an iframe's inline scripts:
or via an xhr (i don't get this. shows as an XHR in devtools, and I guess it gets eval'd, but how would CDT know to assign that script execution to this xhr URL?):
|
anyway, let's hold this PR until I add to the bytes fixture to test coverage of JS loaded in an iframe + loaded via xhr+eval. |
Update: nothing to do with iframes or xhr. It's all because of We have the IMO there really should be a distinction in the protocol between network urls and the magic comment urls. This has already bit us before. |
in a gatherer, how might I turn a scriptId into a URL (if applicable)? |
AFAIK I have this problem in DevTools where it's impossible to get back the non-sourcemap comment URL of what I'm looking at, so that leads me to believe it might be a limitation with the current protocol setup. I hope I'm wrong 🤞 |
yup, the however, (store.google.com, highlighted is a known inline script w/ a comment url) (store.google.com, sometimes url is present but embedderName is blank ... I think this is eval from an xhr?) |
I agree, but resolving will require larger changes within unused-javascript (for one, making network record not necessary). And given it's just to give a better name for inline scripts using Thinking out loud, an easy resolution might be to replace the |
recapping.....
(fun fact: you can actually use both sourceURL and sourcemappingurl on the same anonymous script to give it identity and describe it's provenance) for sourcemaps we use subitems to show how a generated/compiled/network source is comprised of its original mapped sources: and in #10930 we are showing mapped source locations instead of the generated/compiled/network location.
K yeah. it sounds like we're mostly on the same page here then. at first blush that resolution seems pretty good. i agree the complete solution is quite complicated and changes a lot of ways that we've been modeling scripts vs requests. i need some more time to noodle on the problem. and perhaps we can bring this discussion to the eng sync. |
Made an issue: #11334 I think this particular PR could land, though. Keying these coverage data by the network url is the most natural thing to do here. I think any usage of urls from |
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.
+1 to discussing further in eng sync but still landing this great progress in the meantime :)
@@ -147,7 +147,7 @@ const expectations = [ | |||
// the specific ms value here is not meaningful for this smoketest | |||
// *some* savings should be reported | |||
overallSavingsMs: '>0', | |||
overallSavingsBytes: '>=25000', | |||
overallSavingsBytes: '35000 +/- 1000', |
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.
WDYT about adding some assertions against the JsUsage artifact in smokes?
@@ -34,9 +43,23 @@ class JsUsage extends Gatherer { | |||
/** @type {Record<string, Array<LH.Crdp.Profiler.ScriptCoverage>>} */ | |||
const usageByUrl = {}; | |||
for (const scriptUsage of scriptUsages) { | |||
const scripts = usageByUrl[scriptUsage.url] || []; | |||
// ScriptCoverages without a URL are from code we run over the protocol. |
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 think we should go a bit further and also
continue
ifscriptParsedEvent.embedderName === ''
yup sg
For some reason the
url
for script coverage is relative to the document. This messes up some assumptions downstream:lighthouse/lighthouse-core/audits/byte-efficiency/unused-javascript.js
Line 89 in e1a0bf0
EDIT: the reason is because of magic
sourceURL
comments.fixes #11261