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

相关推荐
早點睡39012 小时前
ReactNative项目OpenHarmony三方库集成实战:react-native-image-gallery
javascript·react native·react.js
清汤饺子12 小时前
Cursor 从 0 到 1 系列《基础篇》:从零上手 Cursor
前端·javascript·后端
时寒的笔记12 小时前
逆向入门1整理2025.3.18
javascript·python
执行部之龙12 小时前
js手写——防抖
开发语言·前端·javascript
DEMO派12 小时前
JavaScript数据存储三剑客:Object、Map与WeakMap完全指南
开发语言·前端·javascript
阿杜杜不是阿木木13 小时前
从0到1构建像Claude Code那样的Agent(二):工具
前端·chrome·agent·ai编程·cluade code
x-cmd13 小时前
[x-cmd] Chrome DevTools MCP 更新:支持 coding agent 直接接管当前的浏览器窗口
前端·chrome·ai·agent·chrome devtools·x-cmd·mcp
芭拉拉小魔仙13 小时前
Vue v-html 中事件绑定失效问题及解决方案
javascript·vue.js·html
_果果然13 小时前
除了防抖和节流,还有哪些 JS 性能优化手段?
javascript·vue.js·性能优化
console.log('npc')13 小时前
git代码冲突reset,如何回退到冲突之前提交之前的版本
javascript·git·react.js