[Bug]: WebKit on Linux sometimes closes the page without the beforeunload dialog on page.close({ runBeforeUnload: true })
Los mantenedores suelen responder en 1 día
@yury-s ya está trabajando en esto.
Desde el 12/10/2026.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 52/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- docker, javascript, node.js, playwright, typescript
- Área
- backend, testing-qa
Línea de trabajo
Start by running the supplied run.mjs reproduction in the Playwright 1.63.0 Linux image with two CPUs, then compare its WebKit protocol log with the Chromium and Firefox runs. The issue points to page.close({ runBeforeUnload: true }) and the Playwright.closePage protocol path; no source files or failing test are named. Done means WebKit consistently opens the prevented beforeunload dialog and keeps the page open until it is dismissed.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Version
1.63.0
Steps to reproduce
- Save
run.mjs(below) in an empty folder. - In that folder, run it in the official image, with two CPUs:
docker run --rm --ipc=host --cpus=2 --memory=7g -v "$PWD:/r" -w /r \
mcr.microsoft.com/playwright@sha256:eff16c30e6f3f4af0a03fa4b706120d5e9b0891c344a27d64559aff5900a4a27 \
bash -c 'npm install --silent --no-audit --no-fund [email protected] && node run.mjs'
The digest is mcr.microsoft.com/playwright:v1.63.0-noble. BROWSER=chromium or BROWSER=firefox (with -e) runs the same
in the other engines; -e DEBUG=pw:protocol and node run.mjs 2> protocol.log write the protocol log.
run.mjs serves a page that prevents beforeunload once its only field changed. Each repetition opens it in a new
context, fills the field, and calls page.close({ runBeforeUnload: true }), waiting for the dialog event. The page
writes to localStorage what its beforeunload saw, and a second page of the same context reads it back, so a
repetition without a dialog still says whether the event ran and was prevented. Two workers, two arms interleaved
(reaching the form by pushState, or directly).
run.mjs
// Repro: on page.close({ runBeforeUnload: true }), WebKit on Linux sometimes closes the page without the beforeunload
// dialog the page asked for. A synthetic page served by Node's http; no other code.
//
// Each repetition opens the page in a new context, fills its only field -- which makes the page prevent beforeunload --
// and closes the page with runBeforeUnload, waiting for the `dialog` event. Two arms, interleaved:
// spa -- open /, follow a link that pushStates to /form, fill the field.
// direct -- open /form, click the field, fill it.
// The page writes to localStorage what its beforeunload saw: read afterwards from another page of the same context, it
// shows, for a repetition without a dialog, whether the event ran and was prevented.
//
// BROWSER=webkit|chromium|firefox (default webkit) REPEATS (default 300) WORKERS (default 2)
import http from 'node:http'
import { chromium, devices, firefox, webkit } from 'playwright'
const BROWSER = process.env.BROWSER ?? 'webkit'
const REPEATS = Number(process.env.REPEATS ?? 300)
const WORKERS = Number(process.env.WORKERS ?? 2)
const types = { webkit, chromium, firefox }
const device = { webkit: devices['Desktop Safari'], chromium: devices['Desktop Chrome'], firefox: devices['Desktop Firefox'] }[BROWSER]
const html = `<!doctype html><meta charset="utf-8"><title>repro</title>
<a id="go" href="/form">Form</a><div id="app"></div>
<script>
let dirty = false
window.addEventListener('beforeunload', (event) => {
if (dirty) { event.preventDefault(); event.returnValue = '' }
localStorage.setItem('unload', JSON.stringify({ dirty, prevented: event.defaultPrevented, active: navigator.userActivation?.hasBeenActive ?? null }))
})
function show() {
if (location.pathname !== '/form') return
document.getElementById('app').innerHTML = '<label>Name <input id="name"></label>'
document.getElementById('name').addEventListener('input', () => { dirty = true })
}
document.getElementById('go').addEventListener('click', (event) => { event.preventDefault(); history.pushState({}, '', '/form'); show() })
show()
</script>`
const server = http.createServer((_request, response) => {
response.writeHead(200, { 'content-type': 'text/html; charset=utf-8' })
response.end(html)
})
await new Promise((resolve) => server.listen(4400, '127.0.0.1', resolve))
const base = 'http://127.0.0.1:4400'
const browser = await types[BROWSER].launch()
console.log(`${BROWSER} ${browser.version()}`)
const results = []
async function once(index) {
const arm = index % 2 === 0 ? 'spa' : 'direct'
const context = await browser.newContext({ ...device })
const page = await context.newPage()
if (arm === 'spa') {
await page.goto(`${base}/`)
await page.click('#go')
} else {
await page.goto(`${base}/form`)
await page.click('#name')
}
await page.fill('#name', 'Morning')
let dialog = null
const asked = page.waitForEvent('dialog').then(
async (question) => {
dialog = question.type()
await question.dismiss()
},
() => undefined,
)
console.error(`MARK ${new Date().toISOString()} repetition ${index} (${arm}) closes`)
await page.close({ runBeforeUnload: true })
await asked
const closed = page.isClosed()
// What the page's beforeunload saw, from another page of the same context.
const reader = await context.newPage()
await reader.goto(`${base}/`)
const unload = JSON.parse((await reader.evaluate(() => localStorage.getItem('unload'))) ?? 'null')
await context.close()
const line = { index, arm, dialog, closed, unload }
results.push(line)
console.log(JSON.stringify(line))
}
let next = 0
await Promise.all(
Array.from({ length: WORKERS }, async () => {
while (next < REPEATS) {
const index = next++
await once(index).catch((error) => console.log(JSON.stringify({ index, error: String(error) })))
}
}),
)
await browser.close()
server.close()
for (const arm of ['spa', 'direct']) {
const mine = results.filter((line) => line.arm === arm)
const missing = mine.filter((line) => line.dialog !== 'beforeunload')
const prevented = missing.filter((line) => line.unload?.prevented === true)
console.log(`SUMMARY ${BROWSER} ${arm}: ${mine.length} runs, ${missing.length} without a dialog, ${prevented.length} of them with beforeunload run and prevented`)
}
Expected behavior
A beforeunload dialog on every repetition, as in Chromium and Firefox.
Actual behavior
On some repetitions in WebKit no dialog comes, and the page closes, although its beforeunload ran and was prevented:
| Browser | Repetitions without a dialog | Of them, with beforeunload run and prevented |
|---|---|---|
| WebKit 26.6 | 12 of 300 (4 of 150 by pushState, 8 of 150 direct) |
12, all with navigator.userActivation.hasBeenActive true |
| Chromium 153.0.8010.12 | 0 of 300 | — |
| Firefox 155.0 | 0 of 300 | — |
The page recorded the prevented event in all 888 repetitions that did show the dialog, so the channel works.
Earlier runs of the same repro in WebKit gave 5 of 300 and 1 of 300. In our application's own test the same case
failed 11 of 150. On a Windows host, outside Docker, WebKit asked 150 of 150.
With DEBUG=pw:protocol, the failure gets no Dialog.javascriptDialogOpening at all after Playwright.closePage, and
the target is destroyed 61 ms later. On the repetition beside it, the dialog comes 36 ms after closePage. So it is not
the client losing the event: the browser closes without asking.
Protocol excerpt
Run 2, 2026-10-11, PROTOCOL=1: 1 of 300 without a dialog (repetition 144, arm spa). Excerpt of DEBUG=pw:protocol.
Repetition 144 (pageProxyId 2237) -- no dialog:
2026-10-11T17:00:31.828Z pw:protocol SEND ► {"method":"Target.sendMessageToTarget", ... "Page.insertText","params":{"text":"Morning"}} (pageProxyId 2237)
2026-10-11T17:00:31.830Z pw:protocol ◀ RECV {"result":{},"id":17618,...,"pageProxyId":"2237"}
2026-10-11T17:00:31.838Z pw:protocol SEND ► {"id":17627,"method":"Playwright.closePage","params":{"pageProxyId":"2237","runBeforeUnload":true}}
2026-10-11T17:00:31.899Z pw:protocol ◀ RECV {"method":"Target.targetDestroyed","params":{"targetId":"page-2238","crashed":false},"browserContextId":"8000000000000092","pageProxyId":"2237"}
2026-10-11T17:00:31.900Z pw:protocol ◀ RECV {"method":"Playwright.pageProxyDestroyed","params":{"pageProxyId":"2237"}}
(no Dialog.* message for pageProxyId 2237 anywhere in the log)
Repetition 145 (pageProxyId 2249) -- the dialog comes, 36 ms after closePage:
2026-10-11T17:00:31.927Z pw:protocol SEND ► {"id":17655,"method":"Playwright.closePage","params":{"pageProxyId":"2249","runBeforeUnload":true}}
2026-10-11T17:00:31.963Z pw:protocol ◀ RECV {"method":"Dialog.javascriptDialogOpening","params":{"type":"beforeunload","message":""},"browserContextId":"8000000000000093","pageProxyId":"2249"}
2026-10-11T17:00:31.966Z pw:protocol SEND ► {"id":17658,"method":"Dialog.handleJavaScriptDialog","params":{"accept":false},"pageProxyId":"2249"}
2026-10-11T17:00:31.967Z pw:protocol ◀ RECV {"method":"Dialog.javascriptDialogClosed","browserContextId":"8000000000000093","pageProxyId":"2249"}
Additional context
Seen only with WebKit on Linux, two CPUs.
Environment
Host: Windows 11 Pro 10.0.26300, Docker Desktop; the container limited to --cpus=2 --memory=7g
Image: mcr.microsoft.com/playwright:v1.63.0-noble (digest above), Node from the image
Playwright: 1.63.0, with its bundled WebKit 26.6, Chromium 153.0.8010.12 and Firefox 155.0
- Lenguaje dominante
- TypeScript
- Estrellas
- 97.4k
- Forks
- 6.6k
- Merge medio
- 19 h 36 min
- PR fusionados (30 d)
- 294
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
-
[Feature]: Set `this.name` in `TargetClosedError` constructorQuizá libre de nuevo @LeonxLJX la tomó hace 41 días y no hay ningún pull request abierto. AbiertoP3-collecting-feedback
Dificultad 1/5 Menos de una hora Aptitud para principiantes 86/100
microsoft/playwright#42522 · 7 comentarios ·
Los mantenedores suelen responder en 1 día
-
[Bug]: WebKit (WPE) web process aborts at exit in PlatformDisplay::sharedDisplay() since 1.64 (webkit-2370)Posiblemente ocupada @yury-s la tomó hoy. Abiertobrowser-webkit v1.65
microsoft/playwright#43394 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Chromium 149 headless shell crashes in service-worker DevTools resource loading during context teardownPosiblemente ocupada @yury-s la tomó hoy. Abiertobrowser-chromium upstream v1.65
microsoft/playwright#43374 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
[Feature]: Allow `retryStrategy: 'isolated'` in test.describe.configure() for tests requiring zero background workersPosiblemente ocupada @alok-108 la tomó hoy. Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 22/100
microsoft/playwright#43351 · 6 comentarios ·
Los mantenedores suelen responder en 1 día
-
[Bug]: Tests whose titles differ only in punctuation share one output directory, and the later test deletes the earlier test's artifactsPosiblemente ocupada @alok-108 la tomó hoy. AbiertoP3-collecting-feedback
Dificultad 4/5 3-5 días Aptitud para principiantes 28/100
microsoft/playwright#43347 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de microsoft/playwright
Issues similares
-
fix(frontend): correct VITE_IS_DEVELPOMENT typo in shared/app.ts and align dev environment flagsAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
vicharanashala/ajrasakha#1439 ·
Los mantenedores suelen responder en 1 día
-
Add: TV5Monde AsieAbiertoapproved check:passed streams:add
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
backnotprop/plannotator#1932 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 Medio día Aptitud para principiantes 62/100
ibm-granite/granite.build#504 ·
Los mantenedores suelen responder en 2 días
-
reproduced
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
anomalyco/opencode#55676 · 1 comentario ·
Los mantenedores suelen responder en 1 día