Skip to content

Instantly share code, notes, and snippets.

@Imperat

Imperat/main.js Secret

Last active March 7, 2023 00:45
Show Gist options
  • Save Imperat/ad54907ca6e8d1167c5bde6a6bf389ac to your computer and use it in GitHub Desktop.
Save Imperat/ad54907ca6e8d1167c5bde6a6bf389ac to your computer and use it in GitHub Desktop.
addBrowserView glitch
// Modules to control application life and create native browser window
const {app, BrowserWindow, BrowserView} = require('electron')
app.whenReady().then(async () => {
const win = new BrowserWindow({
width: 800,
height: 600,
backgroundColor: 'black'
})
const view1 = new BrowserView()
view1.setBackgroundColor('white');
win.addBrowserView(view1);
view1.setBounds({ x: 0, y: 0, width: 800, height: 600 })
await view1.webContents.loadURL('https://electronjs.org')
const view2 = new BrowserView();
view2.setBackgroundColor('white');
win.addBrowserView(view2);
view2.setBounds({ x: 0, y: 0, width: 800, height: 600 })
await view2.webContents.loadURL('https://www.electronjs.org/apps');
setInterval(() => {
win.removeBrowserView(view2);
setTimeout(() => {
win.addBrowserView(view2);
}, 1000);
}, 3000);
})
{
"name": "upbeat-structure-plan-e743d",
"productName": "upbeat-structure-plan-e743d",
"description": "My Electron application description",
"keywords": [],
"main": "./main.js",
"version": "1.0.0",
"author": "leliakin",
"scripts": {
"start": "electron ."
},
"dependencies": {},
"devDependencies": {
"electron": "20.1.4"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment