From 80342871031e07dee85c40a7cc443b9b5252f77a Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Fri, 21 Sep 2018 15:33:52 -0700 Subject: [PATCH 1/7] Added check to make sure Protocol Runtime evaluate result exists. --- lighthouse-core/gather/driver.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lighthouse-core/gather/driver.js b/lighthouse-core/gather/driver.js index 7ed571c6034d..a2634425b11d 100644 --- a/lighthouse-core/gather/driver.js +++ b/lighthouse-core/gather/driver.js @@ -313,6 +313,13 @@ class Driver { this.sendCommand('Runtime.evaluate', evaluationParams).then(result => { clearTimeout(asyncTimeout); + + // Protocol should always return a 'result' object, but it is sometimes undefined + // see https://github.com/GoogleChrome/lighthouse/issues/6026 + if (result.result === undefined) { + return reject(new Error('Driver did not sent a result object')); + } + const value = result.result.value; if (result.exceptionDetails) { From 6385308002d50d089e24f2277c405b8b3b11e584 Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Fri, 21 Sep 2018 16:42:23 -0700 Subject: [PATCH 2/7] Changed result to response. Added an else to the else-if chain. --- 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 a2634425b11d..6aede53acab3 100644 --- a/lighthouse-core/gather/driver.js +++ b/lighthouse-core/gather/driver.js @@ -311,21 +311,21 @@ class Driver { contextId, }; - this.sendCommand('Runtime.evaluate', evaluationParams).then(result => { + this.sendCommand('Runtime.evaluate', evaluationParams).then(response => { clearTimeout(asyncTimeout); // Protocol should always return a 'result' object, but it is sometimes undefined // see https://github.com/GoogleChrome/lighthouse/issues/6026 - if (result.result === undefined) { + if (response.result === undefined) { return reject(new Error('Driver did not sent a result object')); } - const value = result.result.value; + const value = response.result.value; - if (result.exceptionDetails) { + if (response.exceptionDetails) { // An error occurred before we could even create a Promise, should be *very* rare reject(new Error('an unexpected driver error occurred')); - } if (value && value.__failedInBrowser) { + } else if (value && value.__failedInBrowser) { reject(Object.assign(new Error(), value)); } else { resolve(value); From e865db19304d8f6eb41251a48f80adc404f20962 Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Fri, 21 Sep 2018 16:56:19 -0700 Subject: [PATCH 3/7] Refactored order of checking response properties. --- lighthouse-core/gather/driver.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lighthouse-core/gather/driver.js b/lighthouse-core/gather/driver.js index 6aede53acab3..940254040933 100644 --- a/lighthouse-core/gather/driver.js +++ b/lighthouse-core/gather/driver.js @@ -314,6 +314,11 @@ class Driver { this.sendCommand('Runtime.evaluate', evaluationParams).then(response => { clearTimeout(asyncTimeout); + if (response.exceptionDetails) { + // An error occurred before we could even create a Promise, should be *very* rare + return reject(new Error('an unexpected driver error occurred')); + } + // Protocol should always return a 'result' object, but it is sometimes undefined // see https://github.com/GoogleChrome/lighthouse/issues/6026 if (response.result === undefined) { @@ -322,10 +327,7 @@ class Driver { const value = response.result.value; - if (response.exceptionDetails) { - // An error occurred before we could even create a Promise, should be *very* rare - reject(new Error('an unexpected driver error occurred')); - } else if (value && value.__failedInBrowser) { + if (value && value.__failedInBrowser) { reject(Object.assign(new Error(), value)); } else { resolve(value); From 75bbef5f6ce77ce4abc48a869d646073b0e68cc2 Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Fri, 21 Sep 2018 17:10:02 -0700 Subject: [PATCH 4/7] Added return to reject. --- lighthouse-core/gather/driver.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lighthouse-core/gather/driver.js b/lighthouse-core/gather/driver.js index 940254040933..dd2e8dccd13a 100644 --- a/lighthouse-core/gather/driver.js +++ b/lighthouse-core/gather/driver.js @@ -328,7 +328,7 @@ class Driver { const value = response.result.value; if (value && value.__failedInBrowser) { - reject(Object.assign(new Error(), value)); + return reject(Object.assign(new Error(), value)); } else { resolve(value); } From 1a6d0fb2aed5b63ca84725184c62cb3d5744204f Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Fri, 21 Sep 2018 17:42:24 -0700 Subject: [PATCH 5/7] Changed wording of comments and exceptions. --- lighthouse-core/gather/driver.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lighthouse-core/gather/driver.js b/lighthouse-core/gather/driver.js index dd2e8dccd13a..9536e91ae227 100644 --- a/lighthouse-core/gather/driver.js +++ b/lighthouse-core/gather/driver.js @@ -316,13 +316,12 @@ class Driver { if (response.exceptionDetails) { // An error occurred before we could even create a Promise, should be *very* rare - return reject(new Error('an unexpected driver error occurred')); + return reject(new Error('Evaluation exception: ${response.exceptionDetails.text}')); } - // Protocol should always return a 'result' object, but it is sometimes undefined - // see https://github.com/GoogleChrome/lighthouse/issues/6026 + // Protocol should always return a 'result' object, but it is sometimes undefined. See #6026. if (response.result === undefined) { - return reject(new Error('Driver did not sent a result object')); + return reject(new Error('Runtime.evaluate response omits a result')); } const value = response.result.value; From dc13d347beed2c22b8305e68cc1d97efcac85088 Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Fri, 21 Sep 2018 18:11:39 -0700 Subject: [PATCH 6/7] Added backticks! --- lighthouse-core/gather/driver.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lighthouse-core/gather/driver.js b/lighthouse-core/gather/driver.js index 9536e91ae227..0dd73660ab00 100644 --- a/lighthouse-core/gather/driver.js +++ b/lighthouse-core/gather/driver.js @@ -316,7 +316,7 @@ class Driver { if (response.exceptionDetails) { // An error occurred before we could even create a Promise, should be *very* rare - return reject(new Error('Evaluation exception: ${response.exceptionDetails.text}')); + return reject(new Error(`Evaluation exception: ${response.exceptionDetails.text}`)); } // Protocol should always return a 'result' object, but it is sometimes undefined. See #6026. From 6f17f8d7a3e5d77d2705d11ccac48890bc351382 Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Fri, 21 Sep 2018 18:28:07 -0700 Subject: [PATCH 7/7] Changed wording on response error msg. --- lighthouse-core/gather/driver.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lighthouse-core/gather/driver.js b/lighthouse-core/gather/driver.js index 0dd73660ab00..e55b2cfaadf3 100644 --- a/lighthouse-core/gather/driver.js +++ b/lighthouse-core/gather/driver.js @@ -321,7 +321,7 @@ class Driver { // Protocol should always return a 'result' object, but it is sometimes undefined. See #6026. if (response.result === undefined) { - return reject(new Error('Runtime.evaluate response omits a result')); + return reject(new Error('Runtime.evaluate response did not contain a "result" object')); } const value = response.result.value;