Skip to content

[Bug]: frame.content() on a frame whose document never arrives hangs forever, even after the page is closed #43647

Closed

Description

Version

1.63.0 (Java, bundled driver)

Steps to reproduce

  1. Serve a page with <iframe src="/hang">, where /hang never answers.
  2. Navigate with waitUntil: DOMCONTENTLOADED: the child frame exists, frame.url() is "" (no document committed).
  3. Call childFrame.content().
  4. From another thread, close the tab through the browser's DevTools endpoint (/json/close/<targetId>): the browser answers Target is closing, page.isClosed() becomes true.

Self-contained repro (JDK HttpServer + Playwright Java):

import com.microsoft.playwright.*;
import com.microsoft.playwright.options.WaitUntilState;
import com.sun.net.httpserver.HttpServer;
import java.net.InetSocketAddress;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.List;
import java.util.concurrent.*;

public class Repro {
  public static void main(String[] args) throws Exception {
    long t0 = System.currentTimeMillis();
    HttpServer server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
    server.setExecutor(Executors.newCachedThreadPool());
    server.createContext("/page", ex -> {
      byte[] b = "<html><body><iframe src='/hang'></iframe></body></html>".getBytes();
      ex.sendResponseHeaders(200, b.length); ex.getResponseBody().write(b); ex.close();
    });
    server.createContext("/hang", ex -> { try { Thread.sleep(600_000); } catch (InterruptedException e) { } });
    server.start();
    int cdpPort = 9333;
    try (Playwright pw = Playwright.create()) {
      Browser browser = pw.chromium().launch(new BrowserType.LaunchOptions()
          .setArgs(List.of("--remote-debugging-port=" + cdpPort)));
      Page page = browser.newPage();
      page.navigate("http://127.0.0.1:" + server.getAddress().getPort() + "/page",
          new Page.NavigateOptions().setWaitUntil(WaitUntilState.DOMCONTENTLOADED));
      Frame child = page.frames().get(1);
      System.out.println("child frame url='" + child.url() + "'");

      // Close the tab from another thread, through the browser's own DevTools endpoint.
      HttpClient http = HttpClient.newHttpClient();
      String targets = http.send(HttpRequest.newBuilder(URI.create("http://127.0.0.1:" + cdpPort + "/json/list")).build(),
          HttpResponse.BodyHandlers.ofString()).body();
      String targetId = targets.replaceAll("(?s).*\"id\": \"([0-9A-F]+)\",\\s*\"title\": \"[^\"]*\",\\s*\"type\": \"page\".*", "$1");
      ScheduledExecutorService closer = Executors.newSingleThreadScheduledExecutor();
      closer.schedule(() -> {
        try {
          String r = http.send(HttpRequest.newBuilder(URI.create("http://127.0.0.1:" + cdpPort + "/json/close/" + targetId)).build(),
              HttpResponse.BodyHandlers.ofString()).body();
          System.out.println((System.currentTimeMillis() - t0) + " ms: tab closed -> " + r);
        } catch (Exception e) { System.out.println("close failed " + e); }
      }, 5, TimeUnit.SECONDS);
      closer.schedule(() -> {
        System.out.println((System.currentTimeMillis() - t0) + " ms: content() still pending, page.isClosed()=" + page.isClosed());
        System.exit(1);
      }, 65, TimeUnit.SECONDS);

      System.out.println((System.currentTimeMillis() - t0) + " ms: calling child.content()");
      String html = child.content(); // never returns
      System.out.println("content() returned " + html.length() + " chars");
      System.exit(0);
    }
  }
}

Output:

child frame url=''
1780 ms: calling child.content()
6798 ms: tab closed -> Target is closing
66787 ms: content() still pending, page.isClosed()=true

Expected behavior

content() returns the frame's initial empty document, or fails once its page is closed ("Target page, context or browser has been closed").

Actual behavior

content() never returns — still pending 60 s after the tab was closed. The Frame.content call carries no timeout, and closing the page does not reject it, so nothing bounds it.

Additional context

  • Same result when the iframe is created by a script after load, and when content() is called 32 s after the frame was created.
  • The same hang is seen for an uncommitted frame nested in a cross-origin iframe.

Environment

  • OS: macOS 27 (arm64)
  • Browser: Chromium headless shell bundled with Playwright 1.63.0
  • Language: Java 21

Activity

  1. sunny-kavixo commented on Oct 26, 2026

    @sunny-kavixo

    Hi Playwright maintainers,

    I'd like to contribute to Issue #43647, and I've started investigating the reported frame.content() hang when an iframe's document never commits, including the case where the owning page is subsequently closed.

    My investigation will focus on:

    1. Independently reproducing the reported behavior using the supplied Java example and a minimal native Node.js Playwright test.
    2. Comparing the behavior on the reported Playwright version and the current upstream implementation.
    3. Tracing frame lifecycle handling, pending operations, and cancellation when the page or browser closes.
    4. Identifying the root cause and determining whether a minimal, backward-compatible fix is appropriate.
    5. Adding focused regression tests covering uncommitted documents, page closure, and normal frame.content() behavior.
    6. Running the relevant tests and checks before proposing an upstream change.

    I'll also check for existing fixes or overlapping contributions to avoid duplicating work.

    Could you please confirm whether this issue is available for contribution and whether I may proceed with a focused fix and PR once the issue is independently reproduced?

    I'll follow the repository's contribution guidelines and share verified findings before claiming a resolution.

    Thank you for your consideration.

    Best regards,
    Putluru Sandeep
    GitHub: Putluru Sandeep (@sunny-kavixo)

  2. github-actions commented on Oct 26, 2026

    @github-actions
    Contributor

    Hi, I'm the Playwright bot and I reproduced this on Linux.

    Reproduced in Chromium and WebKit on 1.65.0-next (e478109de5542aa6bd69f817d6cb054523af9ce4). Firefox completes in this case. The pending execution-context wait does not stop when its page closes. A verified fix makes it reject on page closure and preserves the target-closed error.

    Draft fix: #43650

    Triaged on Linux by the Playwright bot - agent run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions