Created
May 3, 2022 14:18
-
-
Save gtalusan/c0ad56685aeb3b2c1108fbccf6b451b4 to your computer and use it in GitHub Desktop.
electron offscreen render fiddle
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> | |
<body> | |
<select id="cars"> | |
<option value="vw">vw</option> | |
<option value="tesla">tesla</option> | |
<option value="gm">gm</option> | |
<option value="saab">saab</option> | |
<option value="fiat">fiat</option> | |
</select> | |
</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') | |
const fs = require('fs') | |
function createWindow() { | |
const mainWindow = new BrowserWindow({ | |
width: 758, | |
height: 1024, | |
webPreferences: { | |
offscreen: true, | |
preload: path.join(__dirname, 'preload.js') | |
} | |
}) | |
mainWindow.on('ready-to-show', () => { | |
mainWindow.webContents.sendInputEvent({ type: 'mouseDown', x: 10, y: 10, button: 'left', clickCount: 1 }) | |
mainWindow.webContents.sendInputEvent({ type: 'mouseUp', x: 10, y: 10, button: 'left', clickCount: 1 }) | |
}) | |
var i = 0; | |
mainWindow.webContents.on('paint', (event, dirty, image) => { | |
fs.writeFileSync(`${i}.png`, image.toPNG()) | |
++i | |
}) | |
mainWindow.loadFile('index.html') | |
mainWindow.focusOnWebView() | |
} | |
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": "homely-price-kill-gzo0z", | |
"productName": "homely-price-kill-gzo0z", | |
"description": "My Electron application description", | |
"keywords": [], | |
"main": "./main.js", | |
"version": "1.0.0", | |
"author": "george", | |
"scripts": { | |
"start": "electron ." | |
}, | |
"dependencies": {}, | |
"devDependencies": { | |
"electron": "18.0.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment