javascript - Windows Build 中 Electron 应用程序的 webContents.savePage 替代方案
问题描述
最近,我正在尝试为“Windows 和 Macintosh”构建 Electron 应用程序。
- 我必须下载使用浏览器窗口中的“加载 URL”方法运行的当前网页。
在 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
解决方案
推荐阅读
- python-3.x - 字典列表 Python3
- postgresql - 错误:引用表的给定键没有唯一约束匹配。PG12
- python - Google Doomsday Fuel 未通过隐藏测试用例
- java - 在我的手机上找不到 apk 使用的本机库
- ocaml - Ocaml中的未绑定值列表?
- javascript - 更新 URL 栏中的锚链接
- node.js - nodejs ReferenceError:未定义要求
- java - 如何转换列表
- html - 在 flex 中对齐 div 以占据容器的整个宽度
- linux - Hosting Panel Pterodactyl 无法访问它的守护进程,连接到端口 8080 超时