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

相关推荐
星海拾遗7 小时前
react源码从入门到入定
前端·javascript·react.js
小满zs7 小时前
Next.js第二十五章(CSS方案)
开发语言·javascript·css
wuhen_n7 小时前
JavaScript事件循环(下) - requestAnimationFrame与Web Workers
开发语言·前端·javascript
铁蛋AI编程实战7 小时前
Gemini in Chrome 全实战:解锁+API调用+自定义扩展+本地推理
前端·人工智能·chrome
Hexene...7 小时前
【前端Vue】出现elementui的index.css引入报错如何解决?
前端·javascript·vue.js·elementui
红色的小鳄鱼7 小时前
Vue 监视属性 (watch) 超全解析:Vue2 Vue3
前端·javascript·css·vue.js·前端框架·html5
web小白成长日记7 小时前
Vue-实例从 createApp 到真实 DOM 的挂载全历程
前端·javascript·vue.js
hbstream海之滨视频网络技术8 小时前
Google正式上线Gemini In Chrome,国内环境怎样开启。
前端·chrome
微祎_8 小时前
Flutter for OpenHarmony:构建一个 Flutter 旋转迷宫游戏,深入解析网格建模、路径连通性检测与交互式解谜设计
javascript·flutter·游戏
红色的小鳄鱼8 小时前
Vue 教程 自定义指令 + 生命周期全解析
开发语言·前端·javascript·vue.js·前端框架·html