我正在使用Electron 2.0.9进行Electron快速入门,只是试图找到一种方法来使Webview标记在Sandbox模式下运行。
但是,我似乎无法解决此问题。我已经搜索了可能的解决方案,但遇到的唯一问题是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"
}
}
因此,如果有人对这种可能的原因有任何想法,或者可以指出我为解决此问题而以某种方式错过的事情,请告诉我们。
操作系统-Windows Server 2008 R2(使用与Windows 7相同的内核)(电子中的所有其他功能似乎都可以正常工作,因此我怀疑它是操作系统。
答案 0 :(得分:1)
似乎直到3.0.0 beta 3版本中,才可以在沙箱中使用标记。即使像我以前的文章一样,在3.0.0 beta 3发布之前的一年中似乎有合并的更改。也许这在某种程度上与semantic versioning有关,所以他们不得不等到下一个主要版本来添加对它的支持。