-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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(critical-request-chains): Remove iframe as Critical Request #3583
Conversation
@@ -22,6 +22,9 @@ class CriticalRequestChains extends ComputedArtifact { | |||
static isCritical(request) { | |||
const resourceTypeCategory = request._resourceType && request._resourceType._category; | |||
|
|||
// Iframes are considered High Priority but they are not render blocking | |||
const isIframe = resourceTypeCategory === WebInspector.resourceTypes.Document._category |
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 there an actual initiator type we can look at? what about frameId would that help us?
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.
parse or script I guess. Main document is set to other. What does frameid means?
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.
requests have a frameId associated with them, so I'm wondering if we can use that to check if the request was for a frame other than the main frame
https://chromedevtools.github.io/devtools-protocol/tot/Network/
@@ -17,11 +17,15 @@ class CriticalRequestChains extends ComputedArtifact { | |||
* For now, we use network priorities as a proxy for "render-blocking"/critical-ness. | |||
* It's imperfect, but there is not a higher-fidelity signal available yet. | |||
* @see https://docs.google.com/document/d/1bCDuq9H1ih9iNjgzyAL0gpwNFiEP4TZS-YLRp_RuMlc | |||
* @param {any} request | |||
* @param {any} request | |||
* @param {!WebInspector.NetworkRequest} |
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.
nit: missing mainResource
name
const resourceTypeCategory = request._resourceType && request._resourceType._category; | ||
|
||
// Iframes are considered High Priority but they are not render blocking | ||
const isIframe = resourceTypeCategory === WebInspector.resourceTypes.Document._category | ||
&& request.frameId !== mainResource.frameId; |
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.
perfect! 💯
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.
niiiiice. let's use _frameId
tho. i think that public api will be changing in our next bump.. haha.
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 just verified that the frameid of the iframe resource is the new iframe.. we're good!
const resourceTypeCategory = request._resourceType && request._resourceType._category; | ||
|
||
// Iframes are considered High Priority but they are not render blocking | ||
const isIframe = resourceTypeCategory === WebInspector.resourceTypes.Document._category |
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.
the other examples in here I believe are a bit more verbose than they need to be, you should be able to just check request._resourceType === WebInspector.resourceTypes.Document
@@ -260,7 +260,7 @@ describe('Runner', () => { | |||
|
|||
return Runner.run({}, {url, config}).then(results => { | |||
const audits = results.audits; | |||
assert.equal(audits['critical-request-chains'].displayValue, 9); | |||
assert.equal(audits['critical-request-chains'].displayValue, 5); |
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.
this is the good kind of test change, right? :D
(i.e. we were wrong before and now we're right)
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.
yes, you can see the diff here.
https://www.diffchecker.com/ec6WBOxh
As you can see we removed 3 iframes from the critical requests:
- https://www.redditmedia.com/ads/display/300x250-companion
- https://www.redditmedia.com/gtm/jail?cb=8CqR7FcToP
- https://www.redditmedia.com/ads/display/300x250
so in total we removed 5 leaf nodes but we only remove 4 chains as https://www.redditstatic.com/reddit-init.en.belOwpfqWtw.js
is still a root node.
networkRecords[1].url = 'https://example.com/iframe.html'; | ||
networkRecords[1].mimeType = 'text/html'; | ||
networkRecords[1]._resourceType._category = WebInspector.resourceTypes.Document._category; | ||
networkRecords[0].frameId = '2'; |
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 this intentional to keep changing frameId of the root document?
also is there a document request case that is within the same frame we should add to tests?
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.
Only html documents that are being fetched are Documents from iframe. XHR is not counted here
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.
this'll be good once it comes back. nice work
const resourceTypeCategory = request._resourceType && request._resourceType._category; | ||
|
||
// Iframes are considered High Priority but they are not render blocking | ||
const isIframe = resourceTypeCategory === WebInspector.resourceTypes.Document._category | ||
&& request.frameId !== mainResource.frameId; |
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.
niiiiice. let's use _frameId
tho. i think that public api will be changing in our next bump.. haha.
const resourceTypeCategory = request._resourceType && request._resourceType._category; | ||
|
||
// Iframes are considered High Priority but they are not render blocking | ||
const isIframe = resourceTypeCategory === WebInspector.resourceTypes.Document._category | ||
&& request.frameId !== mainResource.frameId; |
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 just verified that the frameid of the iframe resource is the new iframe.. we're good!
*/ | ||
static isCritical(request) { | ||
static isCritical(request, mainResource) { | ||
const resourceTypeCategory = request._resourceType && request._resourceType._category; | ||
|
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.
should we add a console.assert(mainResource, 'mainResource not provided')
?
we'll need https://eslint.org/docs/rules/no-console#options set up
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 could wrap it between disable statements? This is just for debugging purposes right?
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.
actually instead:
const assert = require('assert');
...
assert.ok(mainResource, 'mainResource not provided');
// 2nd record is an iframe in the page | ||
networkRecords[1].url = 'https://example.com/iframe.html'; | ||
networkRecords[1].mimeType = 'text/html'; | ||
networkRecords[1]._resourceType._category = WebInspector.resourceTypes.Document._category; |
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.
along with the change above, this can now be
networkRecords[1]._resourceType = WebInspector.resourceTypes.Document;
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.
awesome thanks @wardpeet!
Fixes #3443
It was pretty hard after all to see if a html document was an iframe or not.
I needed this for the preload audit.