gpt4 book ai didi

electron - 当Electron的沙箱设置为true时,Webview无法呈现

转载 作者:行者123 更新时间:2023-12-03 12:26:22 24 4
gpt4 key购买 nike

我正在使用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相同的内核)( Electron 中的所有其他功能似乎都可以正常工作,因此我怀疑它是操作系统)。

最佳答案

直到3.0.0 beta 3版本发布,似乎无法在沙箱中使用标记。即使像我以前的文章一样,在3.0.0 beta 3发布之前的一年里似乎有合并的更改。也许这在某种程度上与semantic versioning有关,所以他们不得不等到下一个主要版本来添加对它的支持。

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

关于electron - 当Electron的沙箱设置为true时,Webview无法呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52337509/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com