[Bug]: page.goto never returns for a load started as a newer service worker takes over (Chromium)

未关闭
#44,287 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
12/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
领域
testing-qa

调研方向

The hang sits in the Chromium driver's handling of Page.navigate when a service worker takes over mid-load, so start from the navigation code in the Chromium backend of the playwright repository and the protocol log in the reproduction repo (protocol-log-hung-run.txt). Run repro.mjs repeatedly to reproduce it, then compare against the direct DevTools protocol scenario. Done would mean page.goto resolves in the takeover case without changing the reproduction's expected timings.

由索引模型根据 Issue 内容生成。

描述

Version

1.65.1 (latest release); also 1.66.0-alpha-2026-11-20 (next)

Steps to reproduce
  1. Clone https://github.com/MorrisonWill/playwright-sw-takeover-goto-hang
  2. npm install
  3. npx playwright install chromium
  4. for i in 1 2 3 4 5 6 7 8 9 10; do node repro.mjs; done
  5. Each run prints loaded /after in N ms (exit 0) or the load did not finish: TimeoutError: page.goto: Timeout 15000ms exceeded. (exit 1). About half or more of the runs hang.

repro.mjs is one file with no dependency besides playwright-core. It serves a tiny site whose service worker answers page loads from navigation preload, else fetch, else an offline page. Tab one starts a load the server holds, so worker 1 stays busy. The server then serves worker 2, which installs and waits (it called skipWaiting). When the held load is answered, worker 2 takes over and worker 1 is stopped. A page.goto started in tab two at that moment is the one that hangs.

Expected behavior

page.goto(origin + "/after") resolves once the page loads (worker 2 answers it, or the browser falls back to the network), as it does every time when the same steps are driven over the DevTools protocol without Playwright.

Actual behavior

page.goto never returns. Playwright's Page.navigate gets no answer until the browser is closed (then net::ERR_ABORTED), the frame never commits, and the Page object stops working: page.evaluate fails with "Target page, context or browser has been closed", although no close event is emitted and the page is no longer in context.pages().

The navigation preload response for that load arrives (200, loading finished) while it hangs. Chromium reports the old worker's target as crashed (Inspector.targetCrashed), which it does on every takeover when a client is attached, hang or not.

How often, same scenario:

Driver The load hangs
repro.mjs, Playwright 1.65.1, Ubuntu 24.04, Node 24 5 of 10
repro.mjs, Playwright 1.65.1, a second machine (Arch-based Linux 7.2, Node 26) 7 of 10
Playwright 1.65.1, page.goto, in a fuller probe 6 to 7 of 10, and 16 of 20
Playwright 1.66.0-alpha-2026-11-20, page.goto 5 of 10
Playwright 1.65.1 with PLAYWRIGHT_DISABLE_SERVICE_WORKER_NETWORK=1 3 of 10
The DevTools protocol directly (own WebSocket, Target.createTarget, Page.navigate, Page.loadEventFired) 0 of 12
Directly, auto-attached to all targets (Target.setAutoAttach, flatten) 0 of 15
Directly, auto-attached with waitForDebuggerOnStart: true, each target resumed with Runtime.runIfWaitingForDebugger 0 of 15
As above, and page-level service worker sessions detached at once 0 of 15
As above, and Network.enable on pages and workers 0 of 15

Under Playwright, the same load started other ways does not hang (20 runs each, in ways-to-load.txt): page.evaluate(() => location.href = url) then page.waitForURL(url, { waitUntil: "load" }): 0 of 20; a context.newCDPSession(page) doing Page.navigate and waiting for Page.loadEventFired: 0 of 20. A locator.click() on a link that navigates across the same takeover hung once in 65 rounds ("waiting for scheduled navigations to finish").

From DEBUG=pw:protocol of a run that hangs (the whole log is protocol-log-hung-run.txt in the repository; session 612083F7... is the second tab, 7041D190... is worker 1):

20:28:00.958Z SEND {"id":79,"method":"Page.navigate","params":{"url":"http://127.0.0.1:40365/after","frameId":"8EF0890A...","referrerPolicy":"unsafeUrl"},"sessionId":"612083F7..."}
20:28:00.959Z RECV Page.frameStartedNavigating {"frameId":"8EF0890A...","url":"http://127.0.0.1:40365/after","navigationType":"differentDocument"}
20:28:00.960Z RECV Network.requestWillBeSent (the navigation, loader 99073655...)
20:28:00.965Z RECV Network.requestWillBeSent {"requestId":"preload-9", ... "/after"} (navigation preload, on worker 1's session)
20:28:00.965Z RECV Network.responseReceived {"requestId":"preload-9", "status":200}
20:28:00.965Z RECV Network.loadingFinished {"requestId":"preload-9"}
20:28:00.967Z RECV {"method":"Inspector.targetCrashed","params":{},"sessionId":"7041D190..."}   (worker 1)
20:28:00.967Z RECV Target.detachedFromTarget {"sessionId":"7041D190...","targetId":"571988D4..."}
   ... service worker targets attached and detached (worker 2) ...
   (nothing for frame 8EF0890A... after this: no frameNavigated, no commit, no load)
20:28:15.968Z SEND Runtime.evaluate ... (the test's own check, which then fails: target closed)
20:29:20.202Z RECV {"id":79,"result":{"frameId":"8EF0890A...","loaderId":"99073655...","errorText":"net::ERR_ABORTED"}}   (only when the browser is closed)
Additional context

Found while making an installed-app (PWA) end-to-end test reliable: it failed in about 3 of 50 CI runs at a page.goto started while a deploy brought in a new worker. The site's own worker is not the cause, since the direct protocol runs above load every time. I did not find an existing issue for this; the nearest are WebKit and Firefox navigation hangs.

I do not intend to work on a fix myself. The investigation and this report were prepared with the help of an AI coding agent; the reproduction was run on two machines and the numbers above are from those runs.

Environment
System:
  OS: Linux 6.8 Ubuntu 24.04 (x64); also Linux 7.2, Arch-based (x64)
Binaries:
  Node: 24.22.2; also 26.12.0
  npm: 11.20.0
npmPackages:
  playwright-core: 1.65.1
Browser:
  Chromium 1255 from Playwright's download (Chrome for Testing 159.0.8154.6), headless
主要语言
TypeScript
星标
100k
派生
6.9k
平均合并
16 小时 8 分钟
30 天内合并 PR
281

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/playwright 的其他 Issue

查看 microsoft/playwright 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。