Skip to content

Conversation

@adamraine
Copy link
Contributor

@adamraine adamraine commented Jan 26, 2023

Alternative to #14716

From what I can tell, we only access the initiator information when looking at network records constructed from the DevtoolsLog. I think it makes sense to encapsulate this with the DevtoolsLog.

@adamraine
Copy link
Contributor Author

adamraine commented Jan 26, 2023

This PR has become a bit of a rabbit hole. While I do think it would be good to land this in the long term, it opens the door for some more complex challenges relating to scripts gathering and third parties.

Incoming brain dump...

Calling Debugger.enable when the domain is disabled will flush any Debugger.scriptParsed events that the session hadn't emitted yet. Since this only happens when the domain was in the disabled state, the events are emitted on the first invocation of Debugger.enable which previously happened in prepare.js as part of our navigation/timespan prework.

This PR moves that invocation into the DevtoolsLog gatherer, which moves the new first invocation of Debugger.enable into the Scripts gatherer. This doesn't mean anything for navigation mode, since the domain will always be enabled while we are on about:blank before the navigation starts. However, timespan mode can start on an already loaded page, which means there could be Debugger.scriptParsed events waiting to emit that will now be caught by the Scripts gatherer since the first invocation of Debugger.enable happens there. This means timespan mode will collect all scripts that are loaded during the timespan, as well as any scripts that were on the page at the start of the timespan. In theory this is a better way of collecting scripts for an arbitrary timespan however...

With the introduction of the new 3P system, we will throw an error if we encounter a url that doesn't exist in the network records. Now we are collecting scripts that weren't fetched during the timespan, which can cause this error to be thrown if we attempt to use a url from one of the pre-timespan scripts in say the valid-source-map audit:

static isLargeFirstPartyJS(script, classifiedEntities) {
if (!script.length) return false;
const isLargeJS = script.length >= LARGE_JS_BYTE_THRESHOLD;
const isFirstPartyJS = script.url ? classifiedEntities.isFirstParty(script.url) : false;
return isLargeJS && isFirstPartyJS;
}

In the future, I imagine we will classify the urls in Scripts but for now I think the easiest workaround is to call Debugger.enable in the navigation/timespan prework so all the Debugger.scriptParsed events are flushed before gathering starts. Or we could just do #14716 w/ @brendankenny's suggestions.

@connorjclark
Copy link
Collaborator

With the introduction of the new 3P system, we will throw an error if we encounter a url that doesn't exist in the network records.

As of #15009 this is no longer the case.

@adamraine still want to do this PR?

@adamraine
Copy link
Contributor Author

It has some organizational benefits, but I don't see myself spending any time on it in the near future

@adamraine adamraine closed this Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants