Skip to content

Instantly share code, notes, and snippets.

@gtalusan
Last active May 21, 2022 13:55
Show Gist options
  • Save gtalusan/06852ae37ed4700aa6612de0c1af80d8 to your computer and use it in GitHub Desktop.
Save gtalusan/06852ae37ed4700aa6612de0c1af80d8 to your computer and use it in GitHub Desktop.
electron offscreen popup
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'">
<link href="./styles.css" rel="stylesheet">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
<script src="./renderer.js"></script>
</body>
</html>
const {app, BrowserWindow} = require('electron')
const path = require('path')
function createWindow () {
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
offscreen: true,
}
})
mainWindow.webContents.setWindowOpenHandler(() => {
return { action: 'allow',
overrideBrowserWindowOptions: {
webPreferences: {
offscreen: true,
preload: path.join(__dirname, "preload.js")
}
}
}
})
mainWindow.loadFile('index.html')
mainWindow.webContents.on('did-create-window', (win, details) => {
console.log(details)
win.webContents.on('paint', (e, dirty, image) => {
console.log(`popup offscreen paint ${JSON.stringify(dirty)}`)
})
})
mainWindow.webContents.on('paint', (e, dirty, image) => {
console.log(`mainwindow offscreen paint ${JSON.stringify(dirty)}`)
})
}
app.whenReady().then(() => {
createWindow()
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
{
"name": "workable-receipt-dream-934wl",
"productName": "workable-receipt-dream-934wl",
"description": "My Electron application description",
"keywords": [],
"main": "./main.js",
"version": "1.0.0",
"author": "george",
"scripts": {
"start": "electron ."
},
"dependencies": {},
"devDependencies": {
"electron": "18.0.3"
}
}
setTimeout(()=> {
alert('hello from popup')
}, 5000)
var pop = window.open('https://www.google.ca','MyWindow','width=300,height=300')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment