electron icon indicating copy to clipboard operation
electron copied to clipboard

Multiple browser windows

Open richardmward opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe. This is more a general request for advise than a feature request. An app I am looking to build requires the ability to use multiple BrowserWindows - a main "launcher" which can be used to open further windows. Ultimately the "child" windows will just be showing other URLs inside the same (vuejs) app.

Describe the solution you'd like A recommended approach to integrating this so that I can make use of CapacitorJS in all the main and child BrowserWindows.

Describe alternatives you've considered Whilst I could build window management into the app itself, for my usecase I'd prefer to be able to use the OSs window management.

Additional context As mentioned before, I'm not necessarily after this as a feature to be added (albeit that would be perfect), I'd be happy with some recommendations around how I could go about doing this as it's probably not a feature a lot of others are after.

richardmward avatar Jan 18 '22 15:01 richardmward

This maybe should be part of the default template, but you could fix it by adding the following to electron/src/index.ts.

const preloadPath = join(app.getAppPath(), 'build', 'src', 'preload.js');

app.on('web-contents-created', (_, contents) => {
  contents.setWindowOpenHandler(() => {
    // This is not secure!
    return { action: 'allow', overrideBrowserWindowOptions: { webPreferences: { preload: preloadPath } } };
  });
});

This doesn't work for the main BrowserWindow since this handler gets overwritten in electron/src/setup.ts. You could simply remove this code because you are handeling it yourself.

jdgjsag67251 avatar Jan 23 '22 16:01 jdgjsag67251