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

相关推荐
弓.长.20 小时前
React Native 鸿蒙跨平台开发:实现一个多功能单位转换器
javascript·react native·react.js
摘星编程20 小时前
React Native for OpenHarmony 实战:ToggleSwitch 切换开关详解
javascript·react native·react.js
满栀58520 小时前
分页插件制作
开发语言·前端·javascript·jquery
qq_4061761420 小时前
深入剖析JavaScript原型与原型链:从底层机制到实战应用
开发语言·前端·javascript·原型模式
弓.长.21 小时前
React Native 鸿蒙跨平台开发:BottomSheet 底部面板详解
javascript·react native·react.js
摘星编程21 小时前
React Native for OpenHarmony 实战:Permissions 权限管理详解
javascript·react native·react.js
闲蛋小超人笑嘻嘻1 天前
Vue 插槽:从基础到进阶
前端·javascript·vue.js
摘星编程1 天前
React Native for OpenHarmony 实战:SearchBar 搜索栏详解
javascript·react native·react.js
tiandyoin1 天前
给 MHTML 添加滚动条.mhtml
前端·chrome·html·mhtml
ayuday1 天前
Svelte - 现代高性能Web开发框架!轻量级‌、响应式、编译时优化‌特点
nodejs·svelte