Hen*_*rik 5 linux chromium node.js npm electron
我正在尝试开始使用 Electron。我已经能够运行所有简单的示例。它们都按预期工作。当我尝试按照快速入门指南我遇到同样的问题,因为在提到这个问题:应用程序启动正常,但不显示节点Chrome和电子的版本。当我查看开发工具时,我看到了这个错误:
Uncaught ReferenceError: process is not defined
at index.html:14
Run Code Online (Sandbox Code Playgroud)
但是,我已经设置nodeIntegration
为true
.
为什么它仍然不起作用?
版本:
操作系统:
索引.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
</head>
<body style="background: white;">
<h1>Hello World!</h1>
<p>
We are using node
<script>document.write(process.versions.node)</script>,
Chrome
<script>document.write(process.versions.chrome)</script>,
and Electron
<script>document.write(process.versions.electron)</script>.
</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
主文件
const { app, BrowserWindow } = require('electron')
function createWindow () {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
})
win.loadFile('index.html')
}
app.whenReady().then(createWindow)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
Run Code Online (Sandbox Code Playgroud)
包.json
{
"name": "my-electron-app",
"version": "0.1.0",
"author": "username",
"description": "My Electron app",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"devDependencies": {
"electron": "^12.0.0"
}
}
Run Code Online (Sandbox Code Playgroud)
小智 7
创建时尝试设置此值BrowserWindow
:
webPreferences: { nodeIntegration: true, contextIsolation: false }
Run Code Online (Sandbox Code Playgroud)
一个新的主要电子版本已经发布,破坏了教程。
具体的重大变化是contextIsolation
标志的新默认值。
有关更多详细信息,请参阅此 GitHub 问题。
归档时间: |
|
查看次数: |
1505 次 |
最近记录: |