Created
October 30, 2019 18:11
-
-
Save CharlieHess/effdbc40530e2ccc3130e99db9075c04 to your computer and use it in GitHub Desktop.
web-contents-created fired too early?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {app, BrowserWindow, webContents: WebContents} = require('electron') | |
const assert = require('assert') | |
let mainWindow | |
function createWindow () { | |
mainWindow = new BrowserWindow({ | |
width: 800, | |
height: 600, | |
webPreferences: { | |
nodeIntegration: true | |
} | |
}) | |
mainWindow.loadFile('index.html') | |
mainWindow.on('closed', function () { | |
mainWindow = null | |
}) | |
} | |
app.on('web-contents-created', (e, webContents) => { | |
const theId = webContents.id | |
const existingWebContents = WebContents.fromId(theId) | |
assert(!!existingWebContents, 'webContents missing?!') | |
}) | |
app.on('ready', createWindow) | |
app.on('window-all-closed', function () { | |
app.quit() | |
}) | |
app.on('activate', function () { | |
if (mainWindow === null) { | |
createWindow() | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment