New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Preload script executing in the renderer process #35584
Comments
From a peek at the screenshots it looks like you're trying to import
|
That is true, but it was only for debugging purposes trying to see if the preload script was executing at all. In the committed version on GitHub, |
That's not how it works and it never has been. Preload is part of the Renderer, that's why you can access the DOM from it. But until Electron 20 (without sandbox) preload scripts were allowed to do a lot more. Please re-read the breaking changes and what https://www.electronjs.org/docs/latest/tutorial/sandbox#preload-scripts |
@Prinzhorn is correct. |
Well, then I guess my reading for tomorrow morning will be the docs again. Clearly, I misunderstood where the preload script is being executed and the concept behind it. 😅 |
Preflight Checklist
Electron Version
20.1.1
What operating system are you using?
Windows
Operating System Version
Windows 10 Version 21H2
What arch are you using?
x64
Last Known Working Electron version
19.0.6
Expected Behavior
When I create a window, I expect the preload script passed in the window options to run in the main process so that the contextBridge can be initialized for the renderer:
This is how it should look, but requires downgrading to Electron 19.0.6:
Actual Behavior
Instead, it runs in the renderer which causes an error to be thrown in the browser console saying that it cannot find the preload script:
This has only started happening since upgrading to version 20.1.1 and the preload script is definitely where it is expected to be for the main process.
Testcase Gist URL
No response
Additional Information
All it takes to reproduce is to clone https://github.com/eiskalteschatten/electron-react-typescript, run
npm i
, thennpm start
. It will compile the TypeScript files for the main process, launch the React development server, then start Electron.Files of interest:
I'm currently running this on Windows 10, but I've also tested it with Ubuntu 22.04 and macOS 12.5.1 and the exact same error occurs.
This is not the only project I have where this error occurs and I've had to downgrade back to Electron 19 in order to avoid this problem from cropping up in the other, critical projects.
The text was updated successfully, but these errors were encountered: