我正在使用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"
}
}
因此,如果任何人对可能的原因有任何想法,就像这样或者可以指出我试图解决这个问题的某些事情,请告诉我。
操作系统 - Windows Server 2008 R2(使用与Windows 7相同的内核)(电子中的其他所有内容似乎都正常工作,所以我怀疑它是操作系统。
似乎在沙盒中使用标记的能力在3.0.0 beta 3发布之前不起作用。尽管如我在上一篇文章中所述,在3.0.0 beta 3发布之前,似乎已经有超过一年的合并更改。也许这在某种程度上与semantic versioning有关,所以他们不得不等到下一个主要版本才能增加对它的支持。