[Bug]: Firefox: actions hang on "waiting for navigation to finish" after a stale-while-revalidate background revalidation
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript, playwright, typescript
調査の方向性
Start with the supplied repro.mjs and run its swr and control modes to confirm the Firefox-specific hang; compare the navigation requests and the 304 revalidation described in the issue. Then trace how Playwright handles Firefox navigation requests and identify why the background revalidation is treated as an unfinished page navigation. Done when the assertion completes in the SWR case and the control modes still pass.
索引モデルが issue の本文から書いたものです。
説明
Version
1.65.0
Steps to reproduce
Repository: https://github.com/stefanprobst/pw-firefox-swr-repro
git clone https://github.com/stefanprobst/pw-firefox-swr-repro && cd pw-firefox-swr-repro
npm install
npx playwright install firefox
node repro.mjs swr 20 # Cache-Control: s-maxage=900, stale-while-revalidate=31535100
node repro.mjs control 20 # Cache-Control: max-age=0, must-revalidate
node repro.mjs swr-pref-off 20 # stale-while-revalidate, with network.http.stale_while_revalidate.enabled = false
repro.mjs:
// Firefox: after page.goto(), actions hang on "waiting for navigation to finish" when the document was cached by
// another page in the same context and is served with stale-while-revalidate.
// Usage: node repro.mjs [swr|control|swr-pref-off] [trials]
import http from "node:http";
import { expect, firefox } from "@playwright/test";
const mode = process.argv[2] ?? "swr";
const trials = Number(process.argv[3] ?? 10);
const cacheControl = mode === "control" ? "max-age=0, must-revalidate" : "s-maxage=900, stale-while-revalidate=31535100";
const server = http.createServer((req, res) => {
const headers = { "content-type": "text/html; charset=utf-8", "cache-control": cacheControl, etag: '"v1"' };
if (req.headers["if-none-match"] === '"v1"') {
res.writeHead(304, headers);
res.end();
return;
}
res.writeHead(200, headers);
res.end("<!doctype html><title>t</title><h1>Hello</h1>");
});
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
const url = `http://127.0.0.1:${server.address().port}/`;
const browser = await firefox.launch({
firefoxUserPrefs: mode === "swr-pref-off" ? { "network.http.stale_while_revalidate.enabled": false } : {},
});
let hangs = 0;
for (let i = 0; i < trials; i++) {
const context = await browser.newContext();
const other = await context.newPage();
await other.goto(url); // caches the document
const page = await context.newPage();
await page.goto(url);
await page.waitForTimeout(1_000);
try {
await expect(page.locator("h1")).toHaveText("Hello", { timeout: 5_000 });
} catch (error) {
hangs++;
if (hangs === 1) console.log(String(error).split("\n").slice(0, 10).join("\n") + "\n");
}
await context.close();
}
console.log(`${mode}: ${hangs} of ${trials} hung (Playwright ${(await import("playwright/package.json", { with: { type: "json" } })).default.version}, Firefox ${browser.version()})`);
await browser.close();
server.close();
Expected behavior
The assertion passes, as it does in the control modes, and in Chromium and WebKit.
Actual behavior
The assertion on the second page hangs, although the page has loaded:
Error: expect(locator).toHaveText(expected) failed
Locator: locator('h1')
Expected: "Hello"
Received: ""
Timeout: 5000ms
Call log:
- Expect "toHaveText" locator('h1') with timeout 5000ms
- waiting for locator('h1')
- waiting for "http://127.0.0.1:42039/" navigation to finish...
| Mode | Hung |
|---|---|
swr |
19 of 20 |
control |
0 of 20 |
swr-pref-off |
0 of 20 |
Additional context
Because the other page has cached the document, Firefox serves it from the cache and revalidates it in the background.
Playwright seems to report that revalidation as a navigation of the page, which never finishes:
- A single
page.goto()reports two requests withrequest.isNavigationRequest() === true: the cached200, and a
conditional request withcache-control: max-age=0that gets a304. Only one document is loaded. - Without the wait, the assertion usually runs before the revalidation is reported, and passes. In a test suite, any
later action hangs instead, e.g. an assertion after a click. locator.textContent()in place ofexpect(locator).toHaveText()did not hang (0 of 10).- Found in a Next.js app, which sends this
Cache-Controlheader for prerendered pages that revalidate: a Firefox test
that opens such a page in two tabs, and toggles a setting that syncs between them, failed in 29 of 30 runs, and in 0
of 30 with the pref disabled.
Possibly related: #42183 (same symptom, closed without a repro) and #42731 (same symptom, triggered by COOP).
Workaround:
launchOptions: {
firefoxUserPrefs: { "network.http.stale_while_revalidate.enabled": false },
},
Environment
OS: Linux 7.0.0-38-generic
Node.js: 26.13.0
@playwright/test: 1.65.0
Firefox: 159.0
- 主要言語
- TypeScript
- スター
- 99.1k
- フォーク
- 6.8k
- 平均マージ
- 16時間 56分
- マージ済み PR(30日)
- 299
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/playwright のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
microsoft/playwright#43998 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
microsoft/playwright#43990 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
microsoft/playwright#43999 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 69/100
microsoft/playwright#43996 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
microsoft/playwright#43994 ·
メンテナーはふだん 1 日以内に返信
microsoft/playwright の issue をすべて見る
似ている issue
-
code-quality good-first-issue
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
OpenRailAssociation/netzgrafik-editor-frontend#1481 ·
メンテナーはふだん 1 日以内に返信
-
bug implicit-state
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
-
area:models enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
bug frontend ui
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
Recording drops clicks on links, filters and checkboxes that share a form with a search field対応中かも @columbia11 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
Tencent/BrowserSkill#657 ·
メンテナーはふだん 1 日以内に返信