Capture URL to JPEG render a black image


#1

Hello,

I have a problem using electron, it renders a black screen when I tried to capture a full js website.

Here is a simple script to reproduce:

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

app.on('ready', () => {
  const b = new BrowserWindow({
    show: false,
    width: 1366,
    height: 768
  })

  b.webContents.on('did-finish-load', () => {
    setTimeout(() => {
      b.webContents.capturePage(image => {
        const buf = image.toJPEG(100)
        writeFile('test.jpeg', buf, err => {
          if (err) {
            console.log('Error during process:', err)
            return
          }
          console.log('Capture saved to: test.jpeg')
          app.quit()
        })
      })
    }, 5000)
  })

  b.loadURL('http://elm-lang.org/')
})

Maybe I’m doing something wrong but I don’t see why.

Thanks for your help.


#2

I just tested your script in my app and it worked just fine. What OS are you on?
I have Windows 10, latest Node/npm and Electron 1.6.11.