Closed pilz97 closed 5 years ago
I have the same problem. Reproduction scenario:
@hjvanranden what was the issue? Sounds like you investigated already some time to get that up and running. Maybe something that could be contributed back to ngx-electron
The issue is that when using Angular in Electron (with ngx-electron), I cannot make an IPC call, because ipcRenderer == null (although electronSvc.isElectronApp returns true).
which version of ng
and electron
are you using
Angular CLI: 7.3.8 "electron": "^5.0.0",
Try setting nodeIntegration
to true
.
new BrowserWindow({ webPreferences: { nodeIntegration: true } });
That fixes the problem, thank you very much!!
Thank you fixes the problem for me too! :)
Fixed for me, would be good to have some documentation on it! thanks @bz-dev
So I have tried this with electron v12 - I need to do 3 things:
nodeIntegration: true, enableRemoteModule: true, contextIsolation: false
As a consequence I am able to access electronService.remote.fs etc etc.
however, when i set contextIsolations as false, it breaks my giving other errors in the angular code:
ReferenceError: $ is not defined
My jquery etc, which was normally preloaded earlier does not load any more. Why is this happening
@venomoustoad I am running into a similar issue with electron v12. The reason is that turning on nodeIntegration
causes an issue when running jQuery or angularJS: https://www.electronjs.org/docs/faq#i-can-not-use-jqueryrequirejsmeteorangularjs-in-electron
Using the delete window properties solution that is shown in the electron FAQ is not solving the issue with the icpRenderer. You basically have to choose between using jQuery and using icpRenderer. I am struggling with this when using a child window to open up an oauth webpage from a 3rd party website where they require jQuery.
Actually I just solved my issue! By using a conditional to check what page the preload script is running on, I was able to delete the node window properties but only on the child window. Keeping these properties on the parent window is required for icpRenderer to work in that context, but I do not need icpRenderer in the child window. Hope this helps!
I have actually the same problem, when i set the contextIsolation: false
it is working - but Electron throws a warning/error "Error: contextBridge API can only be used when contextIsolation is enabled"
When i set the contextIsolation
to true
the IPC calls are not working
@ThorstenHans
App.mainWindow = new BrowserWindow({
width: width,
height: height,
show: true,
icon: join(__dirname, '..', electronAppName, 'assets', 'icons', 'icon.png'),
webPreferences: {
contextIsolation: false,
nodeIntegration: true,
backgroundThrottling: false,
preload: join(__dirname, 'main.preload.js'),
},
});
Hi,
i packed my angular app to an .exe with electron-packager. Inside my app I want to use sendSync from the ipcRenderer, but then I get an error because the ipcRenderer is null although isElectronApp is true..
This is my code where the window is created:
` const { app, BrowserWindow } = require('electron'); const path = require('path'); const url = require('url');
let win;
const createWindow = () => { win = new BrowserWindow({ width: 800, height: 600, icon: path.join(__dirname, 'assets/test.png'), }); win.setKiosk(true);
win.loadURL(url.format({ pathname: path.join(__dirname, 'index.html'), protocol: 'file:', slashes: true }));
win.on('closed', () => { win = null; }); }
app.on('ready', createWindow);
app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit(); } });
app.on('activate', () => { if (win === null) { createWindow(); } }); `
What I am doing wrong?