Last active
May 21, 2022 13:55
-
-
Save gtalusan/06852ae37ed4700aa6612de0c1af80d8 to your computer and use it in GitHub Desktop.
electron offscreen popup
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
<!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> |
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} = 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() | |
}) |
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
{ | |
"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" | |
} | |
} |
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
setTimeout(()=> { | |
alert('hello from popup') | |
}, 5000) |
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
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