Skip to content

[BUG] Memory leak in Chrome on repeated browser open/close #21079

@rustyhectors

Description

@rustyhectors

Context:

  • Playwright Version: 1.29.0
  • Operating System: Mac 12.6.1
  • Node.js version: v19.6.1
  • Browser: Chrome 110.0.5481.100
  • Extra: Note that this is a BYOB (bring your own browser) scenario for this repro

Code Snippet

Help us help you! Put down a short code snippet that illustrates your bug and
that we can run and debug locally. For example:

package repro;

import com.microsoft.playwright.Browser;
import com.microsoft.playwright.BrowserContext;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;
import java.util.Map;

public class Repro {
  // Before running, launch chrome with "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --remote-debugging-port=9223 --headless
  public static void main(String[] args) throws InterruptedException {
    Playwright playwright = Playwright.create(
      new Playwright.CreateOptions().setEnv(Map.of("PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD", "true")));

    // open one browser/page
    Browser browser = playwright.chromium().connectOverCDP("http://" + "localhost" + ":" + 9223);
    BrowserContext context = browser.newContext();
    Page page = context.newPage();
    page.navigate("https://www.google.com");

    // open/close a browser repeatedly
    while (true) {
      try {
        Browser shortLivedBrowser = playwright.chromium().connectOverCDP("http://" + "localhost" + ":" + 9223);
        shortLivedBrowser.close();
        System.out.println("Opened and closed.");
      } catch (Exception e) {
        System.out.println("Failed to open or close browser.");
        System.out.println(e);
      }
      Thread.sleep(10);
    }
  }
}

Describe the bug
Chrome memory usage grows in the "renderer" process.

Baseline before running the repro:
Screen Shot 2023-02-21 at 6 50 06 PM

Right after starting:
Screen Shot 2023-02-21 at 6 50 19 PM

A minute or two:
Screen Shot 2023-02-21 at 6 52 14 PM

About four minutes after starting:
Screen Shot 2023-02-21 at 6 54 37 PM

Metadata

Metadata

Assignees

No one assigned

    Labels

    browser-chromiumupstreamThis is a bug in something playwright depends on, like a browser.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions