Driving the Electron app
Overview
scripts/drive.mjs launches the project's Electron app under Playwright in a
background daemon and keeps it running between commands, so each action
(click, type, snapshot, screenshot, eval) is one fast shell call. Every launch
uses a scratch profile, so the agent can check a UI change or reproduce a bug
in the real app, not only in unit tests, without touching the user's data.
When to Use This Skill
- Use when you need to verify a UI change in the running Electron app.
- Use when reproducing a renderer or startup bug, or a failure that only
shows up in the production build (for example a stricter CSP).
- Use when checking first-run, onboarding or settings screens.
- Use when exercising a feature end to end, including IPC through the preload
bridge or code in the main process.
- Do not use it for web apps without Electron, or for multi-window flows (see
Limitations).
How It Works
Step 1: Check prerequisites
scripts/drive.mjs, in this skill's directory, finds the project by the
nearest package.json, so run it from anywhere inside the project. Set DR
to its absolute path.
It needs electron and playwright-core (1.49 or later) installed in the
project. If start says either is missing, tell the user rather than
installing it yourself. Launch settings come from drive.config.json at the
project root (see Step 4); with no file, it runs electron ..
Step 2: Start, look, act, stop
DR=<this skill's directory>/scripts/drive.mjs
$DR start # last build, profile 'default'; prints status
$DR snapshot # accessibility tree: find what to click, by role and name
$DR click 'role=button[name="Get started"]'
$DR fill 'role=textbox[name="Email"]' 'test@example.com'
$DR wait 'text=Welcome'
$DR screenshot # prints a PNG path; Read it to see the window
$DR logs --lines 80 # main and renderer console, plus the config's logFile
$DR stop # ALWAYS, before finishing
- Start options:
--build: run the config's build command first. Needed after any
source change if the app runs from a build, because the build is
otherwise stale; start prints its age.
--fresh: wipe the scratch profile, which gives you the app's first-run
state.
--profile <name>: a separate scratch profile.
--dev: see Step 5.
- Targets are Playwright selectors. Prefer
role=button[name="…"] from
snapshot output, then text=…, then CSS.
-- ends the flags. Put it before text that starts with dashes:
$DR fill 'role=textbox[name="Args"]' -- --verbose.
- Other commands:
select <target> <value|label>, press <key>,
status, screenshot --selector <css>. $DR help lists everything.
Step 3: Run code in the app
eval <js> runs in the renderer, main <js> in the main process
(electron and process are in scope, require is not). Use a bare
expression, or a body with return. - reads the code from stdin, which
avoids quoting entirely. The result comes back as JSON, so return plain data:
a DOM node or a function comes back as undefined or {}.
To exercise IPC, call whatever the app's preload exposes through eval. That
goes through the real preload bridge, as the app's own renderer code does.
Step 4: Configure the launch (optional)
drive.config.json at the project root; every field is optional:
{
"build": "npm run build",
"args": ["."],
"env": { "APP_DATA_DIR": "{profile}/data" },
"logFile": "logs/main.log",
"dev": {
"args": ["."],
"env": { "ELECTRON_RENDERER_URL": "http://localhost:5173" },
"url": "http://localhost:5173"
}
}
args: what Electron is launched with: an app directory whose
package.json main is the built entry point, or the entry file itself.
env: added to the app's environment. {profile} becomes the scratch
profile directory (in env values only, not in args). This is how data
kept outside userData is redirected: APP_DATA_DIR is only an example
name, and it has an effect only if the app reads it. Check the app's source
for the variable it actually uses.
logFile: a log file relative to the profile directory, shown by logs.
If a project has no config and start fails or launches the wrong thing,
work out these values from the project's package.json and build setup,
then suggest a drive.config.json to the user.
Step 5: Dev mode (optional)
For a fast loop on renderer code, with hot reload and source maps:
- The user (or a background Bash call) starts the renderer dev server
without its own Electron. Many templates'
start/dev scripts launch
Electron too, and two instances would share state. The config's
dev.url is checked before launch.
$DR start --dev launches Electron with dev.args and dev.env, and
NODE_ENV=development.
Examples
Example 1: Verify a change to the first-run screen
$DR start --build --fresh
$DR snapshot
$DR click 'role=button[name=/Next/]'
$DR screenshot
$DR logs --lines 40
$DR stop
Example 2: Inspect renderer state and call IPC
echo "return document.querySelectorAll('button').length" | $DR eval -
$DR eval "window.api.getSettings()"
Example 3: Query the main process
$DR main "electron.app.getVersion()"
$DR main "electron.BrowserWindow.getAllWindows().length"
Best Practices
- ✅ Look before acting. Take a
snapshot or screenshot first. The same
profile can open differently on a second launch (past the first-run
screens), and a click that times out usually means the screen is not what
you assumed.
- ✅ Check
logs for [renderer:error] and [renderer:pageerror] after
each step.
- ✅ Prefer the production build. It catches failures that only show up
there, such as a stricter Content-Security-Policy, which the dev server
would miss.
- ✅ Always
stop, including after a failure. stop reports how the app
went down; anything but "quit via app.quit()" (a hung quit, a SIGKILL) is
worth a line in your report.
- ❌ Don't use the npm/yarn script wrappers (e.g.
yarn drive). Run the
script directly. yarn 1 re-splits arguments and drops inner quotes, which
silently breaks most JavaScript passed to eval and main.
- ❌ Don't install
electron or playwright-core yourself; ask the user.
Limitations
- One window. Commands act on the first window that is not DevTools, and
there is no way to pick another.
status shows which window that is; a
splash screen is current until it closes.
- One app at a time per project.
start refuses while one is running.
- Windows: run it as
node scripts/drive.mjs. The process-tree kill that
stop falls back to is POSIX only.
- Requires
electron and playwright-core 1.49+ in the project, and Node.js
18+.
- It does not replace the project's own test suite or a human check of
visual design. Stop and ask if the launch settings or data locations are
unclear.
Security & Safety Notes
- Local-only. The daemon listens on
127.0.0.1 with a random per-session
token. Nothing is sent to third-party services.
- Never point it at the user's real data. Every launch gets
--user-data-dir set to a scratch profile under
$TMPDIR/electron-drive/<project>/profiles/<name>, which moves
app.getPath('userData'). Data the app keeps elsewhere (a documents
folder, a path from an env var) is only redirected if drive.config.json
sets it through env. Check that before doing anything that writes data.
If the app would touch real user files, stop and tell the user.
eval and main run arbitrary code with the app's privileges; the
main process has full Node.js access. Only run code needed for the task,
and never code that deletes files or makes network calls outside the app's
normal behavior without the user's confirmation.
start --build runs the build command from drive.config.json in a
shell. Read the config before the first --build in a project you did
not set up.
--fresh deletes the scratch profile directory only, never the app's
real userData.
Common Pitfalls
- Problem:
start fails.
Solution: Read the daemon log it prints. Common causes are a missing
build (--build), electron or playwright-core not installed, or wrong
args.
- Problem: "The app is not running".
Solution: It crashed or quit. Run
logs, then stop, then start.
- Problem: The app shows old behavior after a source change.
Solution: The build is stale. Restart with
start --build.
- Problem: A click can't find a button whose name includes icon-font text
(such as
arrow_forward).
Solution: Use a regex name: role=button[name=/Next/].
- Problem: A stuck state after an interrupted session.
Solution:
$DR stop cleans up the daemon, the app and the state file,
even when the daemon is already gone.
Related Skills
@electron-development - For building and packaging the Electron app
itself; use this skill to verify the result in the running app.
@systematic-debugging - Pair with this skill to reproduce and narrow down
a bug in the real app.
1---2name: electron-drive-skill3description: "Launch the project's Electron app on a scratch profile and drive it: click, type, screenshot, run renderer or main-process code, read logs. Use to verify UI changes end to end."4category: testing5risk: critical6source: community7source_repo: Search-3D/electron-drive-skill8source_type: community9date_added: "2026-09-23"10author: Search-3D11tags: [electron, playwright, desktop, e2e, testing, automation]12tools: [claude]13license: "MIT"14license_source: "https://github.com/Search-3D/electron-drive-skill/blob/main/LICENSE"15metadata:16 source: https://skillmd.com/skills/francostino/electron-drive-skill17---1819# Driving the Electron app2021## Overview2223`scripts/drive.mjs` launches the project's Electron app under Playwright in a24background daemon and keeps it running between commands, so each action25(click, type, snapshot, screenshot, eval) is one fast shell call. Every launch26uses a scratch profile, so the agent can check a UI change or reproduce a bug27in the real app, not only in unit tests, without touching the user's data.2829## When to Use This Skill3031- Use when you need to verify a UI change in the running Electron app.32- Use when reproducing a renderer or startup bug, or a failure that only33 shows up in the production build (for example a stricter CSP).34- Use when checking first-run, onboarding or settings screens.35- Use when exercising a feature end to end, including IPC through the preload36 bridge or code in the main process.37- Do not use it for web apps without Electron, or for multi-window flows (see38 Limitations).3940## How It Works4142### Step 1: Check prerequisites4344`scripts/drive.mjs`, in this skill's directory, finds the project by the45nearest `package.json`, so run it from anywhere inside the project. Set `DR`46to its absolute path.4748It needs `electron` and `playwright-core` (1.49 or later) installed in the49project. If `start` says either is missing, tell the user rather than50installing it yourself. Launch settings come from `drive.config.json` at the51project root (see Step 4); with no file, it runs `electron .`.5253### Step 2: Start, look, act, stop5455```bash56DR=<this skill's directory>/scripts/drive.mjs5758$DR start # last build, profile 'default'; prints status59$DR snapshot # accessibility tree: find what to click, by role and name60$DR click 'role=button[name="Get started"]'61$DR fill 'role=textbox[name="Email"]' 'test@example.com'62$DR wait 'text=Welcome'63$DR screenshot # prints a PNG path; Read it to see the window64$DR logs --lines 80 # main and renderer console, plus the config's logFile65$DR stop # ALWAYS, before finishing66```6768- **Start options:**69 - `--build`: run the config's `build` command first. **Needed after any70 source change** if the app runs from a build, because the build is71 otherwise stale; `start` prints its age.72 - `--fresh`: wipe the scratch profile, which gives you the app's first-run73 state.74 - `--profile <name>`: a separate scratch profile.75 - `--dev`: see Step 5.76- **Targets** are Playwright selectors. Prefer `role=button[name="…"]` from77 `snapshot` output, then `text=…`, then CSS.78- **`--`** ends the flags. Put it before text that starts with dashes:79 `$DR fill 'role=textbox[name="Args"]' -- --verbose`.80- Other commands: `select <target> <value|label>`, `press <key>`,81 `status`, `screenshot --selector <css>`. `$DR help` lists everything.8283### Step 3: Run code in the app8485**`eval <js>`** runs in the renderer, **`main <js>`** in the main process86(`electron` and `process` are in scope, `require` is not). Use a bare87expression, or a body with `return`. `-` reads the code from stdin, which88avoids quoting entirely. The result comes back as JSON, so return plain data:89a DOM node or a function comes back as `undefined` or `{}`.9091To exercise IPC, call whatever the app's preload exposes through `eval`. That92goes through the real preload bridge, as the app's own renderer code does.9394### Step 4: Configure the launch (optional)9596`drive.config.json` at the project root; every field is optional:9798```json99{100 "build": "npm run build",101 "args": ["."],102 "env": { "APP_DATA_DIR": "{profile}/data" },103 "logFile": "logs/main.log",104 "dev": {105 "args": ["."],106 "env": { "ELECTRON_RENDERER_URL": "http://localhost:5173" },107 "url": "http://localhost:5173"108 }109}110```111112- `args`: what Electron is launched with: an app directory whose113 `package.json` `main` is the built entry point, or the entry file itself.114- `env`: added to the app's environment. `{profile}` becomes the scratch115 profile directory (in `env` values only, not in `args`). This is how data116 kept outside `userData` is redirected: `APP_DATA_DIR` is only an example117 name, and it has an effect only if the app reads it. Check the app's source118 for the variable it actually uses.119- `logFile`: a log file relative to the profile directory, shown by `logs`.120121If a project has no config and `start` fails or launches the wrong thing,122work out these values from the project's `package.json` and build setup,123then suggest a `drive.config.json` to the user.124125### Step 5: Dev mode (optional)126127For a fast loop on renderer code, with hot reload and source maps:1281291. The user (or a background Bash call) starts the renderer dev server130 **without** its own Electron. Many templates' `start`/`dev` scripts launch131 Electron too, and two instances would share state. The config's132 `dev.url` is checked before launch.1332. `$DR start --dev` launches Electron with `dev.args` and `dev.env`, and134 `NODE_ENV=development`.135136## Examples137138### Example 1: Verify a change to the first-run screen139140```bash141$DR start --build --fresh142$DR snapshot143$DR click 'role=button[name=/Next/]'144$DR screenshot145$DR logs --lines 40146$DR stop147```148149### Example 2: Inspect renderer state and call IPC150151```bash152echo "return document.querySelectorAll('button').length" | $DR eval -153$DR eval "window.api.getSettings()"154```155156### Example 3: Query the main process157158```bash159$DR main "electron.app.getVersion()"160$DR main "electron.BrowserWindow.getAllWindows().length"161```162163## Best Practices164165- ✅ **Look before acting.** Take a `snapshot` or `screenshot` first. The same166 profile can open differently on a second launch (past the first-run167 screens), and a click that times out usually means the screen is not what168 you assumed.169- ✅ **Check `logs`** for `[renderer:error]` and `[renderer:pageerror]` after170 each step.171- ✅ **Prefer the production build.** It catches failures that only show up172 there, such as a stricter Content-Security-Policy, which the dev server173 would miss.174- ✅ **Always `stop`**, including after a failure. `stop` reports how the app175 went down; anything but "quit via app.quit()" (a hung quit, a SIGKILL) is176 worth a line in your report.177- ❌ **Don't use the npm/yarn script wrappers** (e.g. `yarn drive`). Run the178 script directly. yarn 1 re-splits arguments and drops inner quotes, which179 silently breaks most JavaScript passed to `eval` and `main`.180- ❌ **Don't install `electron` or `playwright-core`** yourself; ask the user.181182## Limitations183184- **One window.** Commands act on the first window that is not DevTools, and185 there is no way to pick another. `status` shows which window that is; a186 splash screen is current until it closes.187- **One app at a time** per project. `start` refuses while one is running.188- **Windows:** run it as `node scripts/drive.mjs`. The process-tree kill that189 `stop` falls back to is POSIX only.190- Requires `electron` and `playwright-core` 1.49+ in the project, and Node.js191 18+.192- It does not replace the project's own test suite or a human check of193 visual design. Stop and ask if the launch settings or data locations are194 unclear.195196## Security & Safety Notes197198- **Local-only.** The daemon listens on `127.0.0.1` with a random per-session199 token. Nothing is sent to third-party services.200- **Never point it at the user's real data.** Every launch gets201 `--user-data-dir` set to a scratch profile under202 `$TMPDIR/electron-drive/<project>/profiles/<name>`, which moves203 `app.getPath('userData')`. Data the app keeps elsewhere (a documents204 folder, a path from an env var) is only redirected if `drive.config.json`205 sets it through `env`. Check that before doing anything that writes data.206 If the app would touch real user files, stop and tell the user.207- **`eval` and `main` run arbitrary code** with the app's privileges; the208 main process has full Node.js access. Only run code needed for the task,209 and never code that deletes files or makes network calls outside the app's210 normal behavior without the user's confirmation.211- **`start --build` runs the `build` command from `drive.config.json` in a212 shell.** Read the config before the first `--build` in a project you did213 not set up.214- **`--fresh` deletes the scratch profile directory** only, never the app's215 real `userData`.216217## Common Pitfalls218219- **Problem:** `start` fails.220 **Solution:** Read the daemon log it prints. Common causes are a missing221 build (`--build`), `electron` or `playwright-core` not installed, or wrong222 `args`.223- **Problem:** "The app is not running".224 **Solution:** It crashed or quit. Run `logs`, then `stop`, then `start`.225- **Problem:** The app shows old behavior after a source change.226 **Solution:** The build is stale. Restart with `start --build`.227- **Problem:** A click can't find a button whose name includes icon-font text228 (such as `arrow_forward`).229 **Solution:** Use a regex name: `role=button[name=/Next/]`.230- **Problem:** A stuck state after an interrupted session.231 **Solution:** `$DR stop` cleans up the daemon, the app and the state file,232 even when the daemon is already gone.233234## Related Skills235236- `@electron-development` - For building and packaging the Electron app237 itself; use this skill to verify the result in the running app.238- `@systematic-debugging` - Pair with this skill to reproduce and narrow down239 a bug in the real app.