相关疑难解决方法(0)

未为 Electron 的入门应用程序定义流程

我正在尝试开始使用 Electron。我已经能够运行所有简单的示例。它们都按预期工作。当我尝试按照快速入门指南我遇到同样的问题,因为在提到这个问题:应用程序启动正常,但不显示节点Chrome和电子的版本。当我查看开发工具时,我看到了这个错误:

Uncaught ReferenceError: process is not defined
    at index.html:14
Run Code Online (Sandbox Code Playgroud)

但是,我已经设置nodeIntegrationtrue.

为什么它仍然不起作用?

版本:

  • npm 7.6.3
  • 节点 v14.16.0
  • 铬 89.0.4389.82

操作系统:

  • Ubuntu 20.04.2 LTS。

索引.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 …
Run Code Online (Sandbox Code Playgroud)

linux chromium node.js npm electron

5
推荐指数
1
解决办法
1505
查看次数

将环境变量值发送到 Electron 应用程序中的渲染器线程

我有一个电子应用程序。我需要从本地计算机获取环境变量的值以在渲染器线程上使用。我想在应用程序启动时将此值传递给渲染器线程。我知道在main.js文件中,我可以像这样获取环境变量:

main.js

const createWindow = () => {
    const win = new BrowserWindow({
        width: 800,
        height: 600
    });
  
    win.loadFile('index.html');

    // Retrieve the environment variable value
    const variableValue = process.env.MY_ENVIRONMENT_VARIABLE;
    console.log(`Variable value: ${variableValue}`);

    // Send the variable and it's value to the renderer.
    win.webContents.send('initialize', { 'variableName':variableValue });
}
Run Code Online (Sandbox Code Playgroud)

上面成功地将环境变量的值打印到终端窗口。但是,我需要在浏览器端使用这个值。我如何在那里获取变量的值?

谢谢你!

javascript electron

4
推荐指数
1
解决办法
4493
查看次数

标签 统计

electron ×2

chromium ×1

javascript ×1

linux ×1

node.js ×1

npm ×1