playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Bug]: Connect to hidden/detached webview page will hang forever using `webview.page()`

Open crazyones110 opened this issue 1 month ago • 1 comments

Version

1.53.0

Steps to reproduce

I'm testing a poorly written Android Hybrid app which does not properly destroy webviews when exited.

Steps to reproduce:

import { _android as android } from "playwright";

const [device] = await android.devices();
const webview = await device.webView({
    pkg: "myapp.webview.pkg.id",
});
console.log("webview got", webview.pid(), webview.pkg());
const initialPage = await webview.page();
console.log("page got", initialPage.url());
const pages = initialPage.context().pages();
for (const p of pages) {
    const isRendering = await p.evaluate(() => {
        return new Promise((res) => {
            const timer = setTimeout(() => {
                res(false);
            }, 100);
            requestAnimationFrame(() => {
                clearTimeout(timer);
                res(true);
            });
        });
    });
    console.log(isRendering);
}

Expected behavior

I can use the raf trick to check whether the page is hidden/detached or visible.

Maybe playwright can let us customize page retrieval timeout or incorporate the raf trick to the server side or expose a new API webview.pages() and let user check whether the page is hidden/detached or visible.

Actual behavior

Sometimes webview.page() will hang forever, I suspect it's due to playwright is connecting to a detached or hidden webview page, and the timeout is set to 0 at server side.

Sometimes the page can be returned by webview.page, but it indeed is detached or hidden, which making moves in it seems useless.

Additional context

Image

Environment

System:
    OS: macOS 15.5
    CPU: (8) arm64 Apple M2
    Memory: 177.14 MB / 16.00 GB
  Binaries:
    Node: 22.15.0 - /Users/crazyones110/.local/state/fnm_multishells/2688_1764752400833/bin/node
    Yarn: 1.22.22 - /Users/crazyones110/.local/state/fnm_multishells/812_1764752170871/bin/yarn
    npm: 10.9.2 - /Users/crazyones110/.local/state/fnm_multishells/2688_1764752400833/bin/npm
    pnpm: 10.22.0 - /Users/crazyones110/.local/state/fnm_multishells/2688_1764752400833/bin/pnpm
  IDEs:
    VSCode: 1.106.3 - /usr/local/bin/code
    Cursor: 0.45.14 - /usr/local/bin/cursor
    Claude Code: 1.2.0 - /Users/crazyones110/.local/state/fnm_multishells/812_1764752170871/bin/claude
  Languages:
    Bash: 3.2.57 - /bin/bash
  npmPackages:
    playwright: 1.53.0 => 1.53.0

crazyones110 avatar Dec 04 '25 07:12 crazyones110

@crazyones110 Could you share an exact repro that allows us to see these hidden/detached pages locally? I think we can just filter them out for you, only connecting to the active page right away, but we need a good repro for that.

dgozman avatar Dec 05 '25 08:12 dgozman

Closing as stale.

Skn0tt avatar Dec 11 '25 11:12 Skn0tt