Reputation: 31
I'm working on electron project that must have child window for the app. I set nodeIntegration: true
for main window and I want to apply that to the child window too, but for some reason I can't. I need to enabling nodeIntegration because I want use that on child window.
To create the child window I used window.open
function from electron and set nodeIntegration to true but the status is still false on child window.
Here is my code:
if(content === 'main'){
let mainSheet = './sheets/main_sheet.html';
//open in proxy window
let readerWin = window.open(mainSheet, '', `
maxWidth=2048,
maxHeight=2048,
width=1920,
height=1080,
fullscreenable=true,
contextIsolation=1,
nodeIntegration=true,
frame: false`)
}
This is the error on child window image
i want to make read and write file system in the child window. When i load another file to the main_sheet.html
the error above appeared.
this main_sheet.html file:
<!DOCTYPE html>
<html>
<head>
....
<script src="../fileSystem/filesystem.js"></script>
...
</head>
<body>
.....
</body>
</html>
and filesystem.js file:
const fs = require("fs");
let saveBTN = document.getElementById('save-data');
saveBTN.addEventListener('click', (e) => {
fs.writeFile("temp.txt", data, (err) => {
if (err) console.log(err);
console.log("Successfully Written to File.");
});
})
How to enable nodeIntegration on child window using window.open
function so i can using read and write in electron ?
Upvotes: 1
Views: 780
Reputation: 1759
The features string follows the format of standard browser, but each feature has to be a field of BrowserWindow's options.
Try, (Set contextIsolation to no)
`maxWidth=2048,
maxHeight=2048,
width=1920,
height=1080,
fullscreenable=yes,
contextIsolation=no,
nodeIntegration=yes,
frame=no`
Refer https://electronjs.org/docs/api/window-open
Refer https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Window_features
Upvotes: 2