Skip to content

feat: support Electron 30 and later - #28

Merged
Fiona2016 merged 4 commits into
publishfrom
feat/support-electron-30
Sep 3, 2026
Merged

Fiona2016 merged 4 commits into
publishfrom
feat/support-electron-30

Conversation

@Fiona2016

@Fiona2016 Fiona2016 commented Sep 3, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #27 — the base retargets to publish once that merges.

Change

session.registerPreloadScript, which the bridge preload is registered through, only exists from Electron 35. It is the only version-sensitive API the SDK uses — everything else (crashReporter, app.getPath, contextBridge, ipcRenderer, app.on('session-created')) has been there far longer, and dd-trace@5 asks for Node >=18 <26, which Electron 30 satisfies.

So instead of branching at each call site, fill the method in from session.setPreloads when it is absent. The SDK stays written against one API, and dd-trace's own registration — made through the same method, on the versions where dd-trace installs at all — keeps being redirected to the SDK's script as before.

  • peerDependencies lowered to electron >= 30, version to 0.3.0.
  • e2e now runs on the supported floor as well as the current Electron.

Known gap below Electron 37

datadog-instrumentations gates its whole Electron hook on electron >= 37. On Electron 30 to 36 that means Electron's own net module is not traced and its requests produce no resource events. Everything else is unaffected: sessions, views, errors, native crashes, terminated renderers, the renderer bridge, and main process HTTP made through Node's http/https or the global fetch — those are instrumented independently of that hook, and the e2e suite asserts them on both legs of the matrix.

This is documented in the README and the changelog, and the one scenario that asserts Electron net tracing skips itself below 37 rather than the claim being quietly lowered.

Known behavioural difference on Electron 30–34

setPreloads replaces the session's preload list instead of adding to it, so the list is read back and appended to: an application's own preloads survive. The reverse does not hold — an application that calls session.setPreloads() itself after the bridge is installed drops it, where registerPreloadScript would have kept both. Applications that set preloads per window through webPreferences.preload are unaffected.

Verification

  • Six new unit cases cover the setPreloads path against the real installBridgePreload: the SDK preload is registered, the application's existing preloads survive, custom partitions are covered, registration happens at most once per session, a later registration is answered with the SDK script, and nothing is warned because nothing is lost. Reverting the source change fails all six.
  • The no-API-at-all path keeps its own cases: no throw from either listener, a later registration stays harmless, one warning across sessions.
  • Full unit suite (702 tests), tsc --noEmit, e2e typecheck and eslint clean.
  • A real Electron 30 runtime is exercised by the new e2e matrix job. Its first run is what surfaced the net gap above — 54 of 55 scenarios passed on Electron 30.5.1, including every renderer-bridge scenario, which is the evidence that the setPreloads fill-in works end to end.

`session.registerPreloadScript`, which the SDK and dd-trace both register the
bridge preload through, only exists from Electron 35. Below that, fill the
method in from `session.setPreloads`, which has been there since Electron 2,
rather than branching at each call site: the SDK and dd-trace stay written
against one API, and dd-trace's registration from inside the `BrowserWindow`
constructor is redirected to the SDK's script exactly as on a newer runtime.

`setPreloads` replaces the session's preload list instead of adding to it, so
the list is read back and appended to and an application's own preloads survive.
The reverse does not hold: on Electron 30 to 34 an application that calls
`setPreloads` itself after the bridge is installed drops it. Applications that
set preloads per window through `webPreferences.preload` are unaffected.

An Electron with neither API still degrades rather than failing: registrations
are accepted and dropped, and one warning names what is lost.

Run the e2e suite on the supported floor as well as the current Electron, so
the floor cannot rot unnoticed.
…ectron-30

# Conflicts:
#	src/preload/preloadInjection.ts
`datadog-instrumentations` gates its whole Electron hook on `electron >= 37`,
so below that nothing wraps Electron's own `net` module and its requests produce
no resource events. Node `http`/`https` and the global `fetch` are instrumented
independently of that hook and keep working on every supported version, which is
what the tests around this one assert.

Skip the scenario below Electron 37 rather than lower the claim, and document
the gap in the README and the changelog.
@Fiona2016
Fiona2016 changed the base branch from fix/legacy-electron-preload-crash to publish September 3, 2026 11:18
@Fiona2016
Fiona2016 merged commit 309635e into publish Sep 3, 2026
3 checks passed
@Fiona2016
Fiona2016 deleted the feat/support-electron-30 branch September 3, 2026 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant