-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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: make target manager accessible on driver #14122
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
06a655c
core: make targetManager accessible on driver
brendankenny ccc846f
feedback
brendankenny b3a55b2
target-manager-test
brendankenny f78707e
move protocolevent tests from session to target-manager
brendankenny a3bc0c7
network-monitor-test
brendankenny f4d4c8c
driver-test
brendankenny 39b9d64
full-page-screenshot-test
brendankenny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,9 @@ | |
'use strict'; | ||
|
||
const log = require('lighthouse-logger'); | ||
const ProtocolSession = require('./session.js'); | ||
const ExecutionContext = require('../../gather/driver/execution-context.js'); | ||
const Fetcher = require('../../gather/fetcher.js'); | ||
const TargetManager = require('../../gather/driver/target-manager.js'); | ||
|
||
/** @return {*} */ | ||
const throwNotConnectedFn = () => { | ||
|
@@ -24,8 +24,6 @@ const throwingSession = { | |
on: throwNotConnectedFn, | ||
once: throwNotConnectedFn, | ||
off: throwNotConnectedFn, | ||
addProtocolMessageListener: throwNotConnectedFn, | ||
removeProtocolMessageListener: throwNotConnectedFn, | ||
sendCommand: throwNotConnectedFn, | ||
dispose: throwNotConnectedFn, | ||
}; | ||
|
@@ -37,6 +35,8 @@ class Driver { | |
*/ | ||
constructor(page) { | ||
this._page = page; | ||
/** @type {TargetManager|undefined} */ | ||
this._targetManager = undefined; | ||
/** @type {ExecutionContext|undefined} */ | ||
this._executionContext = undefined; | ||
/** @type {Fetcher|undefined} */ | ||
|
@@ -57,6 +57,11 @@ class Driver { | |
return this._fetcher; | ||
} | ||
|
||
get targetManager() { | ||
if (!this._targetManager) return throwNotConnectedFn(); | ||
return this._targetManager; | ||
} | ||
|
||
/** @return {Promise<string>} */ | ||
async url() { | ||
return this._page.url(); | ||
|
@@ -67,8 +72,10 @@ class Driver { | |
if (this.defaultSession !== throwingSession) return; | ||
const status = {msg: 'Connecting to browser', id: 'lh:driver:connect'}; | ||
log.time(status); | ||
const session = await this._page.target().createCDPSession(); | ||
this.defaultSession = new ProtocolSession(session); | ||
const cdpSession = await this._page.target().createCDPSession(); | ||
this._targetManager = new TargetManager(cdpSession); | ||
await this._targetManager.enable(); | ||
this.defaultSession = this._targetManager.rootSession(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'd love to s/defaultSession/rootSession/g but fine with it happening in a followup. |
||
this._executionContext = new ExecutionContext(this.defaultSession); | ||
this._fetcher = new Fetcher(this.defaultSession); | ||
log.timeEnd(status); | ||
|
@@ -77,6 +84,7 @@ class Driver { | |
/** @return {Promise<void>} */ | ||
async disconnect() { | ||
if (this.defaultSession === throwingSession) return; | ||
this._targetManager?.disable(); | ||
await this.defaultSession.dispose(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because
TargetManager
is in charge of creating FRProtocolSession
s fromCDPSession
s, and we want to eventually make those sessions available for gatherers to access directly, Driver now gets itsdriver.defaultSession
from targetManager instead of making it itself. This is a little weird, but otherwise we have two different session objects pointing to the same thing. This seemed conceptually simpler (driver setup is a little more involved but it means the set of all active sessions includesdefaultSession
) but open to ideas.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Big fan of avoiding the double session object! (I was seeing that at the CDP traffic level. so weird.)