【Electron】是否在 Electron 中运行
4月7日4月7日

简介

Electron 里,nodeIntegration 这个属性控制着渲染进程能否使用 Node.jsAPI。当 nodeIntegration 设置为 true 时,渲染进程会和 Node.js 环境集成,这意味着在渲染进程的全局 window 对象上会暴露 Node.js 的全局变量和 API,其中就包括 process 对象。所以,开启 nodeIntegration 之后,可以通过 window.process 访问到 Node.jsprocess 对象。

检测

1if (typeof process !== 'undefined' && typeof process.versions === 'object' && !!process.versions.electron) { 2 return true; 3}

cd ..
©2025All rights reserved by z0ffy.