Setting NodeIntegration to false prevents Electron window from opening #330

Closed
opened 2026-01-29 16:36:36 +00:00 by claunia · 6 comments
Owner

Originally created by @raloverafs on GitHub (May 23, 2019).

Originally assigned to: @GregorBiswanger on GitHub.

  • Version: ElectronNET.CLI Version: 5.22.12.0

  • Target: .NET Core 2.1

Screen Shot 2019-05-23 at 4 30 29 PM

Steps to Reproduce:

  1. Make a basic Electron.NET app.
  2. Make a BrowserWindowOptions with WebPreferences.NodeIntegration = false
  3. Pass said BrowserWindowOptions to Electron.WindowManager.CreateWindowAsync

We need to set NodeIntegration to false because we are dependent on jQuery, Bootstrap, and Highcharts.

Screen Shot 2019-05-23 at 4 42 07 PM

How can we fix this? Also, is there a workaround to make jQuery and Highcharts work in Electron.NET?

Originally created by @raloverafs on GitHub (May 23, 2019). Originally assigned to: @GregorBiswanger on GitHub. * **Version**: ElectronNET.CLI Version: 5.22.12.0 * **Target**: .NET Core 2.1 <img width="533" alt="Screen Shot 2019-05-23 at 4 30 29 PM" src="https://user-images.githubusercontent.com/47339880/58237624-26ae1080-7d78-11e9-92aa-cfce0b53a52f.png"> Steps to Reproduce: 1. Make a basic Electron.NET app. 2. Make a BrowserWindowOptions with WebPreferences.NodeIntegration = false 3. Pass said BrowserWindowOptions to Electron.WindowManager.CreateWindowAsync We need to set NodeIntegration to false because we are dependent on jQuery, Bootstrap, and Highcharts. <img width="382" alt="Screen Shot 2019-05-23 at 4 42 07 PM" src="https://user-images.githubusercontent.com/47339880/58238409-cd46e100-7d79-11e9-89a0-85b7dcae10df.png"> How can we fix this? Also, is there a workaround to make jQuery and Highcharts work in Electron.NET?
claunia added the bug label 2026-01-29 16:36:36 +00:00
Author
Owner

@GregorBiswanger commented on GitHub (May 23, 2019):

I don´t know, how do you reference the JavaScript files. Node integration refers to the windows. Is actually needed for IPC communication, or if you want JavaScript Libaries with the require command. I would not disable it.

@GregorBiswanger commented on GitHub (May 23, 2019): I don´t know, how do you reference the JavaScript files. Node integration refers to the windows. Is actually needed for IPC communication, or if you want JavaScript Libaries with the `require `command. I would not disable it.
Author
Owner

@rakista112 commented on GitHub (May 27, 2019):

I include them via script tags in Index.cshtml
<script src="/scripts/jquery-3.4.1.m.js"></script> <script src="/scripts/highcharts.js"></script> <script src="/scripts/es5-shim.min.js"></script> <script src="/scripts/es6-shim.min.js"></script> <script src="/scripts/ourproduct.min.js"></script>

Then we get an error here

Screen Shot 2019-05-27 at 11 43 25 AM

Why can't it find jQuery? We also get a similar error for highcharts.

@rakista112 commented on GitHub (May 27, 2019): I include them via script tags in Index.cshtml ` <script src="/scripts/jquery-3.4.1.m.js"></script> <script src="/scripts/highcharts.js"></script> <script src="/scripts/es5-shim.min.js"></script> <script src="/scripts/es6-shim.min.js"></script> <script src="/scripts/ourproduct.min.js"></script>` Then we get an error here <img width="950" alt="Screen Shot 2019-05-27 at 11 43 25 AM" src="https://user-images.githubusercontent.com/815354/58394283-07afc700-8075-11e9-92cb-c76a2d1d54ac.png"> Why can't it find jQuery? We also get a similar error for highcharts.
Author
Owner

@GregorBiswanger commented on GitHub (May 29, 2019):

Please open the Chrome Dev Tools and analyse the script loading errors:

Electron.WindowManager.BrowserWindows.First().WebContents.OpenDevTools()

I think that is only a path problem.

Alternative try to set a base href in the index.html:

<head>
  <meta charset="utf-8">
  <title></title>
  <base href="./">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
@GregorBiswanger commented on GitHub (May 29, 2019): Please open the Chrome Dev Tools and analyse the script loading errors: `Electron.WindowManager.BrowserWindows.First().WebContents.OpenDevTools()` I think that is only a path problem. Alternative try to set a **base href** in the **index.html**: ``` <head> <meta charset="utf-8"> <title></title> <base href="./"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="icon" type="image/x-icon" href="favicon.ico"> </head> ```
Author
Owner

@gfs commented on GitHub (Jun 1, 2019):

@rakista112 I noticed a similar issue getting jQuery to load. As dumb as it sounds, including it twice in the html fixed it.

@gfs commented on GitHub (Jun 1, 2019): @rakista112 I noticed a similar issue getting jQuery to load. As dumb as it sounds, including it twice in the html fixed it.
Author
Owner

@rakista112 commented on GitHub (Jun 3, 2019):

Hi I was able to import and use jQuery and Highcharts using the info in the Electron wiki.
I followed the instructions here. https://electronjs.org/docs/faq#i-can-not-use-jqueryrequirejsmeteorangularjs-in-electron

I actually tried the wiki solution a couple of times before posting this thread. I only thought the solution wasn't working because the previous client build/javascript was getting stuck.
I had to delete the obj/ directory in the project directory.

It's really cumbersome but I have to do it every time I make a new build because I'm afraid I might be running outdated code.

@rakista112 commented on GitHub (Jun 3, 2019): Hi I was able to import and use jQuery and Highcharts using the info in the Electron wiki. I followed the instructions here. https://electronjs.org/docs/faq#i-can-not-use-jqueryrequirejsmeteorangularjs-in-electron I actually tried the wiki solution a couple of times before posting this thread. I only thought the solution wasn't working because the previous client build/javascript was getting stuck. I had to delete the `obj/ `directory in the project directory. It's really cumbersome but I have to do it every time I make a new build because I'm afraid I might be running outdated code.
Author
Owner

@GregorBiswanger commented on GitHub (May 9, 2020):

Can be deactivated. However, IPC can then no longer be used.

WebPreferences wp = new WebPreferences();
wp.NodeIntegration = false;
BrowserWindowOptions browserWindowOptions = new BrowserWindowOptions
{
    WebPreferences = wp
}
@GregorBiswanger commented on GitHub (May 9, 2020): Can be deactivated. However, IPC can then no longer be used. ``` WebPreferences wp = new WebPreferences(); wp.NodeIntegration = false; BrowserWindowOptions browserWindowOptions = new BrowserWindowOptions { WebPreferences = wp } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#330