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

相关推荐
Mr.Jessy1 小时前
JavaScript高级:构造函数与原型
开发语言·前端·javascript·学习·ecmascript
爱上妖精的尾巴4 小时前
6-4 WPS JS宏 不重复随机取值应用
开发语言·前端·javascript
三七吃山漆5 小时前
攻防世界——wife_wife
前端·javascript·web安全·网络安全·ctf
用户47949283569155 小时前
面试官问"try-catch影响性能吗",我用数据打脸
前端·javascript·面试
GISer_Jing6 小时前
前端营销技术实战:数据+AI实战指南
前端·javascript·人工智能
嘉琪0016 小时前
Vue3+JS 高级前端面试题
开发语言·前端·javascript
vipbic7 小时前
用 Turborepo 打造 Strapi 插件开发的极速全栈体验
前端·javascript
天涯学馆7 小时前
为什么 JavaScript 可以单线程却能处理异步?
前端·javascript
asdfg12589638 小时前
JS中的闭包应用
开发语言·前端·javascript
kirk_wang8 小时前
Flutter 导航锁踩坑实录:从断言失败到类型转换异常
前端·javascript·flutter