Skip to content

Commit 0ce149c

Browse files
Merge pull request #727 from GuillaumeGomez/handle-execution-context-destroyed
Handle "execution context was destroyed" errors in changing page waiter
2 parents 6ab0245 + 5c9ba7d commit 0ce149c

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ async function runInstruction(loadedInstruction, pages, extras) {
175175
return;
176176
} catch (err) { // execution error
177177
if (err.message && err.message.indexOf
178-
&& err.message.indexOf('Execution context was destroyed') === 0) {
178+
&& err.message.indexOf('Execution context was destroyed') === 0
179+
) {
179180
// Puppeteer error so this time we wait until the document is ready before trying
180181
// again.
181182
await pages[0].waitForFunction('document.readyState === "complete"');

src/utils.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,21 @@ async function waitForConditionTrue(pages, callback) {
206206

207207
// eslint-disable-next-line no-constant-condition
208208
while (true) {
209-
if (await callback()) {
210-
return true;
211-
}
212-
if (timeLimit === 0) {
213-
continue;
209+
try {
210+
if (await callback()) {
211+
return true;
212+
}
213+
if (timeLimit === 0) {
214+
continue;
215+
}
216+
} catch (err) {
217+
if (err.message && err.message.indexOf
218+
&& err.message.indexOf('Execution context was destroyed') === 0
219+
) {
220+
// "All good", we continue to wait.
221+
} else {
222+
throw err;
223+
}
214224
}
215225
allTime += timeAdd;
216226
if (allTime >= timeLimit) {

0 commit comments

Comments
 (0)