From 65b607245a9ca7b670b2b45ac8731b01bf4d5f4f Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 25 Apr 2026 09:22:13 +0100 Subject: [PATCH] fix(browser): ignore handled route navigation races Co-authored-by: Richard Steadman <198648604+Steady-ai@users.noreply.github.com> --- CHANGELOG.md | 1 + ...ssion.create-page.navigation-guard.test.ts | 28 +++++++++++++++++++ extensions/browser/src/browser/pw-session.ts | 16 +++++++++-- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2303b25514b..9c7ceb4773d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Docs: https://docs.openclaw.ai ### Fixes +- Browser/Playwright: ignore benign already-handled route races during guarded navigation so browser-page tasks no longer fail when Playwright tears down a route mid-flight. (#68708) Thanks @Steady-ai. - Browser/Linux: detect Chromium-based installs under `/opt/google`, `/opt/brave.com`, `/usr/lib/chromium`, and `/usr/lib/chromium-browser` before asking users to set `browser.executablePath`. (#48563) Thanks @lupuletic. - MCP/CLI: retire bundled MCP runtimes at the end of one-shot `openclaw agent` and `openclaw infer model run` gateway/local executions, so repeated scripted runs do not accumulate stdio MCP child processes. Fixes #71457. - OpenAI/Codex image generation: canonicalize legacy `openai-codex.baseUrl` values such as `https://chatgpt.com/backend-api` to the Codex Responses backend before calling `gpt-image-2`, matching the chat transport. Fixes #71460. diff --git a/extensions/browser/src/browser/pw-session.create-page.navigation-guard.test.ts b/extensions/browser/src/browser/pw-session.create-page.navigation-guard.test.ts index 0447bd2b962..adaffb6efd1 100644 --- a/extensions/browser/src/browser/pw-session.create-page.navigation-guard.test.ts +++ b/extensions/browser/src/browser/pw-session.create-page.navigation-guard.test.ts @@ -345,6 +345,34 @@ describe("pw-session createPageViaPlaywright navigation guard", () => { expect(pageClose).not.toHaveBeenCalled(); }); + it("ignores already-handled route races during guarded navigation", async () => { + const { pageGoto, pageClose, getRouteHandler, mainFrame } = installBrowserMocks(); + const route = createMockRoute({ + continue: vi.fn(async () => { + throw new Error("Route is already handled"); + }), + }); + pageGoto.mockImplementationOnce(async () => { + await dispatchMockNavigation({ + getRouteHandler, + mainFrame, + url: "https://example.com", + route, + }); + return null; + }); + + const created = await createPageViaPlaywright({ + cdpUrl: "http://127.0.0.1:18792", + url: "https://example.com", + }); + + expect(created.targetId).toBe("TARGET_1"); + expect(route.continue).toHaveBeenCalledTimes(1); + expect(pageGoto).toHaveBeenCalledTimes(1); + expect(pageClose).not.toHaveBeenCalled(); + }); + it("propagates unsupported redirect protocols as navigation errors", async () => { const { pageGoto, pageClose, getRouteHandler, mainFrame } = installBrowserMocks(); mockBlockedRedirectNavigation({ diff --git a/extensions/browser/src/browser/pw-session.ts b/extensions/browser/src/browser/pw-session.ts index 18e8b442ce6..a9fcd8fafc3 100644 --- a/extensions/browser/src/browser/pw-session.ts +++ b/extensions/browser/src/browser/pw-session.ts @@ -818,6 +818,18 @@ export async function assertPageNavigationCompletedSafely( } } +async function continueRouteSafely(route: Route): Promise { + try { + await route.continue(); + } catch (err) { + const message = err instanceof Error ? err.message : ""; + if (message.includes("Route is already handled")) { + return; + } + throw err; + } +} + export async function gotoPageWithNavigationGuard( opts: { cdpUrl: string; @@ -841,7 +853,7 @@ export async function gotoPageWithNavigationGuard( const isSubframeDocument = !isTopLevel && isSubframeDocumentNavigationRequest(opts.page, request); if (!isTopLevel && !isSubframeDocument) { - await route.continue(); + await continueRouteSafely(route); return; } try { @@ -859,7 +871,7 @@ export async function gotoPageWithNavigationGuard( } throw err; } - await route.continue(); + await continueRouteSafely(route); }; await opts.page.route("**", handler);