Reputation: 531
When loading my main window by passing the HTML file directly through Electron, everything works as expected.
Electron app:
mainWindow.loadURL(
url.format({
pathname: path.join(__dirname, "mainWindow.html"),
protocol: "file:",
slashes: true
})
);
But when using Express and accessing the main window through localhost
, there is a big delay (white screen) at the first launch of the Electron app which lasts for about 30 seconds.
However, The page is accessible through localhost
in the browser as soon as the I run electron .
Express app:
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "mainWindow.html"));
});
app.listen(3000);
Electron app:
mainWindow.loadURL("http://localhost:3000");
I've tried this with multiple ports and they all give the same result.
Upvotes: 4
Views: 3707
Reputation: 24181
Browsers can sometimes try to be a bit more clever than they need too, proxy server's used to be common in the early days of the web. And in co-operate companies they are still popular. But in most case's proxy servers can be handled transparently by the OS, so why browsers still try to handle this I'm not 100% sure.
But the easy fix is to tell the embedded Chromium not to try a resolve the proxy server.
app.commandLine.appendSwitch('auto-detect', 'false');
app.commandLine.appendSwitch('no-proxy-server')
You may not need both the above switches.
Of course if you app is running on a system that does use a proxy, it might have issues. But I've a feeling even then it's unlikely to cause an isssue, as hopefully the OS would be handling this anyway.
Also this might be handy keeping an eye on -> https://github.com/electron/electron/issues/13829
Upvotes: 4