Skip to content

Instantly share code, notes, and snippets.

@CharlieHess
Created October 30, 2019 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CharlieHess/effdbc40530e2ccc3130e99db9075c04 to your computer and use it in GitHub Desktop.
Save CharlieHess/effdbc40530e2ccc3130e99db9075c04 to your computer and use it in GitHub Desktop.
web-contents-created fired too early?
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