Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[Bug]: WebKit on Linux sometimes closes the page without the beforeunload dialog on page.close({ runBeforeUnload: true })

オープン
#43,285 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@yury-s がすでに取り組んでいます。

2026年10月12日 から。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
52/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
docker, javascript, node.js, playwright, typescript

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

v1.65
Version

1.63.0

Steps to reproduce
  1. Save run.mjs (below) in an empty folder.
  2. 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
主要言語
TypeScript
スター
97.4k
フォーク
6.6k
平均マージ
18時間 15分
マージ済み PR(30日)
318

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/playwright のほかの issue

microsoft/playwright の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。