requirejsdurandal-2.0electron

Electron - Issue Resolving Electron Modules In Renderer Process


I am having difficulty resolving the electron modules in my web application using Electron v0.32.3 using require. My understanding (although its not very clear in the docs) is that the modules are supposed to be automatically available to require of the application being run in the webview (examples include 'ipc' and 'remote'). I can see that they are there at runtime, but I am not sure how to access them: enter image description here

I feel like there is some piece to this that I am missing. Other information: my web application is a Durandal 2x SPA that uses require to load modules already. Is there any other kind of setup that is required in the render process requirejs config to access these modules?


Solution

  • It turns out I just didn't understand all of the different processes going on. So with an application that is using a webview inside of a browser-window, there are actually three processes to be concerned about:

    1. Main process - has access to node
    2. Renderer process (browser window) - has access to node by default
    3. Web view process - does not have access to node by default

    I was seeing the node modules available to 2) and trying to use them in 3). The webview has the 'nodeintegration' attribute that can be used to enable this: http://electron.atom.io/docs/v0.34.0/api/web-view-tag/#nodeintegration

    However, using a preload script allows for exposing only the necessary node functionality with using nodeintegration: http://electron.atom.io/docs/v0.34.0/api/web-view-tag/#preload

    I went with that solution, setting up communication between the renderer process and the webview process.