From 056e564e4c8a58367092b05e312bf9a535fd7a5b Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Wed, 8 Jun 2022 11:43:58 -0700 Subject: [PATCH] core(driver): do not use target manager in legacy mode (#14079) --- .../gather/driver/network-monitor.js | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/lighthouse-core/gather/driver/network-monitor.js b/lighthouse-core/gather/driver/network-monitor.js index bbc6c86405fe..495daae6c57b 100644 --- a/lighthouse-core/gather/driver/network-monitor.js +++ b/lighthouse-core/gather/driver/network-monitor.js @@ -106,10 +106,17 @@ class NetworkMonitor { this._networkRecorder.on('requestloaded', reEmit('requestloaded')); this._session.on('Page.frameNavigated', this._onFrameNavigated); - this._targetManager.addTargetAttachedListener(this._onTargetAttached); - await this._session.sendCommand('Page.enable'); - await this._targetManager.enable(); + + // Legacy driver does its own target management. + // @ts-expect-error + const isLegacyRunner = Boolean(this._session._domainEnabledCounts); + if (isLegacyRunner) { + this._session.addProtocolMessageListener(this._onProtocolMessage); + } else { + this._targetManager.addTargetAttachedListener(this._onTargetAttached); + await this._targetManager.enable(); + } } /** @@ -119,13 +126,21 @@ class NetworkMonitor { if (!this._targetManager) return; this._session.off('Page.frameNavigated', this._onFrameNavigated); - this._targetManager.removeTargetAttachedListener(this._onTargetAttached); - for (const session of this._sessions.values()) { - session.removeProtocolMessageListener(this._onProtocolMessage); - } + // Legacy driver does its own target management. + // @ts-expect-error + const isLegacyRunner = Boolean(this._session._domainEnabledCounts); + if (isLegacyRunner) { + this._session.removeProtocolMessageListener(this._onProtocolMessage); + } else { + this._targetManager.removeTargetAttachedListener(this._onTargetAttached); - await this._targetManager.disable(); + for (const session of this._sessions.values()) { + session.removeProtocolMessageListener(this._onProtocolMessage); + } + + await this._targetManager.disable(); + } this._frameNavigations = []; this._networkRecorder = undefined;