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

相关推荐
还是鼠鼠1 小时前
图书管理系统 Axios 源码__编辑图书
前端·javascript·vscode·ajax·前端框架
北极象1 小时前
vue3中el-input无法获得焦点的问题
前端·javascript·vue.js
GISer_Jing2 小时前
react redux监测值的变化
前端·javascript·react.js
m0_528723812 小时前
react中useEffect的使用
前端·javascript·react.js
Real_man3 小时前
noVNC 技术解析与最佳实践
javascript
大模型铲屎官3 小时前
HTML从入门到精通:链接与图像标签全解析
开发语言·前端·javascript·html·编程·链接标签·图像标签
大模型铲屎官3 小时前
HTML 列表标签全解析:无序与有序列表的深度应用
前端·javascript·html·有序列表·列表标签·无序列表
霸王蟹5 小时前
文本复制兼容方案最佳实现落地。
前端·javascript·vue.js·笔记·学习
扎量丙不要犟6 小时前
跨平台的客户端gui到底是选“原生”还是web
前端·javascript·c++·qt·rust·electron·tauri
hunter2062066 小时前
如何监控ubuntu系统某个程序的运行状态,如果程序出现异常,对其自动重启。
linux·chrome·ubuntu