[BUG] Does Playwright support Electron 18?
Context:
- Playwright Version: 1.24.*
- Operating System: Windows
- Node.js version: 16.10 +
- Browser: Chrome
Code Snippet electronApp = await electron.launch({ args: [path.join(__dirname, ' ****')], bypassCSP: true }); app1stWindow= await electronApp.firstWindow();
**Describe the bug**
**Electron 12 has been EOL, so i migrate the electron app to electron 18 , but seems the playwright get the firstWindow timeout,
my question is does latest playwright supported the electron 18 now???**
Yes it does support Electron 18.
Could you provide us a minimal reproducible what exactly is not working so we can run it locally and find out if the Electron version is the root-cause of it?
Yes it does support Electron 18.
Could you provide us a minimal reproducible what exactly is not working so we can run it locally and find out if the Electron version is the root-cause of it?
os: ubuntu linux node: 16.16.0 electron: 18.3.5
Error:
✖ failed
Error: function timed out, ensure the promise resolves within 5000 milliseconds
at Timeout.
my code:
electronApp = await electron.launch({ args: [path.join(__dirname, '../../../../dist/apps/domy/main.js')], bypassCSP: true }); firstWindow = await electronApp.firstWindow();
can not get electronApp.firstWindow(), function timed out, ensure the promise resolves within 5000 milliseconds
Can you provide us a repro which we can run locally?
I can our tests on Electron 18 and they pass for me (except unrelated failures where we work separately on it. https://github.com/microsoft/playwright/issues/16025 - they are not the cause of the timeout tho).
hello, i test if git clone https://github.com/electron/electron-quick-start, use latest playwright, latest electron version, we can get firstWindow(), but this electron-quick-start main.js is very simple.
i use playwright simple introduction test code. e.g:
const { _electron: electron } = require('playwright');
(async () => { // Launch Electron app. const electronApp = await electron.launch({ args: ['dist/apps/xxx/main.js'], bypassCSP: true });
// Evaluation expression in the Electron context.
const appPath = await electronApp.evaluate(async ({ app }) => {
// This runs in the main Electron process, parameter here is always
// the result of the require('electron') in the main app script.
return app.getAppPath();
});
console.log(appPath);
// Get the first window that the app opens, wait if necessary.
const window = await electronApp.firstWindow();
// Print the title.
console.log(await window.title());
// Capture a screenshot.
await window.screenshot({ path: 'intro.png' });
// Direct Electron console to Node terminal.
window.on('console', console.log);
// Click button.
// await window.click('text=Click me');
// Exit app.
await electronApp.close();
})();
but in our electron main.js, it is duplicate than electron-quick-start main.js, we find this issue when i increase timeout in cucumber before function, e.g
Before({ timeout: 300000 }, async function(this: World) { console.log('before '); console.log(this); electronApp = await electron.launch({ args: [path.join(__dirname, 'dist/apps/xxx/main.js')], bypassCSP: true }); console.log('launch finish', electronApp);
xxxFirstWindow = await electronApp.firstWindow();
then we get this error: electronApplication.waitForEvent: Timeout 30000ms exceeded while waiting for event "window" i see electron app can launch finish, but await electronApp.firstWindow(), firstwindow() can't get even i increase timeout value
and this issue is start from electron 14 version, in electron 13 latest version, i test our main.js it is ok
hello, i test if git clone https://github.com/electron/electron-quick-start, use latest playwright, latest electron version, we can get firstWindow(), but this electron-quick-start main.js is very simple.
i use playwright simple introduction test code. e.g:
const { _electron: electron } = require('playwright');
(async () => { // Launch Electron app. const electronApp = await electron.launch({ args: ['dist/apps/xxx/main.js'], bypassCSP: true });
// Evaluation expression in the Electron context. const appPath = await electronApp.evaluate(async ({ app }) => { // This runs in the main Electron process, parameter here is always // the result of the require('electron') in the main app script. return app.getAppPath(); }); console.log(appPath); // Get the first window that the app opens, wait if necessary. const window = await electronApp.firstWindow(); // Print the title. console.log(await window.title()); // Capture a screenshot. await window.screenshot({ path: 'intro.png' }); // Direct Electron console to Node terminal. window.on('console', console.log); // Click button. // await window.click('text=Click me'); // Exit app. await electronApp.close();})();
but in our electron main.js, it is duplicate than electron-quick-start main.js, we find this issue when i increase timeout in cucumber before function, e.g
Before({ timeout: 300000 }, async function(this: World) { console.log('before '); console.log(this); electronApp = await electron.launch({ args: [path.join(__dirname, 'dist/apps/xxx/main.js')], bypassCSP: true }); console.log('launch finish', electronApp);
xxxFirstWindow = await electronApp.firstWindow();
then we get this error: electronApplication.waitForEvent: Timeout 30000ms exceeded while waiting for event "window" i see electron app can launch finish, but await electronApp.firstWindow(), firstwindow() can't get even i increase timeout value
and this issue is start from electron 14 version, in electron 13 latest version, i test our main.js it is ok
as @lswnsn mentioned , @mxschmitt do you have any comments?
I tried to reproduce but it was working fine for me - could you provide us a full repro in form of a Git repository?
@mxschmitt it is our internal repo, i just can give you electron build out main.js, is it ok?
No, we need a minimal reproducible, see here: https://stackoverflow.com/help/minimal-reproducible-example
@mxschmitt do you have IM tool that i can share my desktop to you, share how to reproduce in my environment?
No I'm sorry that we can't accept whole codebases, we need a minimal reproducible in form of a Git repository.
@mxschmitt this is my reproduce repo: https://github.com/lswnsn/electron-quick-start
you can use this command: node test.js, then you will see electron application can launch, but we can't get the firstWindow(), error is:
C:\cu-vdu\electron-quick-start\electron14
(node:5956) UnhandledPromiseRejectionWarning: electronApplication.firstWindow: Timeout 30000ms exceeded while waiting for event "window"
at C:\cu-vdu\electron-quick-start\test.js:16:38
(Use node --trace-warnings ... to show where the warning was created)
(node:5956) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by
rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (se
e https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:5956) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js pro
cess with a non-zero exit code.
but if you change test.js file, this line: const electronApp = await electron.launch({ args: ['electron14/main.js'] }); to const electronApp = await electron.launch({ args: ['electron13/main.js'] }); or to const electronApp = await electron.launch({ args: ['electron12/main.js'] }); it is work, we can get the firstwindow() and the tilte CU WebEM print in console
this issue is begin from electron 14.0.0, i test in our repo, electron version: 12.2.3 or electron version: 13.6.9, this issue is not exist, only begin from electron 14.0.0, issue exist, we can't get the firstWindow()
Very helpful repro, so what I know so far, that its caused by the child_process.fork. Would be helpful to understand what's all happening in assets/index.js but unfortunately it's minified.
Building the file with NODE_ENV=development / don't minify it would be maybe enough for me to find out what in the file is inferring with our logic, that no new pages get found.
@mxschmitt i have upload new folder electron14-2 to this repo: https://github.com/lswnsn/electron-quick-start, in electron14-2/assets, now there is main.js, this file, mostly is nestjs code and we include wasmBinaryFile which is convert c++ code to js file in order to fullfil our business request.
use node test.js will see errors:
C:\cu-vdu\electron-quick-start\electron14-2
(node:3876) UnhandledPromiseRejectionWarning: electronApplication.firstWindow: Timeout 30000ms exceeded while waiting for eve
nt "window"
at C:\cu-vdu\electron-quick-start\test.js:16:38
(Use node --trace-warnings ... to show where the warning was created)
(node:3876) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of
an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the nod
e process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.ht
ml#cli_unhandled_rejections_mode). (rejection id: 1)
(node:3876) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that
are not handled will terminate the Node.js process with a non-zero exit code.
the difference between electron14 and electron14-2 is : error is same, electronApplication.firstWindow: Timeout, different is, electron14, we can launch electron window, but electron14-2, we can't launch electron window.
Thank you! I was able to find out the root cause, it's show: false which leads into this edge-case. If you set this to show: true instead, it should work as intended until we have a fix for this. Feel free to hide your repro repo from GitHub, I created this one instead: https://github.com/mxschmitt/electron-quick-start/commit/1ba27aed2a6b9ea694d56a17785e356d0c5c307b
Will try to follow-up on a smaller one without Playwright and then file it against Electron.
Would be amazing if you could verify that when setting show: true it works as intended across the "affected Electron versions".
@mxschmitt i test it to set show to true, the electron14 application can launch, but we still can't get the firstWindow, if we can't get the firstwindow, our playwright automatic test case can't run
i use playwright: 1.25.0, electron: 14, set show: true,
error is:
C:\cu-vdu\electron-quick-start\electron14-2
(node:27284) UnhandledPromiseRejectionWarning: electronApplication.firstWindow: Timeout 30000ms exceeded while waiting for event "window"
at C:\cu-vdu\electron-quick-start\test.js:16:38
(Use node --trace-warnings ... to show where the warning was created)
(node:27284) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or b
y rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (s
ee https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:27284) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js pr
ocess with a non-zero exit code.
Actually not sure what the issue is, I found one issue with Electron, which might be a different bug.
I was able to reduce the repro, so if you spawn a subprocess and have:
const common_1 = require("@nestjs/common");
process.send(`SERVER_UP`);
it reproduces as well. Unfortunately I can't spend more time on it, since this is very specific and might not be a Playwright issue. Marking it as p3 for now to collect upvotes if more people run into that.
That should be fixed in 1.28, please re-file if it still does not work!
22/12/2022 I have the same problem