问题
I recently created an electron/angular app which runs the following inside main.ts
:
win.loadURL(url.format({
pathname: path.join(__dirname, 'dist/index.html'),
protocol: 'file:',
slashes: true
}));
When the electron app loads, the following shows
Somehow, the html is loading inside a <pre>
tag inside html.
I have checked __dirname/dist
and the folder contains all the correct files (i.e. index.html, main.js, etc). Has anyone seen something similar with electron before? If so, any clues as to what is happening?
回答1:
While not totally obvious, I fixed my issue - my win
object was throwing warnings since I am using service workers and therefore, did not load the html properly.
The solution: use the nodeIntegrationInWorker: true
property. Once that was added everything worked like magic.
// Create the browser window.
win = new BrowserWindow({
x: 0,
y: 0,
width: size.width,
height: size.height,
webPreferences: {
nodeIntegration: true,
nodeIntegrationInWorker: true
}
});
来源:https://stackoverflow.com/questions/55128495/electron-loading-html-inside-pre-tag