Skip to content

Instantly share code, notes, and snippets.

@gtalusan
Created May 3, 2022 14:18
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 gtalusan/c0ad56685aeb3b2c1108fbccf6b451b4 to your computer and use it in GitHub Desktop.
Save gtalusan/c0ad56685aeb3b2c1108fbccf6b451b4 to your computer and use it in GitHub Desktop.
electron offscreen render fiddle
<!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>
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()
})
{
"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