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

BugFix: Always close all pages and then the browser, fixes #2 #18

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions usappointment.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,7 @@ const axios = require('axios');
}
//#endregion

async function runLogic() {
//#region Init puppeteer
const browser = await puppeteer.launch();
// Comment above line and uncomment following line to see puppeteer in action
//const browser = await puppeteer.launch({ headless: false });
async function runLogic(browser) {
const page = await browser.newPage();
const timeout = 5000;
const navigationTimeout = 60000;
Expand Down Expand Up @@ -341,16 +337,29 @@ const axios = require('axios');
//#endregion
}

async function close(browser) {
const pages = await browser.pages();
for (let i = 0; i < pages.length; i++) {
await pages[i].close();
}
await browser.close();
}

while (true){
// Change value of headless to "false" to see puppeteer in action
const browser = await puppeteer.launch({ headless: true });

try{
const result = await runLogic();
const result = await runLogic(browser);

if (result){
notify("Successfully scheduled a new appointment");
break;
}
} catch (err){
// Swallow the error and keep running in case we encountered an error.
} finally {
close(browser)
}

await sleep(retryTimeout);
Expand Down