4

Recently, I was trying to build Electron Apps for "Windows and Macintosh".

  • I had to download the current web page running using the "load URL" method in Browser Window.

In Macintosh, when I run below function:

const { BrowserWindow } = require('electron')
let win = new BrowserWindow()

win.loadURL('https://github.com')

win.webContents.on('did-finish-load', async () => {
  win.webContents.savePage('/tmp/test.html', 'HTMLComplete').then(() => {
    console.log('Page was saved successfully.')
  }).catch(err => {
    console.log(err)
  })
})

and When I load the "stackoverflow.html" file in the App, It runs the download page for offline use and replaces old stackoverflow.html content as "It works" too - "StackOverflow HTML" code as well as all CSS, JS file in stackoverflow_files directory.

But When I run the same function in "Windows Build" - It just doesn't save. I tried debugging the issue by printing the event in console.log, it does say - "Page has been downloaded and provides path", but when I access the page, it has not downloaded anything and Original content "It works" is always shown.

Is there any other way, we can download webPage just like how "savePage" works in Macintosh for Windows?

savePage API documentation - https://www.electronjs.org/docs/api/web-contents#contentssavepagefullpath-savetype

John Cargo
  • 1,839
  • 2
  • 29
  • 59

0 Answers0