[BUG] WebKit keeps every removed iframe's JS heap alive (memory grows until the page crashes)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 12/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- javascript, nodejs, playwright, typescript
- 领域
- testing-qa
调研方向
The report is a memory leak in Playwright's WebKit build or inspector backend, so it is not a first-timer task. Start from the repro script in the issue body, which removes iframes in a loop and reads WebContent RSS with ps. Done would mean a fix that keeps RSS flat, which needs WebKit-side or protocol-side debugging well beyond a newcomer's scope.
由索引模型根据 Issue 内容生成。
描述
Version
- Playwright 1.65.1, WebKit revision 2388 (Linux WPE build and macOS build)
- Node.js 26.13.1
- OS: Ubuntu 26.04 (GitHub Actions
ubuntu-26.04image, 4 CPU, 16 GB); macOS 27.2 - Found through Vitest 5.1.1 browser mode (
@vitest/browser-playwright5.1.1), which
runs each test file in a new same-origin iframe and removes it after. The repro
below does not use Vitest.
Steps to reproduce
Save as repro.mjs and run node repro.mjs:
import { execSync } from "node:child_process";
import { webkit } from "playwright";
const CHILD =
"<script>window.big = Array.from({ length: 300000 }, (_, i) => ({ i, s: 'x' + i }));</script>";
const rss = () =>
execSync("ps -eo rss=,comm=")
.toString()
.split("\n")
.filter((l) => /WPEWebProcess|WebContent/.test(l))
.map((l) => Math.round(Number(l.trim().split(/\s+/)[0]) / 1024))
.join(" ");
const browser = await webkit.launch();
const page = await browser.newPage();
await page.route("http://leak.test/**", (route) =>
route.fulfill({
contentType: "text/html",
body: route.request().url().endsWith("/child") ? CHILD : "<body></body>",
}),
);
await page.goto("http://leak.test/");
for (let i = 0; i <= 200; i++) {
await page.evaluate(async () => {
const frame = document.createElement("iframe");
frame.src = "/child";
const loaded = new Promise((r) => (frame.onload = r));
document.body.append(frame);
await loaded;
await new Promise((r) => setTimeout(r, 50));
frame.remove();
});
if (i % 25 === 0) console.log(i, "iframes, WebContent RSS MB:", rss());
}
await browser.close();
Expected behavior
The memory of a removed iframe is reclaimed. RSS stays flat.
Actual behavior
RSS grows by about 36 MB per removed iframe (the size of the child's window.big)
and is never reclaimed. It grows linearly and does not level off:
| Removed iframes | Linux WPE (CI) | macOS Playwright WebKit | Chromium (same script) |
|---|---|---|---|
| 0 | 273 MB | 149 MB | 107 MB |
| 100 | 3,883 MB | 3,756 MB | - |
| 200 | 7,460 MB | 7,333 MB | 264 MB |
On Linux, the content process crashes at about 8.5 GB ("page crashed").
Findings:
- Reachability decides it. A child that allocates the same data in a block-scoped
const(garbage at load) does not leak: 147 MB → 403 MB after 200 iframes. So
the removed iframe's global object stays reachable. - None of these change the result (identical numbers): an open or closed
BroadcastChannelin the child, a listener onparent, an openWebSocket, and
navigating the iframe toabout:blankbefore removal. - Playwright's automation is not the trigger. A page that adds and removes the
iframes by itself, with nopage.evaluateorpage.route, leaks the same in
Playwright WebKit: 4.8 GB after 129 iframes. - System WebKit does not leak. The same self-driving page in a system
WKWebView
(macOS 27.2) stays flat at about 264 MB for 200 iframes. That points at Playwright's
WebKit build or its inspector backend, not at WebKit itself.
Impact
Vitest browser mode on WebKit grows each page by the full heap of every finished test
file. A 185-file suite reaches about 8 GB per page and crashes the page (or exhausts a
16 GB CI runner with three pages).
- 主要语言
- TypeScript
- 星标
- 100k
- 派生
- 6.9k
- 平均合并
- 16 小时 8 分钟
- 30 天内合并 PR
- 281
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/playwright 的其他 Issue
-
[MCP]: page snapshots in .playwright-mcp/ are not git-ignored (.playwright-cli/ is, since #42318)未关闭
难度 2/5 1-3 小时 新手友好度 62/100
microsoft/playwright#44289 ·
维护者通常 1 天内回复
-
agent-triage-done
难度 2/5 1-3 小时 新手友好度 72/100
microsoft/playwright#44264 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 22/100
microsoft/playwright#44288 ·
维护者通常 1 天内回复
-
[Bug]: page.goto never returns for a load started as a newer service worker takes over (Chromium)未关闭
难度 5/5 一周以上 新手友好度 12/100
microsoft/playwright#44287 ·
维护者通常 1 天内回复
-
[MCP] browser_tabs list/select indices diverge across HTTP sessions with --shared-browser-context未关闭
难度 4/5 3-5 天 新手友好度 22/100
microsoft/playwright#44279 ·
维护者通常 1 天内回复
查看 microsoft/playwright 的全部 Issue
相似的 Issue
-
good first issue
难度 2/5 半天 新手友好度 65/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
blamechris/chroxy#9272 ·
维护者通常 1 天内回复
-
no-repo-link tool-submission
难度 1/5 1 小时以内 新手友好度 66/100
BraveOPotato/NoSignups#2458 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
drmrd/vernacular#1061 ·
维护者通常 1 天内回复
-
[Bug] PUT /profiles/{id} silently drops design_prompt — designed voice profiles cannot be edited未关闭
难度 2/5 1-3 小时 新手友好度 82/100