Skip to content

Instantly share code, notes, and snippets.

@Hans-Halverson
Created May 7, 2024 23:45
Show Gist options
  • Save Hans-Halverson/8de9cbacec6253ec3d8de03723b7a914 to your computer and use it in GitHub Desktop.
Save Hans-Halverson/8de9cbacec6253ec3d8de03723b7a914 to your computer and use it in GitHub Desktop.
Electron addChildView crash
// Modules to control application life and create native browser window
const { app, BrowserWindow, WebContentsView } = require('electron')
const path = require('node:path')
function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow()
const view1 = new WebContentsView();
const view2 = new WebContentsView();
mainWindow.contentView.addChildView(view1);
mainWindow.contentView.addChildView(view1);
mainWindow.contentView.addChildView(view2);
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
createWindow()
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
{
"name": "lovely-wax-comb-2iug7",
"productName": "lovely-wax-comb-2iug7",
"description": "My Electron application description",
"keywords": [],
"main": "./main.js",
"version": "1.0.0",
"author": "hhalverson",
"scripts": {
"start": "electron ."
},
"dependencies": {},
"devDependencies": {
"electron": "30.0.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment