skip to Main Content
  • Electron 23.1.1
  • Chrome: 110.0.5481.104

I have an Electron Desktop app which reacts to certain events and opens up new Browser windows for each new event.

For performance reasons, we have added process-per-site so that new windows don’t have to create a new renderer process.

The apps loads two different urls in the Browser Windows:

  1. somedomain.xy.com – This is a Static Window
  2. localhost.xy.com:74125. – This is the url used to open new windows reacting to events.

As I can understand, the above 2 urls come under same site because of xy.com. This is leading to have one shared process for all the windows.

I wanted to have a separate process for the Static window and another process which houses all the windows reacting to events. This is to prevent any crash jeopradizing all the renderer windows.

I have tried

app.commandLine.appenSwitch('isolateOrigins', 'https://localhost.xy.com:74125')

and also

app.commandLine.appenSwitch('isolate-origins', 'https://localhost.xy.com:74125')

But, unable to see the process separation.

2

Answers


  1. I found that your issue is most likely related to your port 74125. It is not in spec of a valid port range.

    When you add a new manual site isolation entry in chrome://flags/#isolate-origins, you will notice that any entries with invalid URLs are stripped after taking effect. The same occurs when using flags.

    Try using a different port and make sure, as @djmonki mentioned, to add both URLs in a list to enforce separation on both sites. In the end you should see a separation in chrome://process-internals/#site-isolation

    Login or Signup to reply.
  2. To separate your Electron app’s windows into different renderer processes, even when they share the same registered domain, you can use the affinity option in the webPreferences of each BrowserWindow. This allows you to group windows into separate processes based on custom affinity strings, overriding the default behavior influenced by process-per-site.

    When creating your BrowserWindow instances, specify different affinity strings in the webPreferences option.

    // For the static window
    const staticWindow = new BrowserWindow({
      webPreferences: {
        affinity: 'staticWindowProcess',
        // other preferences
      },
      // other options
    });
    
    // For the event-driven windows
    const eventWindow = new BrowserWindow({
      webPreferences: {
        affinity: 'eventWindowsProcess',
        // other preferences
      },
      // other options
    });
    

    The affinity option forces Electron to group windows with the same affinity into the same renderer process, regardless of the domain or site isolation settings. By assigning different affinity strings, you ensure that the static window and event-driven windows run in separate renderer processes.

    Benefits:

    • Process Isolation: Crashes in one renderer process (the event-driven windows) won’t affect the other (the static window), enhancing the stability of your app.
    • Performance Optimization: You still benefit from shared processes for windows that should be grouped together, optimizing resource usage without compromising on process isolation.

    Note: Using affinity is compatible with the process-per-site policy but allows you to override it for specific cases where you need more granular control over process allocation.

    References

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search