[Bug]: WebKit on Linux sometimes closes the page without the beforeunload dialog on page.close({ runBeforeUnload: true })
I maintainer di solito rispondono entro 1 giorno
@yury-s ci sta già lavorando.
Dal 12/10/2026.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 52/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- docker, javascript, node.js, playwright, typescript
- Ambito
- backend, testing-qa
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- TypeScript
- Stelle
- 97.4k
- Fork
- 6.6k
- Merge medio
- 18h 15m
- PR unite (30g)
- 318
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di microsoft/playwright
-
[Feature]: Set `this.name` in `TargetClosedError` constructorForse di nuovo libera @LeonxLJX l’ha presa 43 giorni fa e non c’è nessuna pull request aperta. ApertaP3-collecting-feedback
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
microsoft/playwright#42522 · 7 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: ariaSnapshot() emits \uXXXX / \b escapes in role names that toMatchAriaSnapshot() parses back incorrectlyForse già presa @alok-108 l’ha presa oggi. Aperta
Difficoltà 3/5 Mezza giornata Idoneità per principianti 22/100
microsoft/playwright#43489 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: Chromium – locale is not applied to Accept-Language / navigator.languages inside dedicated WorkersForse già presa @yury-s l’ha presa oggi. Aperta
Difficoltà 3/5 Mezza giornata Idoneità per principianti 25/100
microsoft/playwright#43484 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: fill() on a paragraph inside a contenteditable body in an iframe resolves but inserts nothingForse già presa @yury-s l’ha presa oggi. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 18/100
microsoft/playwright#43483 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: Python sync API logs CancelledError when exiting sync_playwright() with an unanswered routeForse già presa @yury-s l’ha presa oggi. Aperta
Difficoltà 2/5 Meno di un'ora Idoneità per principianti 18/100
microsoft/playwright#43463 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di microsoft/playwright
Issue simili
-
bug engine
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
frostney/GocciaScript#1746 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
agilepathway/label-checker#739 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
CopilotKit/OpenBot#800 ·
I maintainer di solito rispondono entro 1 giorno
-
Endpoint links in the tag operations list are below the 24px target sizeForse già presa @AdzerKI l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
ehmpathy/rhachet-roles-bhuild#471 ·
I maintainer di solito rispondono entro 1 giorno