Skip to content
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

Move NodeRT to N-API or make it context-aware (Electron renderer processes in >v14) #158

Open
felixrieseberg opened this issue Jul 8, 2021 · 1 comment

Comments

@felixrieseberg
Copy link
Collaborator

Most of today's NodeRT users use it to call native Windows methods from Node.js or Electron. In order to do so safely in Electron's renderer process, NodeRT has to move to N-API or be otherwise made context-aware.

From Node.js's docs:

There are environments in which Node.js addons may need to be loaded multiple times in multiple contexts. For example, the Electron runtime runs multiple instances of Node.js in a single process. Each instance will have its own require() cache, and thus each instance will need a native addon to behave correctly when loaded via require(). This means that the addon must support multiple initializations.

Until Electron 14, NodeRT could still be loaded safely in renderer processes by using the process.allowRendererProcessReuse option. In the future, this will no longer be possible, meaning that NodeRT should not be loaded in renderer processes.

Options for Electron/NodeRT users

  1. require() NodeRT only in the main process and use Electron's IPC to marshal calls between the main and the renderer process. This is what I, Felix, would do right now.
  2. Move NodeRT to N-API. This is the right solution to the problem and would improve NodeRT dramatically, but I probably don't have the time to do this anytime soon.
  3. Make NodeRT context-aware using NAN's helpers. Easier than option 2, but still work.

I'll gladly accept all pull requests helping here.

@Adam-Kernig
Copy link

Just to add that may help someone if they come across this, it is advised that native calls should not be done via Electrons Render processes instead, build a communication layer in between render and main:
https://www.electronjs.org/docs/tutorial/security

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

No branches or pull requests

2 participants