Skip to content

Commit

Permalink
core(driver): do not use target manager in legacy mode (#14079)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark authored Jun 8, 2022
1 parent c463c4e commit 056e564
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions lighthouse-core/gather/driver/network-monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

/**
Expand All @@ -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;
Expand Down

0 comments on commit 056e564

Please sign in to comment.