From d3dbc446b7fe6ab187cb8266055119f42db9d1a7 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Fri, 21 May 2021 11:25:10 -0700 Subject: [PATCH 1/3] core(network-recorder): fix main session OOPIF checks for devtools --- lighthouse-core/lib/network-recorder.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lighthouse-core/lib/network-recorder.js b/lighthouse-core/lib/network-recorder.js index d20bc480538b..e38daa8c3ec5 100644 --- a/lighthouse-core/lib/network-recorder.js +++ b/lighthouse-core/lib/network-recorder.js @@ -21,6 +21,8 @@ class NetworkRecorder extends EventEmitter { this._records = []; /** @type {Map} */ this._recordsById = new Map(); + /** @type {string|null|undefined} */ + this._mainSessionId = null; } /** @@ -205,6 +207,13 @@ class NetworkRecorder extends EventEmitter { * @return {NetworkRequest|undefined} */ _findRealRequestAndSetSession(requestId, sessionId) { + if (this._mainSessionId === null) { + this._mainSessionId = sessionId; + } + if (this._mainSessionId === sessionId) { + sessionId = undefined; + } + let request = this._recordsById.get(requestId); if (!request || !request.isValid) return undefined; From 57db5f47b2bf6bc49e4ad59c641e1ac8262d91f1 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Fri, 21 May 2021 11:36:28 -0700 Subject: [PATCH 2/3] comment --- lighthouse-core/lib/network-recorder.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lighthouse-core/lib/network-recorder.js b/lighthouse-core/lib/network-recorder.js index e38daa8c3ec5..db12e47ff4a0 100644 --- a/lighthouse-core/lib/network-recorder.js +++ b/lighthouse-core/lib/network-recorder.js @@ -207,6 +207,13 @@ 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. if (this._mainSessionId === null) { this._mainSessionId = sessionId; } From 8f338224c56627935afaa467cd5b9835d1cc0a67 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Fri, 21 May 2021 11:39:48 -0700 Subject: [PATCH 3/3] Update lighthouse-core/lib/network-recorder.js --- lighthouse-core/lib/network-recorder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lighthouse-core/lib/network-recorder.js b/lighthouse-core/lib/network-recorder.js index db12e47ff4a0..3149e9519aa3 100644 --- a/lighthouse-core/lib/network-recorder.js +++ b/lighthouse-core/lib/network-recorder.js @@ -213,7 +213,7 @@ class NetworkRecorder extends EventEmitter { // 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. + // it matches the first value seen. if (this._mainSessionId === null) { this._mainSessionId = sessionId; }