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(driver): do not use target manager in legacy mode #14079

Merged
merged 6 commits into from
Jun 8, 2022
Merged
Changes from all 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
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);
Copy link
Member

Choose a reason for hiding this comment

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

Are you planning to remove this hack as part of #14078, or once the legacy runner is removed?

Copy link
Member

Choose a reason for hiding this comment

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

IMO the latter. (once the legacy runner is removed)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

uh, whatever comes first?

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