Working example for BrowserView?

Hi , guys , im trying to get Browserview work following documentation example:


let win = new BrowserWindow({ width: 800, height: 600 })
win.on('closed', () => {
  win = null
})

let view = new BrowserView()
win.setBrowserView(view)
view.setBounds({ x: 0, y: 0, width: 300, height: 300 })
view.webContents.loadURL('https://electronjs.org')

But when execute im getting:

Error: Cannot create BrowserWindow before app is ready

Can you provide working example about BrowserView ?
Regards.
Leandro

You can try executing the above example code within the context of your app.on("ready") function. In addition to the possibility of solving your problem, this fix may give you a more descriptive error; and therein path forward

app.on(‘ready’, function() {
const win = new BrowserWindow ;
const view = new BrowserView() ;

win.setBrowserView(view)
view.setBounds({ x: 100, y: 100, width: 300, height: 300 })
view.webContents.loadURL(‘https://google.com’)
});