Onscreen Rendering as well as Offscreen Rendering of electron window

612 views Asked by At

I liked the Offscreen Rendering feature of electron app. I can render window content to image so easily with this feature.

const { app, BrowserWindow } = require('electron')
const fs = require('fs')

app.disableHardwareAcceleration()

let win

app.whenReady().then(() => {
  win = new BrowserWindow({ webPreferences: { offscreen: true } })

  win.loadURL('https://github.com')
  win.webContents.on('paint', (event, dirty, image) => {
    fs.writeFileSync('my_image.png', image.toPNG())
  })
  win.webContents.setFrameRate(60)
})

By default offscreen is false so content renders on the screen.

How can I see content of window on screen as well as off screen(image my_image.png) in such a way that when I perform some action on window(Onscreen) that should reflect on my_image.png(Offscreen) also?

0

There are 0 answers