Search code examples
menuelectronwindowframe

Electron.js | Remove new window frame


I'm using an index.html including an iframe. When a page is opened in a new tab with CTRL + Click keys, the properties I defined for BrowserWindow are not applied.

I want to remove the frame of the opened new tab. How can I do it?

const path = require('path')
const {app, BrowserWindow, Menu} = require('electron')

function createWindow() {
    const win = new BrowserWindow({
        width: 1000,
        height: 700,
        frame: false,
        show: false,
    })
    win.loadFile('index.html')
    win.once('ready-to-show', () => { win.show() });
}

const menu = Menu.buildFromTemplate([])
Menu.setApplicationMenu(menu)

app.whenReady().then(() => { createWindow() })

Solution

  • Windows opened via links don't inherit their parents options, instead, you have to register a window open handler and set the options manually:

    win.webContents.setWindowOpenHandler(({ url }) => {
      return {
        action: 'allow',
        overrideBrowserWindowOptions: { // These options will be applied to the new BrowserWindow
          frame: false,
          // other BrowserWindow settings
        }
      }
    }
    

    On the documentation: https://www.electronjs.org/docs/latest/api/window-open#native-window-example