Skip to content
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

Merged
merged 7 commits into from
Oct 20, 2017

Conversation

wardpeet
Copy link
Collaborator

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.

@@ -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
Copy link
Collaborator

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?

Copy link
Collaborator Author

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?

Copy link
Collaborator

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}
Copy link
Collaborator

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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect! 💯

Copy link
Member

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.

Copy link
Member

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
Copy link
Collaborator

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);
Copy link
Collaborator

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)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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';
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

Copy link
Member

@paulirish paulirish left a 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;
Copy link
Member

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;
Copy link
Member

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;

Copy link
Member

@paulirish paulirish Oct 19, 2017

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

Copy link
Collaborator Author

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?

Copy link
Member

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;
Copy link
Member

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;

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome thanks @wardpeet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants