Repository navigation
feat: support Electron 30 and later - #28
Merged
Merged
Conversation
`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
changed the base branch from
fix/legacy-electron-preload-crash
to
publish
September 3, 2026 11:18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #27 — the base retargets to
publishonce 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, anddd-trace@5asks for Node>=18 <26, which Electron 30 satisfies.So instead of branching at each call site, fill the method in from
session.setPreloadswhen 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.peerDependencieslowered toelectron >= 30, version to 0.3.0.Known gap below Electron 37
datadog-instrumentationsgates its whole Electron hook onelectron >= 37. On Electron 30 to 36 that means Electron's ownnetmodule is not traced and its requests produce noresourceevents. Everything else is unaffected: sessions, views, errors, native crashes, terminated renderers, the renderer bridge, and main process HTTP made through Node'shttp/httpsor the globalfetch— 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
nettracing skips itself below 37 rather than the claim being quietly lowered.Known behavioural difference on Electron 30–34
setPreloadsreplaces 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 callssession.setPreloads()itself after the bridge is installed drops it, whereregisterPreloadScriptwould have kept both. Applications that set preloads per window throughwebPreferences.preloadare unaffected.Verification
setPreloadspath against the realinstallBridgePreload: 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.tsc --noEmit, e2e typecheck andeslintclean.netgap above — 54 of 55 scenarios passed on Electron 30.5.1, including every renderer-bridge scenario, which is the evidence that thesetPreloadsfill-in works end to end.