Repository navigation
fix: process undefined in ESM preload when contextIsolation is disabled - #51693
Conversation
|
For more information on signing commits, see GitHub's documentation on Telling Git about your signing key. |
8f70e5a to
64b6fc9
Compare
|
Congrats on merging your first pull request! 🎉🎉🎉 |
|
Release Notes Persisted
|
|
I was unable to backport this PR to "42-x-y" cleanly; |
|
I have automatically backported this PR to "43-x-y", please check out #51723 |
…bled (#51726) * fix: `process` undefined in ESM preload when contextIsolation is disabled (#51693) Co-authored-by: Charles Kerr <[email protected]> * empty commit for faraday https://github.com/electron/faraday/blob/8d85b5e342f6d5ef0c4f3f87faf0a118aaeee533/internal/checker/checker.go\#L231 --------- Co-authored-by: Sheita <[email protected]>
Description of Change
Fixes #46142.
When
nodeIntegrationandcontextIsolationare both disabled, the Nodeglobals (
process,Buffer,setImmediate, ...) were being removed from therenderer's main world via a
process.once('loaded', ...)listener. The'loaded'event fires on the next tick afterlib/renderer/init.tsreturns,which is before any async ESM preload script has finished executing — so by
the time the preload code ran,
processwas already gone and any access toit threw
ReferenceError. CJS preloads were unaffected because they ransynchronously inside
init.ts, before'loaded'fired.This change drops the
'loaded'-based deletion and instead runs itexplicitly in an
onPreloadsLoadedcallback that is invoked right beforeappCodeLoaded()in both the ESM-preload path (via.finally(), so itstill runs even if a preload throws) and the no-ESM-preload path. The
deletion still happens after every preload (CJS or ESM) has had a chance
to use the Node globals, and still before the renderer's user-facing
scripts run — preserving the existing security boundary.
Checklist
npm testpassesRelease Notes
Notes: Fixed an issue where
processand other Node globals were undefined in ESM preload scripts whencontextIsolationwas disabled.