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: fix main session OOPIF checks for devtools #12533

Merged
merged 3 commits into from
May 25, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lighthouse-core/lib/network-recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class NetworkRecorder extends EventEmitter {
this._records = [];
/** @type {Map<string, NetworkRequest>} */
this._recordsById = new Map();
/** @type {string|null|undefined} */
this._mainSessionId = null;
}

/**
Expand Down Expand Up @@ -205,6 +207,20 @@ class NetworkRecorder extends EventEmitter {
* @return {NetworkRequest|undefined}
*/
_findRealRequestAndSetSession(requestId, sessionId) {
// The very first sessionId processed is always the main sessionId. In all but DevTools,
// this sessionId is undefined. However, in DevTools the main Lighthouse protocol connection
// does send events with sessionId set to a string, because of how DevTools routes the protocol
// to Lighthouse.
// Many places in Lighthouse use `record.sessionId === undefined` to mean that the session is not
// an OOPIF. To maintain this property, we intercept sessionId here and set it to undefined if
// itt matches the first value seen.
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
if (this._mainSessionId === null) {
Copy link
Member

Choose a reason for hiding this comment

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

I wish the roles of undefined and null are reversed for _mainSessionId, but doing so would probably require changes to the protocol and/or large changes to how we handle sessionId downstream. Sounds like a lot of work for a minor annoyance, so this LGTM.

Copy link
Collaborator

Choose a reason for hiding this comment

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

we'll need to take another look at the entire use of sessionId when we revisit FR OOPIF handling which is going to have to be more complex anyway. I'm also fine with a temporary bandaid here

this._mainSessionId = sessionId;
}
if (this._mainSessionId === sessionId) {
sessionId = undefined;
}

let request = this._recordsById.get(requestId);
if (!request || !request.isValid) return undefined;

Expand Down