当 Electron 的沙箱设置为 true 时,Webview 不呈现

Webview not rendering when Electron's sandbox is set to true

我正在使用 Electron 2.0.9 完成 Electron 快速入门,我只是想找到一种方法来在沙盒模式下将 webview 标签获取到 运行。

但是我似乎无法解决这个问题。我已经搜索了可能的解决方案,但我遇到的唯一问题是 here,如图所示,这个问题已关闭,一年前合并了一些东西。很明显那是在 2.0.9 中,我不会遇到这个问题。

index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Sandbox Test</title>
    <style>
      webview {
        width: 100%;
        height: 500px;
        border: solid 1px black;
      }

    </style>
  </head>
  <body>
    <input id="urlInput" type="url" value="https://www.google.com/" placeholder="Enter Url">
    <button onclick="setUrl();">Load Page</button> 
    <br>

    <div id="webviewDiv">
    </div>

    <script>
      // You can also require other files to run in this process
      // require('./renderer.js');

      function setUrl()
      {
        url = document.getElementById("urlInput").value;
        document.getElementById("webviewDiv").innerHTML = '<webview src="' + url + '"></webview>';
      }
    </script>
  </body>
</html>

main.js

// Modules to control application life and create native browser window
const {app, BrowserWindow} = require('electron')

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow

function createWindow () {
  // Create the browser window.
  mainWindow = new BrowserWindow({
    webPreferences: {
      sandbox: true
    },
    width: 800, 
    height: 600
  })

  // and load the index.html of the app.
  mainWindow.loadFile('index.html')

  // Open the DevTools.
  // mainWindow.webContents.openDevTools()

  // Emitted when the window is closed.
  mainWindow.on('closed', function () {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    mainWindow = null
  })
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)

// Quit when all windows are closed.
app.on('window-all-closed', function () {
  // On OS X it is common for applications and their menu bar
  // to stay active until the user quits explicitly with Cmd + Q
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

app.on('activate', function () {
  // On OS X it's common to re-create a window in the app when the
  // dock icon is clicked and there are no other windows open.
  if (mainWindow === null) {
    createWindow()
  }
})

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

package.json

{
  "name": "electron-quick-start",
  "version": "1.0.0",
  "description": "A minimal Electron application",
  "main": "main.js",
  "scripts": {
    "start": "electron . --enable-mixed-sandbox"
  },
  "repository": "https://github.com/electron/electron-quick-start",
  "keywords": [
    "Electron",
    "quick",
    "start",
    "tutorial",
    "demo"
  ],
  "author": "GitHub",
  "license": "CC0-1.0",
  "devDependencies": {
    "electron": "2.0.9"
  }
}

因此,如果有人对可能的原因有任何想法,或者可以指出我在尝试解决此问题时不知何故错过的事情,请告诉我。

OS - Windows Server 2008 R2(使用与 Windows 7 相同的内核)(电子中的其他一切似乎都正常工作所以我怀疑它是 OS.

似乎在 3.0.0 beta 3 发布之前,在沙箱中使用标签的功能才起作用。即使在我之前的 post 中,在 3.0.0 beta 3 发布之前的一年多时间里似乎已经进行了合并更改。也许这在某种程度上与 semantic versioning 有关,所以他们不得不等到下一个主要版本才添加对它的支持。

https://electronjs.org/releases#3.0.0-beta.3