Replies: 1 comment 2 replies
-
I wonder whats the difference between setting up the preload through webpack and the mainwindow |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Originally posted this here as issue #344, so I wanted to move it to a better place (suggested by @alexis-piquet).
First off I wanted to say thank you for creating this as it's been super helpful for me with quite a few projects! I wanted to ask this question as it's something that I find quite useful and feel it may be useful for others as well. I was looking at trying to create an example project that utilizes electron's preload functionality for complete context isolation. I originally came across #259 which was super helpful when I had this issue. However, I noticed that if I wanted to create an example it would only be for the renderer side of things. I didn't want to create a PR with this change yet as it could be a fairly substantial change to most projects and not everyone might find it necessary. So for the time being I'd like to outline my proposal to get your input.
My proposal
To start, following this comment we would set up the
nextron.config.js
file andnext.config.js
files appropriately (dependent on if the project is typescript or javascript).Then, we'd flip our
webPreferences
in thecreate-window
helper so thatnodeIntegrations
is false andcontextIsolation
is true.Next, we'd have a preload file located at
./main/preload.(ts|js)
that could look something like this as an example:Of course, we'd want to show how to utilize the preload file by modifying
./background/main.(ts|js)
to do so:And lastly, for typescript, we could expose the types for the window and modify the tsconfig(s) so that they are recognized. For example
./@types/preload.d.ts
:and our
./renderer/tsconfig.json
:Optionally, we could also introduce an example function (either in the background file or a separate file) for registering our listeners such as:
Again, I'd love to hear if this is something I'd be able to work on adding but either way look forward to hearing your thoughts.
Beta Was this translation helpful? Give feedback.
All reactions