From f3f54f97daf6fe9bc719bd26d48aa938d9ae8e7c Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Tue, 16 May 2017 10:18:36 -0700 Subject: [PATCH 1/3] fix: switch back to waiting for 0-quiet --- lighthouse-core/gather/driver.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lighthouse-core/gather/driver.js b/lighthouse-core/gather/driver.js index 8a588bf45f50..3c0e1da6f14e 100644 --- a/lighthouse-core/gather/driver.js +++ b/lighthouse-core/gather/driver.js @@ -397,7 +397,7 @@ class Driver { const promise = new Promise((resolve, reject) => { const onIdle = () => { // eslint-disable-next-line no-use-before-define - this._networkStatusMonitor.once('network-2-busy', onBusy); + this._networkStatusMonitor.once('networkbusy', onBusy); idleTimeout = setTimeout(_ => { cancel(); resolve(); @@ -405,17 +405,17 @@ class Driver { }; const onBusy = () => { - this._networkStatusMonitor.once('network-2-idle', onIdle); + this._networkStatusMonitor.once('networkidle', onIdle); clearTimeout(idleTimeout); }; cancel = () => { clearTimeout(idleTimeout); - this._networkStatusMonitor.removeListener('network-2-busy', onBusy); - this._networkStatusMonitor.removeListener('network-2-idle', onIdle); + this._networkStatusMonitor.removeListener('networkbusy', onBusy); + this._networkStatusMonitor.removeListener('networkidle', onIdle); }; - if (this._networkStatusMonitor.is2Idle()) { + if (this._networkStatusMonitor.isIdle()) { onIdle(); } else { onBusy(); From 1ec7f5db596de7f59cdb5baa31b582f352744018 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Wed, 17 May 2017 16:00:41 -0700 Subject: [PATCH 2/3] Revert "fix: switch back to waiting for 0-quiet" This reverts commit f3f54f97daf6fe9bc719bd26d48aa938d9ae8e7c. --- lighthouse-core/gather/driver.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lighthouse-core/gather/driver.js b/lighthouse-core/gather/driver.js index 3c0e1da6f14e..8a588bf45f50 100644 --- a/lighthouse-core/gather/driver.js +++ b/lighthouse-core/gather/driver.js @@ -397,7 +397,7 @@ class Driver { const promise = new Promise((resolve, reject) => { const onIdle = () => { // eslint-disable-next-line no-use-before-define - this._networkStatusMonitor.once('networkbusy', onBusy); + this._networkStatusMonitor.once('network-2-busy', onBusy); idleTimeout = setTimeout(_ => { cancel(); resolve(); @@ -405,17 +405,17 @@ class Driver { }; const onBusy = () => { - this._networkStatusMonitor.once('networkidle', onIdle); + this._networkStatusMonitor.once('network-2-idle', onIdle); clearTimeout(idleTimeout); }; cancel = () => { clearTimeout(idleTimeout); - this._networkStatusMonitor.removeListener('networkbusy', onBusy); - this._networkStatusMonitor.removeListener('networkidle', onIdle); + this._networkStatusMonitor.removeListener('network-2-busy', onBusy); + this._networkStatusMonitor.removeListener('network-2-idle', onIdle); }; - if (this._networkStatusMonitor.isIdle()) { + if (this._networkStatusMonitor.is2Idle()) { onIdle(); } else { onBusy(); From ce686bfcde0bd209c9300c6d37bc691283b0b6c0 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Wed, 17 May 2017 17:04:16 -0700 Subject: [PATCH 3/3] wait for DCL --- lighthouse-core/gather/driver.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lighthouse-core/gather/driver.js b/lighthouse-core/gather/driver.js index 8a588bf45f50..6453df49e367 100644 --- a/lighthouse-core/gather/driver.js +++ b/lighthouse-core/gather/driver.js @@ -382,9 +382,8 @@ class Driver { } /** - * Returns a promise that resolves when the network has been idle for - * `networkQuietThresholdMs` ms and a method to cancel internal network listeners and - * timeout. + * Returns a promise that resolves when the network has been idle (after DCL) for + * `networkQuietThresholdMs` ms and a method to cancel internal network listeners/timeout. * @param {number} networkQuietThresholdMs * @param {number} pauseAfterNetworkQuietMs * @return {{promise: !Promise, cancel: function()}} @@ -409,17 +408,21 @@ class Driver { clearTimeout(idleTimeout); }; + const domContentLoadedListener = () => { + if (this._networkStatusMonitor.is2Idle()) { + onIdle(); + } else { + onBusy(); + } + }; + + this.once('Page.domContentEventFired', domContentLoadedListener); cancel = () => { clearTimeout(idleTimeout); + this.off('Page.domContentEventFired', domContentLoadedListener); this._networkStatusMonitor.removeListener('network-2-busy', onBusy); this._networkStatusMonitor.removeListener('network-2-idle', onIdle); }; - - if (this._networkStatusMonitor.is2Idle()) { - onIdle(); - } else { - onBusy(); - } }).then(() => { // Once idle has been determined wait another pauseAfterLoadMs return new Promise(resolve => setTimeout(resolve, pauseAfterNetworkQuietMs));