Skip to content

Commit

Permalink
Merge pull request #64 from marvinhagemeister/race-navigation
Browse files Browse the repository at this point in the history
fix: ensure navigation listeners are setup before trigger
  • Loading branch information
lino-levan committed May 23, 2024
2 parents 4985628 + ea41411 commit 299bace
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/pages/guides/navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ await page.waitForNetworkIdle({ idleConnections: 0, idleTime: 1000 });
// Click the 'pyro' link
const xLink = await page.$("a.justify-between:nth-child(1)");
await Promise.all([
xLink!.click(),
page.waitForNavigation(),
xLink!.click(),
]);

// Click the link to 'pyro.deno.dev'
const dLink = await page.$(
".markdown-body > p:nth-child(8) > a:nth-child(1)",
);
await Promise.all([
dLink!.click(),
page.waitForNavigation(),
dLink!.click(),
]);

// Close browser
Expand Down
4 changes: 2 additions & 2 deletions examples/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ await page.waitForNetworkIdle({ idleConnections: 0, idleTime: 1000 });
// Click the 'pyro' link
const xLink = await page.$("a.justify-between:nth-child(1)");
await Promise.all([
xLink!.click(),
page.waitForNavigation(),
xLink!.click(),
]);

// Click the link to 'pyro.deno.dev'
const dLink = await page.$(
".markdown-body > p:nth-child(8) > a:nth-child(1)",
);
await Promise.all([
dLink!.click(),
page.waitForNavigation(),
dLink!.click(),
]);

// Close browser
Expand Down
4 changes: 2 additions & 2 deletions src/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,11 @@ export class Page extends EventTarget {
async goto(url: string, options?: GoToOptions) {
options = options ?? {};
await Promise.all([
this.waitForNavigation(options),
retryDeadline(
this.#celestial.Page.navigate({ url, ...options }),
this.timeout,
),
this.waitForNavigation(options),
]);
}

Expand Down Expand Up @@ -524,8 +524,8 @@ export class Page extends EventTarget {
*/
async reload(options?: WaitForOptions) {
await Promise.all([
retryDeadline(this.#celestial.Page.reload({}), this.timeout),
this.waitForNavigation(options),
retryDeadline(this.#celestial.Page.reload({}), this.timeout),
]);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/wait_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ Deno.test("Wait for selector", async () => {
const browser = await launch();

// Open the webpage
const page = await browser.newPage("http://deno.land");
const page = await browser.newPage("https://example.com");

// Wait for selector
const selected = await page.waitForSelector(".font-bold");
const selected = await page.waitForSelector("h1");
console.log(selected);

// Close browser
Expand All @@ -23,7 +23,7 @@ Deno.test("Fail wait for selector", async () => {
const browser = await launch();

// Open the webpage
const page = await browser.newPage("http://deno.land");
const page = await browser.newPage("https://example.com");

await assertRejects(
() => {
Expand Down

0 comments on commit 299bace

Please sign in to comment.