[Bug]: Firefox: actions hang on "waiting for navigation to finish" after a stale-while-revalidate background revalidation
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- javascript, playwright, typescript
- Área
- backend-api-design, testing
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- TypeScript
- Estrellas
- 99.1k
- Forks
- 6.8k
- Merge medio
- 16 h 56 min
- PR fusionados (30 d)
- 299
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de microsoft/playwright
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
microsoft/playwright#43998 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
microsoft/playwright#43990 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
microsoft/playwright#43999 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 69/100
microsoft/playwright#43996 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 72/100
microsoft/playwright#43994 ·
Los mantenedores suelen responder en 1 día
Todos los issues de microsoft/playwright
Issues similares
-
code-quality good-first-issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
OpenRailAssociation/netzgrafik-editor-frontend#1481 ·
Los mantenedores suelen responder en 1 día
-
bug implicit-state
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
-
area:models enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
bug frontend ui
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Recording drops clicks on links, filters and checkboxes that share a form with a search fieldPosiblemente ocupada @columbia11 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Tencent/BrowserSkill#657 ·
Los mantenedores suelen responder en 1 día