-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
feat: configurable page timeout #1672
Changes from 5 commits
9da9013
e47b102
b87ef4b
4012ca7
a5b1cf2
67a85dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,10 +25,12 @@ const URL = require('../lib/url-shim'); | |
const log = require('../lib/log.js'); | ||
const DevtoolsLog = require('./devtools-log'); | ||
|
||
const MAX_WAIT_FOR_FULLY_LOADED = 25 * 1000; | ||
const PAUSE_AFTER_LOAD = 500; | ||
|
||
class Driver { | ||
static get MAX_WAIT_FOR_FULLY_LOADED() { | ||
return 25 * 1000; | ||
} | ||
|
||
/** | ||
* @param {!Connection} connection | ||
|
@@ -417,13 +419,14 @@ class Driver { | |
* Returns a promise that resolves when: | ||
* - it's been pauseAfterLoadMs milliseconds after both onload and the network | ||
* has gone idle, or | ||
* - MAX_WAIT_FOR_FULLY_LOADED milliseconds have passed. | ||
* - maxWaitForLoadedMs milliseconds have passed. | ||
* See https://github.com/GoogleChrome/lighthouse/issues/627 for more. | ||
* @param {number} pauseAfterLoadMs | ||
* @param {number} maxWaitForLoadedMs | ||
* @return {!Promise} | ||
* @private | ||
*/ | ||
_waitForFullyLoaded(pauseAfterLoadMs) { | ||
_waitForFullyLoaded(pauseAfterLoadMs, maxWaitForLoadedMs) { | ||
let maxTimeoutHandle; | ||
|
||
// Listener for onload. Resolves pauseAfterLoadMs ms after load. | ||
|
@@ -443,10 +446,10 @@ class Driver { | |
}; | ||
}); | ||
|
||
// Last resort timeout. Resolves MAX_WAIT_FOR_FULLY_LOADED ms from now on | ||
// Last resort timeout. Resolves maxWaitForLoadedMs ms from now on | ||
// cleanup function that removes loadEvent and network idle listeners. | ||
const maxTimeoutPromise = new Promise((resolve, reject) => { | ||
maxTimeoutHandle = setTimeout(resolve, MAX_WAIT_FOR_FULLY_LOADED); | ||
maxTimeoutHandle = setTimeout(resolve, maxWaitForLoadedMs); | ||
}).then(_ => { | ||
return function() { | ||
log.warn('Driver', 'Timed out waiting for page load. Moving on...'); | ||
|
@@ -472,16 +475,17 @@ class Driver { | |
* @param {!Object} options | ||
* @return {!Promise} | ||
*/ | ||
gotoURL(url, options) { | ||
const _options = options || {}; | ||
const waitForLoad = _options.waitForLoad || false; | ||
const disableJS = _options.disableJavaScript || false; | ||
const pauseAfterLoadMs = (_options.flags && _options.flags.pauseAfterLoad) || PAUSE_AFTER_LOAD; | ||
gotoURL(url, options = {}) { | ||
const waitForLoad = options.waitForLoad || false; | ||
const disableJS = options.disableJavaScript || false; | ||
const pauseAfterLoadMs = (options.flags && options.flags.pauseAfterLoad) || PAUSE_AFTER_LOAD; | ||
const maxWaitMs = (options.flags && options.flags.maxWaitForLoad) || | ||
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. should we support 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 would say that would lead to a useless lighthouse run that wouldn't return any results so filling in default is fine with me :) |
||
Driver.MAX_WAIT_FOR_FULLY_LOADED; | ||
|
||
return this.sendCommand('Page.enable') | ||
.then(_ => this.sendCommand('Emulation.setScriptExecutionDisabled', {value: disableJS})) | ||
.then(_ => this.sendCommand('Page.navigate', {url})) | ||
.then(_ => waitForLoad && this._waitForFullyLoaded(pauseAfterLoadMs)); | ||
.then(_ => waitForLoad && this._waitForFullyLoaded(pauseAfterLoadMs, maxWaitMs)); | ||
} | ||
|
||
/** | ||
|
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.
how would this be possible? AFAIK, yargs creates the former and makes sure they match at this point.
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.
The bug as mentioned in the above identical check makes this happen when the default is used.
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.
How do we feel about updating yargs? Current is 6.6.0 :(
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.
What was the google3 dependency on yargs that kept us here, are they game to update?
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.
suspect that's it. Just complaining out loud that that restriction continues to hold us back.
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.
Let's bump yargs from our 3.30.0 to 3.32.0.
It has the fix for these: yargs/yargs@51c0063
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.
done, from the looks of it google3 is still on lighthouse ~1.1 so we likely will have quite a few other issues to iron out when they want to upgrade anyway...