[Bug]: Firefox: actions hang on "waiting for navigation to finish" after a stale-while-revalidate background revalidation
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript, playwright, typescript
- Lĩnh vực
- backend-api-design, testing
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- TypeScript
- Star
- 99.1k
- Fork
- 6.8k
- Merge trung bình
- 16 giờ 56 phút
- Pull request đã merge (30 ngày)
- 299
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/playwright
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
microsoft/playwright#43998 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
microsoft/playwright#43990 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
microsoft/playwright#43999 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 69/100
microsoft/playwright#43996 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
microsoft/playwright#43994 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của microsoft/playwright
Issue tương tự
-
code-quality good-first-issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
OpenRailAssociation/netzgrafik-editor-frontend#1481 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug implicit-state
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
-
area:models enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug frontend ui
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Recording drops clicks on links, filters and checkboxes that share a form with a search fieldCó thể đã có người làm @columbia11 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Tencent/BrowserSkill#657 ·
Maintainer thường phản hồi trong vòng 1 ngày