0

Based on the Electron process model, I expected that a blocked main process would not cause unresponsiveness in a renderer process, unless that renderer process is somehow waiting on the main process.

What I actually see is that, when the main process is blocked (e.g. sleeping), the renderer process is completely unresponsive, even though there is no IPC or other obvious communication between these processes.

Here is my entire Electron application.

main.js:

const { execSync } = require("child_process");
const { app, BrowserWindow } = require("electron");

app.whenReady().then(() => {
  const mainWindow = new BrowserWindow({ width: 800, height: 600 });
  mainWindow.loadFile("index.html");
});

function blockMainThread() {
  execSync(`sleep 2`);
}

setInterval(blockMainThread, 4_000);

index.html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <style>h1:hover { background-color: red; }</style>
  </head>
  <body>
    <h1>Hello World!</h1>
  </body>
</html>

What I see is that, while the main process is not busy, hovering the h1 makes it turn red promptly, but while the main process is busy or sleeping, the entire window is unresponsive.

There is no IPC between these processes.

Is there some communication between the main process and renderer process that I'm not aware of? How can I make the renderer process remain responsive even when the main process is busy or sleeping?

1
  • This question is similar to: Does Electron's main thread block BrowserWindow?. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem.
    – Arkellys
    Commented Jul 24 at 5:49

0