microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
63.82k stars 3.46k forks source link

[Bug]: Timeout on electron.launch when not loading any file or URL in the main window #29386

Open dabo248 opened 5 months ago

dabo248 commented 5 months ago

Version

1.41.1

Steps to reproduce

  1. Clone my repo at https://github.com/dabo248/electron-playwright-issue
  2. Run the following commands:
npm install
npm run build
npx playwright test

Expected behavior

I expect the example test to succeed without setting any URL or file to the main window. Only if I load an URL (or file) with the BrowserWindow it works. See main.js for this workaround.

Actual behavior

Playwright's electron.launch does not return and the test runs into a timeout.

I was able to track it down to _waitForAllPagesToBeInitialized not returning for the main window because of Emulation.setFocusEmulationEnabled not receiving a response.

When running the test with DEBUG=pw:protocol npx playwright test you can see a response for the browser view ("id":11), but not for the browser window ("id":22):

pw:protocol SEND ► {"id":11,"method":"Emulation.setFocusEmulationEnabled","params":{"enabled":true},"sessionId":"8D031A3EF58E25A9CCF2354E0C8F467E"} +1ms

[...]

pw:protocol ◀ RECV {"id":11,"result":{},"sessionId":"8D031A3EF58E25A9CCF2354E0C8F467E"} +0ms

[...]

pw:protocol SEND ► {"id":22,"method":"Emulation.setFocusEmulationEnabled","params":{"enabled":true},"sessionId":"D8169FB4EE16A5D0A8366C326B7FACC6"} +1ms

Additional context

I first experienced this issue when switching from Electron 24.1.0 to 27.1.2 without changing the Playwright version.

Environment

System:
    OS: Linux 6.5 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish)
    CPU: (4) x64 QEMU Virtual CPU version 2.5+
    Memory: 12.71 GB / 15.61 GB
    Container: Yes
  Binaries:
    Node: 18.15.0 - ~/.nvm/versions/node/v18.15.0/bin/node
    npm: 9.5.0 - ~/.nvm/versions/node/v18.15.0/bin/npm
  Languages:
    Bash: 5.1.16 - /usr/bin/bash
  npmPackages:
    @playwright/test: ^1.41.1 => 1.41.1
dgozman commented 5 months ago

I was able to repro by modifying the executablePath:

  const electronApp = await _electron.launch({
    executablePath: 'dist/mac-arm64/electron-playwright-issue.app/Contents/MacOS/electron-playwright-issue'
  });
Agritite commented 1 week ago

Can confirm this also happens in our codebase. At the beginning of our program we have this code:

const dummy = new BrowserWindow({ x: 1, y: 1, show: false });

doSomething(dummy.getNativeWindowHandle());

dummy is the first BrowserWindow to be created, and because we merely need a HWND to handle WM_QUERYENDSESSION messages, loadURL is not called, which resulted in the same issue.

Once I added

await dummy.loadURL('about:blank');

_electron.launch no longer hangs.

Environment

Windows 11 x64 22631
electron@28.3.3
electron-builder@24.10.0
playwright@1.45.0