I am very new to node, javascript, and electron. I am just trying to write a simple app that opens a local HTML file in a browser window. The local file has some complex embedded javascript (tiddlywiki). Here is some sample code (I did not use local file in this one, but the result is the same):
const {app, BrowserWindow} = require('electron')
const path = require('path')
const url = require('url')
let win
function createWindow () {
// Create the browser window.
win = new BrowserWindow({width: 800, height: 600})
// and load the index.html of the app.
win.loadURL(url.format({
pathname: 'tiddlywiki.com',
protocol: 'http:',
slashes: true,
webPreferences: {
nodeIntegration: false,
}
}))
When the electron app launches I get the following error in the browser dev tools.
Uncaught TypeError: Cannot read property 'length' of undefined
at Object.$tw.boot.startup (tiddlywiki.com/:27506)
at tiddlywiki.com/:27765
at Object.$tw.boot.decryptEncryptedTiddlers (tiddlywiki.com/:27053)
at Object.$tw.boot.boot (tiddlywiki.com/:27763)
at _boot (tiddlywiki.com/:27772)
at tiddlywiki.com/:27782
I assume this is because of some integration of the node.js object model? Sorry for the lack of understanding. Thanks in advance for the help.
You put the webPreferences into the wrong place.
You have to put it in the initialization for the BrowserWindow and not in url.format:
win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: false
}
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With