【问题标题】:Electron 6.0.9 webview load any urls are blankElectron 6.0.9 webview加载任何网址都是空白的
【发布时间】:2024-01-02 12:27:01
【问题描述】:

我用的是电子官方样本“https://github.com/hokein/electron-sample-apps/tree/master/webview/browser

使用以下命令:

/home/roroco/.node/node_modules/bin/electron /home/roroco/Downloads/js/electron-sample-apps/webview/browser/main.js

电子窗口控制台没有任何错误

我尝试打开 webview devtools 但它没有打开

  const webview = document.querySelector('webview')
  webview.addEventListener('dom-ready', () => {
    webview.openDevTools()
  })

我猜是linux环境的问题,可能windows和mac都有这个bug,这是我的环境:

roroco@roroco ~/Downloads/js/electron-sample-apps $ lsb_release  -a
No LSB modules are available.
Distributor ID: LinuxMint
Description:    Linux Mint 19.1 Tessa
Release:    19.1
Codename:   tessa

【问题讨论】:

    标签: javascript electron


    【解决方案1】:

    我找到了解决办法,在 electron 中,webview 功能默认是禁用的,我应该手动启用它

    https://github.com/electron/electron/blob/master/docs/api/breaking-changes.md#new-browserwindow-webpreferences-

    使用以下代码:

    新的浏览器窗口({ 宽度:800,高度:600, webPreferences: {webviewTag: true} })

    【讨论】:

      最近更新 更多