profiles: ensure all page.goto() promises have at least catch block or are awaited (#559)

In particular, an API call to /navigate starts, but doesn't wait for a
page load to finish, since user can choose to close the profile browser
at any time. This ensures that user operations don't cause the browser to crash if
page.goto() is interrupted/fails (browser closed, profile is saved, etc...) while a page is still loading.

bump to 1.1.1
This commit is contained in:
Ilya Kreymer 2024-04-25 09:34:57 +02:00 committed by GitHub
parent 15d2b09757
commit a61206fd73
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 4 deletions

View file

@ -1,6 +1,6 @@
{
"name": "browsertrix-crawler",
"version": "1.1.0",
"version": "1.1.1",
"main": "browsertrix-crawler",
"type": "module",
"repository": "https://github.com/webrecorder/browsertrix-crawler",

View file

@ -247,7 +247,11 @@ async function automatedProfile(
logger.info(`Loading page: ${params.url}`);
try {
await page.goto(params.url, { waitUntil });
} catch (e) {
logger.error("Page Load Failed/Interrupted", e);
}
logger.debug("Looking for username and password entry fields on page...");
@ -404,9 +408,15 @@ class InteractiveBrowser {
cdp.send("Page.enable");
cdp.on("Page.windowOpen", async (resp) => {
if (resp.url) {
if (!resp.url) {
return;
}
try {
await cdp.send("Target.activateTarget", { targetId: this.targetId });
await page.goto(resp.url);
} catch (e) {
logger.error("Page Load Failed/Interrupted", e);
}
});
}
@ -568,7 +578,12 @@ class InteractiveBrowser {
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify({ success: true }));
this.page.goto(url);
logger.info("Loading Page", { page: url });
this.page
.goto(url)
.catch((e) => logger.warn("Page Load Failed/Interrupted", e));
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
res.writeHead(400, { "Content-Type": "application/json" });