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

相关推荐
2501_9481953437 分钟前
RN for OpenHarmony英雄联盟助手App实战:符文配置实现
javascript·react native·react.js
rocky1911 小时前
网页版时钟
前端·javascript·html
一只小阿乐2 小时前
vue-web端实现图片懒加载的方
前端·javascript·vue.js
2501_944521002 小时前
rn_for_openharmony商城项目app实战-商品评价实现
javascript·数据库·react native·react.js·ecmascript·harmonyos
程序猿的程3 小时前
我用 stock-sdk 构建了一个个人专属的 A 股行情仪表盘
javascript·web前端
这个图像胖嘟嘟3 小时前
前端开发的基本运行环境配置
开发语言·javascript·vue.js·react.js·typescript·npm·node.js
是小崔啊3 小时前
03-vue2
前端·javascript·vue.js
刘羡阳3 小时前
使用Web Worker的经历
前端·javascript
发现一只大呆瓜3 小时前
JS-类型转换:从显式“强制”到隐式“魔法”
javascript
!执行3 小时前
高德地图 JS API 在 Linux 系统的兼容性解决方案
linux·前端·javascript