-
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(driver): add waitForFCP timeout #7356
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ac5f9f4
core(driver): add waitForFCP timeout
patrickhulce 7905fe5
extra test for fix
patrickhulce a571bf0
snapshots
patrickhulce e69e3f1
Update types/externs.d.ts
brendankenny 83c043e
lower to 15s
patrickhulce 9c708e4
gzip fix
patrickhulce 5030864
Merge branch 'master' into max_wait_for_fcp
patrickhulce cbce736
Merge branch 'master' into max_wait_for_fcp
patrickhulce 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
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 |
---|---|---|
|
@@ -13,5 +13,6 @@ | |
<script src="script.js"></script> | ||
</head> | ||
<body> | ||
GZIP FTW! | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -562,20 +562,25 @@ class Driver { | |
|
||
/** | ||
* Returns a promise that resolve when a frame has a FCP. | ||
* @param {number} maxWaitForFCPMs | ||
* @return {{promise: Promise<void>, cancel: function(): void}} | ||
*/ | ||
_waitForFCP() { | ||
_waitForFCP(maxWaitForFCPMs) { | ||
/** @type {(() => void)} */ | ||
let cancel = () => { | ||
throw new Error('_waitForFCP.cancel() called before it was defined'); | ||
}; | ||
|
||
const promise = new Promise(resolve => { | ||
const promise = new Promise((resolve, reject) => { | ||
const maxWaitTimeout = setTimeout(() => { | ||
reject(new LHError(LHError.errors.NO_FCP)); | ||
}, maxWaitForFCPMs); | ||
|
||
/** @param {LH.Crdp.Page.LifecycleEventEvent} e */ | ||
const lifecycleListener = e => { | ||
if (e.name === 'firstContentfulPaint') { | ||
cancel(); | ||
resolve(); | ||
cancel(); | ||
} | ||
}; | ||
|
||
|
@@ -586,6 +591,8 @@ class Driver { | |
if (canceled) return; | ||
canceled = true; | ||
this.off('Page.lifecycleEvent', lifecycleListener); | ||
maxWaitTimeout && clearTimeout(maxWaitTimeout); | ||
reject(new Error('Wait for FCP canceled')); | ||
}; | ||
}); | ||
|
||
|
@@ -857,17 +864,17 @@ class Driver { | |
* @param {number} networkQuietThresholdMs | ||
* @param {number} cpuQuietThresholdMs | ||
* @param {number} maxWaitForLoadedMs | ||
* @param {boolean} shouldWaitForFCP | ||
* @param {number=} maxWaitForFCPMs | ||
* @return {Promise<void>} | ||
* @private | ||
*/ | ||
async _waitForFullyLoaded(pauseAfterLoadMs, networkQuietThresholdMs, cpuQuietThresholdMs, | ||
maxWaitForLoadedMs, shouldWaitForFCP) { | ||
maxWaitForLoadedMs, maxWaitForFCPMs) { | ||
/** @type {NodeJS.Timer|undefined} */ | ||
let maxTimeoutHandle; | ||
|
||
// Listener for onload. Resolves on first FCP event. | ||
const waitForFCP = shouldWaitForFCP ? this._waitForFCP() : this._waitForNothing(); | ||
const waitForFCP = maxWaitForFCPMs ? this._waitForFCP(maxWaitForFCPMs) : this._waitForNothing(); | ||
// Listener for onload. Resolves pauseAfterLoadMs ms after load. | ||
const waitForLoadEvent = this._waitForLoadEvent(pauseAfterLoadMs); | ||
// Network listener. Resolves when the network has been idle for networkQuietThresholdMs. | ||
|
@@ -895,6 +902,11 @@ class Driver { | |
return function() { | ||
log.verbose('Driver', 'loadEventFired and network considered idle'); | ||
}; | ||
}).catch(err => { | ||
// Throw the error in the cleanupFn so we still cleanup all our handlers. | ||
return function() { | ||
throw err; | ||
}; | ||
}); | ||
|
||
// Last resort timeout. Resolves maxWaitForLoadedMs ms from now on | ||
|
@@ -1038,7 +1050,7 @@ class Driver { | |
await this.sendCommand('Page.enable'); | ||
await this.sendCommand('Page.setLifecycleEventsEnabled', {enabled: true}); | ||
await this.sendCommand('Emulation.setScriptExecutionDisabled', {value: disableJS}); | ||
// No timeout needed for Page.navigate. See #6413. | ||
// No timeout needed for Page.navigate. See https://github.com/GoogleChrome/lighthouse/pull/6413. | ||
const waitforPageNavigateCmd = this._innerSendCommand('Page.navigate', {url}); | ||
|
||
if (waitForNavigated) { | ||
|
@@ -1047,19 +1059,22 @@ class Driver { | |
const passConfig = /** @type {Partial<LH.Config.Pass>} */ (passContext.passConfig || {}); | ||
let {pauseAfterLoadMs, networkQuietThresholdMs, cpuQuietThresholdMs} = passConfig; | ||
let maxWaitMs = passContext.settings && passContext.settings.maxWaitForLoad; | ||
let maxFCPMs = passContext.settings && passContext.settings.maxWaitForFcp; | ||
|
||
/* eslint-disable max-len */ | ||
if (typeof pauseAfterLoadMs !== 'number') pauseAfterLoadMs = DEFAULT_PAUSE_AFTER_LOAD; | ||
if (typeof networkQuietThresholdMs !== 'number') networkQuietThresholdMs = DEFAULT_NETWORK_QUIET_THRESHOLD; | ||
if (typeof cpuQuietThresholdMs !== 'number') cpuQuietThresholdMs = DEFAULT_CPU_QUIET_THRESHOLD; | ||
if (typeof maxWaitMs !== 'number') maxWaitMs = constants.defaultSettings.maxWaitForLoad; | ||
if (typeof maxFCPMs !== 'number') maxFCPMs = constants.defaultSettings.maxWaitForFcp; | ||
/* eslint-enable max-len */ | ||
|
||
if (!waitForFCP) maxFCPMs = undefined; | ||
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. it's a little confusing that there are two similar-but-different parameters for this, but this way does seem to make the most sense from both gather-runner and driver's perspectives, so I guess this is where we live now :) |
||
await this._waitForFullyLoaded(pauseAfterLoadMs, networkQuietThresholdMs, cpuQuietThresholdMs, | ||
maxWaitMs, waitForFCP); | ||
maxWaitMs, maxFCPMs); | ||
} | ||
|
||
// Bring `Page.navigate` errors back into the promise chain. See #6739. | ||
// Bring `Page.navigate` errors back into the promise chain. See https://github.com/GoogleChrome/lighthouse/pull/6739. | ||
await waitforPageNavigateCmd; | ||
|
||
return this._endNetworkStatusMonitoring(); | ||
|
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
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.
this isn't getting easier to follow... :P
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.
no, it's not, but it's very well tested now and ready for refactoring :)