[Bug]: WebKit on Linux sometimes closes the page without the beforeunload dialog on page.close({ runBeforeUnload: true })
Maintainers usually reply within 1 day
@yury-s is already working on this.
Since Oct 12, 2026.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 52/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- docker, javascript, node.js, playwright, typescript
- Domain
- backend, testing-qa
Research direction
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.
Written by the indexing model from the issue text.
Description
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
- Dominant language
- TypeScript
- Stars
- 97.4k
- Forks
- 6.6k
- Avg merge
- 22h 17m
- Merged PRs (30d)
- 278
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/playwright
-
[Bug]: Windows: Chrome for Testing crashes in its stack sampling profiler during fullPage screenshotsPossibly taken @yury-s claimed this today. Openneeds-triage-win
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
microsoft/playwright#43327 · 1 comment ·
Maintainers usually reply within 1 day
-
[Feature]: Set `this.name` in `TargetClosedError` constructorMay be free again @LeonxLJX claimed this 39 days ago, and no pull request is open. OpenP3-collecting-feedback
Difficulty 1/5 Under an hour Newbie friendliness 86/100
microsoft/playwright#42522 · 7 comments ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 28/100
microsoft/playwright#43347 · 1 comment ·
Maintainers usually reply within 1 day
-
[Bug] Chromium: launch({ proxy: { username, password } }) credentials are sent to a website's 401 Basic challengePossibly taken @yury-s claimed this today. Open
Difficulty 4/5 3-5 days Newbie friendliness 45/100
microsoft/playwright#43326 ·
Maintainers usually reply within 1 day
-
[Bug]: Firefox drops the context's colorScheme and deviceScaleFactor on pages that send Cross-Origin-Opener-PolicyPossibly taken @dgozman claimed this 1 day ago. Openbrowser-firefox v1.65
microsoft/playwright#43287 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
All issues in microsoft/playwright
Similar issues
-
priority:high
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
immich-app/immich#32426 ·
Maintainers usually reply within 1 day
-
documentation good first issue hacktoberfest help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
libredb/libredb-studio#1756 ·
Maintainers usually reply within 1 day
-
state:triage-needed
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day