首页 > 解决方案 > Windows Build 中 Electron 应用程序的 webContents.savePage 替代方案

问题描述

最近,我正在尝试为“Windows 和 Macintosh”构建 Electron 应用程序。

在 Macintosh 中,当我运行以下函数时:

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)
  })
})

当我在应用程序中加载“stackoverflow.html”文件时,它会运行下载页面以供离线使用,并将旧的 stackoverflow.html 内容替换为“它也可以” - “StackOverflow HTML”代码以及所有 CSS、JS 文件在stackoverflow_files目录中。

但是当我在“Windows Build”中运行相同的功能时 - 它只是不保存。我尝试通过在 中打印事件来调试问题console.log,它确实说 - “页面已下载并提供路径”,但是当我访问该页面时,它没有下载任何内容,并且始终显示原始内容“它有效”。

有没有其他方法,我们可以像“savePage”在 Macintosh for Windows 中的工作方式一样下载 webPage?

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

标签: javascriptelectronelectron-builderelectron-packager

解决方案


推荐阅读