I am running a test setup with Playwright setup as described in https://playwright.dev/docs/api/class-electron and with Electron v35 in GitHub CI running on Ubuntu with xvfb I keep getting the following error:
Protocol error (Page.captureScreenshot): Cannot take screenshot with 0 width.
The code is this:
const { _electron: electron } = require('playwright');
(async () => {
// Launch Electron app.
const electronApp = await electron.launch({ args: ['main.js'] });
// 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();
})();
Failing line is the one with the screenshot call - await window.screenshot({ path: 'intro.png' });.
It does manage to succeed sometimes, but very rarely. On Windows and Mac, both on CI and locally it does not fail. On Electron v34 the same code is fine. What could be the issue?