microsoft/playwright · error · NavigationAbortedError

Navigation to "${url}" is interrupted by another navigation

Error message

Navigation to "${url}" is interrupted by another navigation to "${event.url}"

What it means

During goto, Playwright waits for the navigated document to commit. If a different document commits first (a second navigation supersedes the one goto started), it throws NavigationAbortedError explaining that the navigation to url was interrupted by a navigation to a different url.

Source

Thrown at packages/playwright-core/src/server/frames.ts:734

      this.off(Frame.Events.InternalNavigation, collectNavigations);
    }

    let event: NavigationEvent;
    if (navigateResult.newDocumentId) {
      const predicate = (event: NavigationEvent) => {
        // We are interested either in this specific document, or any other document that
        // did commit and replaced the expected document.
        return event.newDocument && (event.newDocument.documentId === navigateResult.newDocumentId || !event.error);
      };
      const events = navigationEvents.filter(predicate);
      if (events.length)
        event = events[0];
      else
        event = await helper.waitForEvent(progress, this, Frame.Events.InternalNavigation, predicate).promise;
      if (event.newDocument!.documentId !== navigateResult.newDocumentId) {
        // This is just a sanity check. In practice, new navigation should
        // cancel the previous one and report "request cancelled"-like error.
        throw new NavigationAbortedError(navigateResult.newDocumentId, `Navigation to "${url}" is interrupted by another navigation to "${event.url}"`);
      }
      if (event.error)
        throw event.error;
    } else {
      // Wait for same document navigation.
      const predicate = (e: NavigationEvent) => !e.newDocument;
      const events = navigationEvents.filter(predicate);
      if (events.length)
        event = events[0];
      else
        event = await helper.waitForEvent(progress, this, Frame.Events.InternalNavigation, predicate).promise;
    }

    if (!this._firedLifecycleEvents.has(waitUntil))
      await helper.waitForEvent(progress, this, Frame.Events.AddLifecycle, (e: types.LifecycleEvent) => e === waitUntil).promise;

    const request = event.newDocument ? event.newDocument.request : undefined;
    const response = request ? await request._finalRequest().response(progress) : null;

View on GitHub (pinned to c8fc3bf8d3)

Solutions

  1. await the final destination: use page.waitForURL(finalUrl) chained with the action that triggers the redirect instead of a single goto.
  2. Remove or stabilize the competing navigation source (disable the meta-refresh, gate the redirect).
  3. Use waitForLoadState('load') or 'networkidle' to settle before asserting.
  4. Retry the goto once the page is stable.

Example fix

// before
await page.goto('https://app.test/old'); // redirected mid-load -> throws
// after
await page.goto('https://app.test/old');
await page.waitForURL('https://app.test/new');
Defensive patterns

Strategy: retry

Validate before calling

// Settle before navigating
await page.waitForLoadState('networkidle');
await page.goto(url);

Type guard

function isNavigationInterrupted(e: unknown) {
  return e instanceof Error && /interrupted by another navigation/i.test(e.message);
}

Try / catch

try {
  await page.goto(url);
} catch (e) {
  if (isNavigationInterrupted(e)) { await page.waitForLoadState('load'); return; }
  throw e;
}

Prevention

When it happens

Trigger: page.goto(url) where, before the expected document commits, the page triggers another navigation: client-side redirects, meta-refresh, JS location changes, history APIs, or a concurrent click causing navigation.

Common situations: SPAs that redirect after load; login flows that bounce through auth then home; a click handler firing during goto; pre-existing timers/redirects racing the navigation; flaky tests under slow network.

Related errors


AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12). Data as JSON: /api/errors/afe777cecf3a161e. Report an issue: GitHub.