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

相关推荐
easyboot几秒前
使用element-plus的暗黑模式
javascript·vue.js·elementui
低保和光头哪个先来9 分钟前
Axios 近期安全版本
开发语言·前端·javascript·前端框架
han_15 分钟前
JavaScript设计模式(八):命令模式实现与应用
前端·javascript·设计模式
Highcharts.js30 分钟前
React中频繁使用setState更新图表会影响性能
前端·javascript·react.js
zzginfo31 分钟前
JavaScript 假值示例详解
开发语言·前端·javascript·ecmascript
早點睡39035 分钟前
ReactNative项目OpenHarmony三方库集成实战:react-native-snackbar
javascript·react native·react.js
研來如此2 小时前
C++ 接口设计 && Doxygen 注释
前端·javascript·c++
野槐3 小时前
Electron开发
前端·javascript·electron
#做一个清醒的人3 小时前
【Electron】开发两年Electron项目评估报告
前端·electron
天真萌泪10 小时前
JS逆向自用
开发语言·javascript·ecmascript