Skip to content

Commit

Permalink
Correctly handle browser navigation and page change errors
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Feb 23, 2023
1 parent 7fa65fe commit b074861
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,24 @@ function waitUntilEnterPressed(error_log) {
readline.question('Press ENTER to continue...');
}

async function runInstruction(loadedInstruction, page, extras) {
try {
await loadedInstruction(page, extras);
return;
} catch (err) { // execution error
if (err.message && err.message.indexOf && err.message.indexOf("Execution context was destroyed") === 0) {
// Puppeteer error so this time we wait until the document is ready before trying
// again.
await page.waitForFunction('document.readyState === "complete"');
} else {
// Not a context error because of navigation, throwing it again.
throw err;
}
}
// We give it another chance...
await loadedInstruction(page, extras);
}

async function runAllCommands(loaded, logs, options, browser) {
logs.append(loaded['file'] + '... ');
const context_parser = loaded['parser'];
Expand Down Expand Up @@ -229,7 +247,6 @@ async function runAllCommands(loaded, logs, options, browser) {
return checkPageErrors('failOnRequestError', 'requestErrors', 'request failed');
};


let error_log = '';
const warnings = [];
let current_url = '';
Expand Down Expand Up @@ -276,7 +293,7 @@ async function runAllCommands(loaded, logs, options, browser) {
break command_loop;
}
try {
await loadedInstruction(page, extras);
await runInstruction(loadedInstruction, page, extras);
} catch (err) { // execution error
if (err === commands_parser.COLOR_CHECK_ERROR) {
error_log += `[ERROR] (line ${line_number}): ${err}\n`;
Expand Down

0 comments on commit b074861

Please sign in to comment.