Install `playwright` (not `@playwright/test` alone) as it includes the Electron automation module. Import and launch: `const { _electron: electron } = require('playwright'); const app = await electron.launch({ args: ['path/to/main.js'] })`.
Obtain the first browser window: `const window = await app.firstWindow()` — this returns a Playwright `Page` object, and the full Playwright page API (locators, assertions, network interception) is available on it.
Evaluate code in the main Electron process (Node.js context): `const appPath = await app.evaluate(({ app }) => app.getAppPath())` — `app.evaluate` runs code in the main process, not the renderer.
Take a screenshot of the app window: `await window.screenshot({ path: 'screenshot.png' })`, or run any standard Playwright page interactions and assertions.
Close the app cleanly: `await app.close()` — this signals Electron to exit rather than just closing the window.
Known gotchas
Playwright's Electron support requires that the app is launched by Playwright — you cannot attach to an already-running Electron process the way you can attach to a remote Chrome via CDP. The app must be started via `electron.launch`.
If the Electron app uses `contextIsolation: true` and a `preload` script, code evaluated via `window.evaluate` runs in the renderer process JavaScript context, not in the preload. Main-process operations must go through `app.evaluate` and the IPC bridge your app exposes.
The version of Electron bundled with your app may not match the Chromium version expected by the installed Playwright version. Check Playwright's release notes for the Electron version compatibility matrix; mismatches can cause unexpected failures or missing API support.
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp