Skip to content

Commit

Permalink
profiles: ensure initial page.load() is awaited (#561)
Browse files Browse the repository at this point in the history
refactor to create a startLoad() method and await it, follow-up to #559
  • Loading branch information
ikreymer committed May 2, 2024
1 parent a61206f commit 22b2136
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/create-login-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,14 @@ async function main() {
const target = await cdp.send("Target.getTargetInfo");
const targetId = target.targetInfo.targetId;

new InteractiveBrowser(params, browser, page, cdp, targetId, waitUntil);
const ibrowser = new InteractiveBrowser(
params,
browser,
page,
cdp,
targetId,
);
await ibrowser.startLoad(waitUntil);
} else {
await automatedProfile(params, browser, page, cdp, waitUntil);
}
Expand Down Expand Up @@ -384,7 +391,6 @@ class InteractiveBrowser {
page: Page,
cdp: CDPSession,
targetId: string,
waitUntil: PuppeteerLifeCycleEvent = "load",
) {
logger.info("Creating Profile Interactively...");
child_process.spawn("socat", [
Expand Down Expand Up @@ -446,12 +452,17 @@ class InteractiveBrowser {
} else {
logger.info("Screencasting with CDP on port 9222");
}
}

logger.info(`Loading page: ${params.url}`);
async startLoad(waitUntil: PuppeteerLifeCycleEvent = "load") {
logger.info(`Loading page: ${this.params.url}`);

page.goto(params.url, { waitUntil, timeout: 0 }).finally(() => {
try {
await this.page.goto(this.params.url, { waitUntil, timeout: 0 });
logger.info("Loaded!");
});
} catch (e) {
logger.warn("Page Load Failed/Interrupted", e);
}
}

handlePageLoad() {
Expand Down

0 comments on commit 22b2136

Please sign in to comment.