- 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:
- somedomain.xy.com – This is a Static Window
- 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
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
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.
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:
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