# Add Crash Reporting to an Electron App

Yes. An agent wires Electron's crashReporter into your app before the first window opens, catches renderer errors through the preload, adds tests and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-crash-reporting/electron/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads how the app starts and what it already logs. In an app shaped like electron-react-boilerplate, src/main/main.ts creates the `BrowserWindow` inside `app.whenReady()`, then calls `startAutoUpdates()` from src/main/updates.ts, which routes electron-updater's errors to electron-log and guards against a second start with a `started` flag. `reportWindowError` logs a failed window creation and destroys the window. electron-log is a dependency, `@electron/notarize` and `electron-updater` are too, and the renderer talks to the main process only through the `ipc-example` channel the preload exposes with `contextBridge`. There is no crash reporter: a native crash in the GPU or renderer process leaves nothing but the operating system's dialog.

The order of calls is the whole design. Electron's `crashReporter.start` must run in the main process as early as possible, before `app.on('ready')`, because a renderer created before the reporter starts is not monitored. The agent adds src/main/crashes.ts with a `startCrashReporting()` that calls `crashReporter.start` with a `submitURL` read from an environment variable, `uploadToServer` true only when that URL is set and the app is packaged, `rateLimit` true, and `globalExtra` carrying the app version from `app.getVersion()` and the channel, and calls it at the top of main.ts before `whenReady`. With no URL configured, dumps are still written under `app.getPath('crashDumps')` and nothing leaves the machine, so a developer build behaves as before.

JavaScript errors are not native crashes, so they get a second path that reuses what the app has. In the main process, `process.on('uncaughtException')` and `process.on('unhandledRejection')` log through electron-log and call `crashReporter.addExtraParameter` with the error name so the next native crash carries it. In the renderer, a `window.onerror` and `unhandledrejection` listener in src/renderer/index.tsx sends the message, stack and URL over a new typed `report-error` channel added to the `Channels` union in src/main/preload.ts, and the main process logs it with the same transport. The `Content-Security-Policy` meta tag in src/renderer/index.html stays as it is, because the preload does the sending.

Tests follow src/__tests__/updates.test.ts, which mocks `electron`, `electron-updater` and `electron-log` with `jest.mock` and runs under the node environment. A crashes.test.ts asserts that `crashReporter.start` is called once with `uploadToServer: false` when no URL is set, that it is called with the URL and `uploadToServer: true` when one is set and `app.isPackaged` is true, and that a second call does not start it again. The agent runs `npm run lint`, `npm exec tsc -- --noEmit`, `npm test` and `npm run package`, the steps test.yml runs, and the `.erb/scripts/smoke-test.cjs` startup check, which already asserts the renderer throws no exception and the preload IPC round-trips.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add crash reporting to this Electron app. Read package.json, src/main/main.ts, src/main/updates.ts, src/main/preload.ts, src/main/util.ts, src/renderer/index.tsx, src/renderer/index.html, src/renderer/preload.d.ts, src/__tests__/updates.test.ts, jest.config.js, electron.vite.config.ts, .erb/scripts/smoke-test.cjs and .github/workflows/test.yml first. Add src/main/crashes.ts with a startCrashReporting function that calls crashReporter.start before app.whenReady: submitURL from an environment variable, uploadToServer only when the URL is set and app.isPackaged, rateLimit true, globalExtra with the app version; guard against a second start like updates.ts does. Add uncaughtException and unhandledRejection handlers in the main process that log through electron-log and call crashReporter.addExtraParameter. Add a typed report-error channel to the Channels union in preload.ts, and window error and unhandledrejection listeners in the renderer that send through it; keep the Content-Security-Policy meta tag unchanged. Write src/__tests__/crashes.test.ts in the style of updates.test.ts covering no URL, a URL when packaged, and a repeated call. Run npm run lint, npm exec tsc -- --noEmit, npm test, npm run package and the smoke test, then open a pull request with the output and a README section on configuring the submit URL.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request on its own branch that adds src/main/crashes.ts and src/__tests__/crashes.test.ts, adds one import and one call at the top of src/main/main.ts before `whenReady`, adds a `report-error` member to the `Channels` type and a handler for it, adds two listeners in src/renderer/index.tsx, and adds a Crash reporting section to README.md naming the environment variable and where dumps land when it is unset. package.json does not change, because `crashReporter` is part of Electron and electron-log is already a dependency.

The description explains the ordering constraint in one paragraph, quotes the `npm test` output with the three new test names, the `tsc --noEmit` and lint results, and the smoke test's closing line about the home route, the preload IPC and no renderer exceptions, since that script is the repository's own proof that startup still works. It also states plainly that with no submit URL configured no report leaves the machine.

Before merging, a reviewer decides which crash server the URL should point at, whether `rateLimit` should stay on, and whether the renderer listener should also report to the server or only log. A follow-up on the same session can add the server's URL to the publish workflow's environment without starting over.

## Run it on every release you want evidence from

This is a change an engineer wants in before the next release and never gets to: a `POST /o/{org}/sessions` with this prompt and the repository in `resources`, sent from the terminal, lets the branch be ready by the time the release is cut. The run continues in its own sandbox after the laptop closes. The sandbox parks with its disk when the turn ends, so a follow-up such as `add a Help menu item that opens the crashDumps folder` wakes it with the branch, node_modules and the packaged build still there.

With a webhook URL on the API key, Rush posts `run.completed` or `run.failed` with the `session_url` when the turn ends. A team that ships more than one Electron app from the same boilerplate can send the same prompt to each repository, one run per repository, and each run reads that app's own main process.

## Why run it on Rush?

Crash reporting is a startup-order problem, and the way to know the order is right is to run the app: start it, confirm the reporter is up before the window, and confirm the renderer still loads with the preload bridge intact. The agent does that in its own sandbox with the repository's own smoke test, a headless Electron under xvfb as test.yml does on Linux, and keeps every line of output in the run's record.

The record also shows the restraint. The transcript has the agent reading `updates.ts` for the guard pattern, choosing to leave uploads off until a URL exists, and keeping the Content-Security-Policy tag untouched by sending through the preload. A reviewer who wants a different reporting service can say so in a follow-up and the parked sandbox swaps the submit path with the tests already written.

## Frequently asked questions

### Does this send anything without a server configured?

No. uploadToServer is true only when the submit URL environment variable is set and app.isPackaged is true. Otherwise dumps are written under app.getPath('crashDumps') and stay on the machine, which is what a development build should do.

### Why must the reporter start before the window?

Because Electron documents that a renderer process created before crashReporter.start is not monitored, and that the call belongs in the main process before the ready event. That is why the call sits at the top of main.ts rather than inside whenReady beside startAutoUpdates.

### Does it add a dependency like Sentry?

No. crashReporter is part of Electron and the JavaScript error path uses electron-log, which is already a dependency, so package.json is unchanged. If the team wants a hosted service, a follow-up can point the submit URL at any server that accepts Breakpad-style minidump uploads.

### How do renderer errors reach the main process?

Through a new report-error member of the Channels type in preload.ts, sent with the same ipcRenderer wrapper the ipc-example channel uses, so the renderer never touches Node and the Content-Security-Policy meta tag does not change. The main process logs what it receives.

### What does the smoke test prove here?

That the app still starts with the reporter in place: .erb/scripts/smoke-test.cjs launches the app, waits for the home route and the image, round-trips the preload IPC and asserts the renderer threw no exception. The pull request quotes its closing line.

## More Electron jobs

- [Add Dark Mode to an Electron App](https://getrush.ai/run/add-dark-mode/electron/)
- [Add Deep Link Handling to an Electron App from a Linear Issue](https://getrush.ai/run/add-deep-links/electron/)
- [Add Open and Save File Dialogs to an Electron App from a Linear Issue](https://getrush.ai/run/add-file-dialogs/electron/)

## The same job on other stacks

- [Add Crash Reporting to an Expo App](https://getrush.ai/run/add-crash-reporting/expo/)
- [Add Crash Reporting to a Flutter App](https://getrush.ai/run/add-crash-reporting/flutter/)
- [Add Crash Reporting to a React Native App](https://getrush.ai/run/add-crash-reporting/react-native/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
