Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Electron: race condition with firstWindow and loadURL, will hang forever #17765

Closed
Prinzhorn opened this issue Oct 2, 2022 · 3 comments · Fixed by #18804
Closed

[BUG] Electron: race condition with firstWindow and loadURL, will hang forever #17765

Prinzhorn opened this issue Oct 2, 2022 · 3 comments · Fixed by #18804
Assignees
Labels
feature-electron upstream This is a bug in something playwright depends on, like a browser.

Comments

@Prinzhorn
Copy link

Context:

  • Playwright Version: 1.26.1
  • Operating System: Linux (Ubuntu 22.04)
  • Node.js version: 16.15.1
  • Browser: Electron 21.0.1

Code Snippet

test.js

import { _electron as electron } from 'playwright';

(async () => {
  const app = await electron.launch({ args: ['main.cjs'] });

  console.log('trying to get window...');

  await app.firstWindow();

  console.log('got window');
})();

main.cjs

const { app, BrowserWindow } = require('electron');

let mainWindow;

function createWindow() {
  mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
  });

  setTimeout(() => {
    mainWindow.loadURL('https://www.example.com/');
  }, 1000);
}

app.whenReady().then(() => {
  createWindow();
});

Describe the bug

The above will forever hang at trying to get window.... Lowering the setTimeout will eventually make it work. E.g. 20ms will sometimes work and give got window.

I'm running into this because here's what my app does:

  1. Instantly open the window, so you immediately get feedback that the app is starting
  2. Launch an HTTP server on localhost
  3. Once the server is up, call loadURL with the localhost URL including the randomly assigned port

Playwright does not work with this setup, because it essentially requires loadURL to be called roughly immediately after creating the window.

@Prinzhorn
Copy link
Author

Prinzhorn commented Oct 2, 2022

A workaround seems to be to synchronously call mainWindow.loadURL('about:blank'); after creating the window. But I'm not sure about the implications this might have, it should not be necessary.

@yury-s
Copy link
Member

yury-s commented Oct 3, 2022

This is a regression. The example works in v13.4.0 and hangs in v14.2.9.

@mxschmitt
Copy link
Member

Was able to create a smaller repro out of it see here and linked it upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-electron upstream This is a bug in something playwright depends on, like a browser.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants