Electron获取nodejs和chrome版本信息

Electron获取nodejs和chrome版本信息

环境:

复制代码
electron: 30.1.1
nodejs: 20.14.0

代码

复制代码
$ tree
.
+--- index.html
+--- index.js
+--- package.json

index.html

复制代码
<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8" />
  <title>Hello Electron</title>
  <meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline';">
</head>

<body>
  <p id="version"></p>

  <script>
    let info =
      `electron: ${process.versions.electron}, nodejs: ${process.versions.node}, chrome: ${process.versions.chrome}, v8: ${process.versions.v8}`;
    document.getElementById("version").innerHTML = info;
    console.log(info);
  </script>
</body>

</html>

index.js

复制代码
const { app, BrowserWindow } = require('electron/main');
// app.commandLine.appendSwitch('remote-debugging-port', '9222');

const createWindow = () => {
  const win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false
    }
  })

  win.loadFile('index.html');
}

app.whenReady().then(() => {
    createWindow();
})

package.json

复制代码
{
  "name": "my-electron-app",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "electron ."
  }
}

结果

复制代码
electron: 30.1.1, nodejs: 20.14.0, chrome: 124.0.6367.243, v8: 12.4.254.20-electron.0

禁用 contextIsolation 和启用 nodeIntegration,会降低应用的安全性。务必谨慎使用,并确保你信任加载的所有代码和资源。

相关推荐
Hilaku2 分钟前
用“人话”讲明白10个最常用的正则表达式
前端·javascript·正则表达式
LL.。14 分钟前
同步回调和异步回调
开发语言·前端·javascript
伊成28 分钟前
Mac中如何Chrome禁用更新[update chflags macos]
chrome·mac
Mintopia39 分钟前
B 样条曲线:计算机图形学里的 “曲线魔术师”
前端·javascript·计算机图形学
Mintopia44 分钟前
Three.js 3D 世界中的噪声运动:当数学与像素共舞
前端·javascript·three.js
来碗疙瘩汤1 小时前
使用 Three.js 与 CSS3DRenderer 在 Vue3 中加载网页为 3D 模型
前端·javascript
打野赵怀真1 小时前
在TypeScript中装饰器有哪些应用场景?
前端·javascript
destinying1 小时前
vite学习笔记
前端·javascript
LRH1 小时前
JS基础 - 手写数组扁平化函数
前端·javascript
FogLetter1 小时前
从零到一实现流式输出:SSE技术在前端应用中的魔法时刻
前端·javascript