跳到主要内容

webPreferences

webPreferences 是创建 BrowserWindow 或 WebContentsView 时的网页配置。它决定这份网页有没有 Node、预加载脚本是哪一个、使用哪份 session。

文档位于 BrowserWindow 的选项说明中。

最常出现的字段​

字段默认倾向含义
preload无预加载脚本的绝对路径
nodeIntegrationfalse页面能否直接使用 Node
contextIsolationtrue(自 Electron 12)预加载脚本与页面是否分属不同 JS 世界
sandboxtrue(自 Electron 20)渲染进程是否进入操作系统沙箱
webSecuritytrue是否启用同源策略等网页安全检查
partition默认 session选择存储和网络分区
webviewTagfalse是否允许页面使用 <webview>
devToolstrue是否允许打开开发者工具
backgroundThrottlingtrue窗口被挡住时是否降低定时器和动画频率

nodeIntegration: true 会关闭沙箱。关闭 contextIsolation 也会关闭沙箱。

相关文档​