-
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: throw fatally on page hang #6497
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!doctype html> | ||
<!-- | ||
* Copyright 2018 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
--> | ||
<html> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1"> | ||
<body> | ||
This is the function that never ends | ||
Yes, it just goes on and on my friends. | ||
Some people started computing it, not knowing what it was. | ||
And they'll continue computing it forever just because, | ||
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. 🤣 |
||
This is the function that never ends. | ||
|
||
<script> | ||
while (true) { | ||
for (let i = 0; i < 1000000; i++) ; | ||
} | ||
</script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* @license Copyright 2018 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
/** | ||
* Config file for sites with various errors, just fail out quickly. | ||
*/ | ||
module.exports = { | ||
extends: 'lighthouse:default', | ||
settings: { | ||
maxWaitForLoad: 5000, | ||
onlyAudits: [ | ||
'first-contentful-paint', | ||
], | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* @license Copyright 2018 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
/** | ||
* Expected Lighthouse audit values for sites with various errors. | ||
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. 🎉 |
||
*/ | ||
module.exports = [ | ||
{ | ||
requestedUrl: 'http://localhost:10200/infinite-loop.html', | ||
finalUrl: 'http://localhost:10200/infinite-loop.html', | ||
errorCode: 'PAGE_HUNG', | ||
audits: {}, | ||
}, | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -369,6 +369,7 @@ class Driver { | |
includeCommandLineAPI: true, | ||
awaitPromise: true, | ||
returnByValue: true, | ||
timeout: 60000, | ||
contextId, | ||
}; | ||
|
||
|
@@ -687,6 +688,25 @@ class Driver { | |
}; | ||
} | ||
|
||
/** | ||
* Returns whether the page appears to be hung. | ||
* @return {Promise<boolean>} | ||
*/ | ||
async isPageHung() { | ||
try { | ||
this.setNextProtocolTimeout(1000); | ||
await this.sendCommand('Runtime.evaluate', { | ||
expression: '"ping"', | ||
returnByValue: true, | ||
timeout: 1000, | ||
}); | ||
|
||
return false; | ||
} catch (err) { | ||
return true; | ||
} | ||
} | ||
|
||
/** | ||
* Returns a promise that resolves when: | ||
* - All of the following conditions have been met: | ||
|
@@ -736,11 +756,18 @@ class Driver { | |
const maxTimeoutPromise = new Promise((resolve, reject) => { | ||
maxTimeoutHandle = setTimeout(resolve, maxWaitForLoadedMs); | ||
}).then(_ => { | ||
return function() { | ||
log.warn('Driver', 'Timed out waiting for page load. Moving on...'); | ||
return async () => { | ||
log.warn('Driver', 'Timed out waiting for page load. Checking if page is hung...'); | ||
waitForLoadEvent.cancel(); | ||
waitForNetworkIdle.cancel(); | ||
waitForCPUIdle && waitForCPUIdle.cancel(); | ||
|
||
if (await this.isPageHung()) { | ||
log.warn('Driver', 'Page appears to be hung, killing JavaScript...'); | ||
await this.sendCommand('Emulation.setScriptExecutionDisabled', {value: true}); | ||
await this.sendCommand('Runtime.terminateExecution'); | ||
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 think we should also run 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. done |
||
throw new LHError(LHError.errors.PAGE_HUNG); | ||
} | ||
}; | ||
}); | ||
|
||
|
@@ -749,7 +776,7 @@ class Driver { | |
loadPromise, | ||
maxTimeoutPromise, | ||
]); | ||
cleanupFn(); | ||
await cleanupFn(); | ||
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. now necessary since we have the awaits inside of maxTimeoutPromise, right? 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. well the awaits are inside the function that it returns too, so we want to wait to find out if the page is hung before moving on 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. order of execution is
we don't want to be doing our killing and hang check while we're trying to see if the page is quiet. |
||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,6 +148,12 @@ const ERRORS = { | |
message: strings.pageLoadFailedInsecure, | ||
lhrRuntimeError: true, | ||
}, | ||
/* Used when the page stopped responding and did not finish loading. */ | ||
PAGE_HUNG: { | ||
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. this'll need to go into the proto. :) 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. done |
||
code: 'PAGE_HUNG', | ||
message: strings.pageLoadFailedHung, | ||
lhrRuntimeError: true, | ||
}, | ||
|
||
// Protocol internal failures | ||
TRACING_ALREADY_STARTED: { | ||
|
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.
license
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