[BUG] WebKit keeps every removed iframe's JS heap alive (memory grows until the page crashes)

Đang mở
#44,290 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
12/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript, nodejs, playwright, typescript
Lĩnh vực
testing-qa

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.04 image, 4 CPU, 16 GB); macOS 27.2
  • Found through Vitest 5.1.1 browser mode (@vitest/browser-playwright 5.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
    BroadcastChannel in the child, a listener on parent, an open WebSocket, and
    navigating the iframe to about:blank before removal.
  • Playwright's automation is not the trigger. A page that adds and removes the
    iframes by itself, with no page.evaluate or page.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).

Ngôn ngữ chính
TypeScript
Star
100k
Fork
6.9k
Merge trung bình
16 giờ 8 phút
Pull request đã merge (30 ngày)
281

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/playwright

Tất cả issue của microsoft/playwright

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.