csepulv / electron-with-create-react-app

Sample Electron application using create-react-app
MIT License
831 stars 217 forks source link

BrowserWindow#loadUrl niside of electron.screen "display-added" callback causes infinite recursion #23

Closed Willerie closed 6 years ago

Willerie commented 6 years ago

This is the minimal code I've found that produces the problem, placed in electron-starter.js:

const electron = require("electron");
const { app, BrowserWindow } = electron;
app.on("ready", () => {
  let window = new BrowserWindow();
  electron.screen.on("display-added", () => {
    window.loadURL("https://www.github.com/");
  });
});

If you have multiple displays, you can reproduce this issue by either plugging in a display, or using Win+P to switch between single screen and extend modes. For some reason, doing this with the above code will cause the "display-added" event to trigger indefinitely.

It doesn't matter if the window is created inside or outside of the callback, nor does it matter what URL (including file paths) is being loaded. I also found by accident that calling a nonexistent method on the window (such as window.asdf()) results in the same problem. Of the few other BrowserWindow methods I've tried, no others caused the same issue.

Any idea what might be going on here? Thanks in advance for your help!