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,会降低应用的安全性。务必谨慎使用,并确保你信任加载的所有代码和资源。

相关推荐
时光足迹41 分钟前
Tiptap之标注组件
前端·javascript·react.js
时光足迹1 小时前
Tiptap 之自定义脚注组件
前端·javascript·react.js
时光足迹1 小时前
Tiptap之造字组件
前端·javascript·react.js
小四的小六1 小时前
WebView 兼容性踩坑实录:那些让我加班的坑
javascript·webview
jump_jump1 小时前
用官方模板理解 Decky 插件:一次从模板到架构的速览
javascript·python·游戏
张元清1 小时前
React 表单处理:防抖校验、自动保存草稿与受控输入
前端·javascript·面试
Hilaku1 小时前
给技术团队定规范,为什么 90% 最后都变成了走形式?
前端·javascript·程序员
昼猫1 小时前
前端打印分页技术探讨与 PrintomJs 方案
javascript·浏览器
gCode Teacher 格码致知1 小时前
Javascript提高:点击飘忽不定的气球,气球爆炸并增加分数-由Deepseek产生
javascript·css·css3
费曼学习法1 小时前
React Hooks 闭包陷阱:为什么 useState 拿不到最新值?
javascript·react.js