Skip to content
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 check to make sure Runtime.evaluate result exists #6089

Merged
merged 7 commits into from
Sep 24, 2018
20 changes: 14 additions & 6 deletions lighthouse-core/gather/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,15 +311,23 @@ class Driver {
contextId,
};

this.sendCommand('Runtime.evaluate', evaluationParams).then(result => {
this.sendCommand('Runtime.evaluate', evaluationParams).then(response => {
clearTimeout(asyncTimeout);
const value = result.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) {
reject(Object.assign(new Error(), value));
return reject(new Error(`Evaluation exception: ${response.exceptionDetails.text}`));
}

// 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'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know @paulirish just said this, but "omits" is weird here. At least "omitted", maybe "did not contain"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also felt like "a result" was confusing, so clarified it is a "result" object that wasn't there.

}

const value = response.result.value;

if (value && value.__failedInBrowser) {
return reject(Object.assign(new Error(), value));
} else {
resolve(value);
}
Expand Down