简体   繁体   English

electron preload.js 文件中的 contextBridge 数量

[英]Number of contextBridge in electron preload.js file

To provide suitable levels of security when loading remote content, it is stated that a BrowserWindow 's contextIsolation and nodeIntegration options must be enabled and disabled respectively.为了在加载远程内容时提供适当的安全级别,必须分别启用和禁用BrowserWindowcontextIsolationnodeIntegration选项。 In this scenario, Node/Electron APIs will not be available to the main renderer process.在这种情况下,Node/Electron API 将不可用于主渲染器进程。 In order to expose specific functionality, the window's preload script may exploit Electron's contextBridge feature, providing the main renderer with access to selected Node/Electron APIs.为了公开特定功能,窗口的预加载脚本可能会利用 Electron 的contextBridge功能,为主渲染器提供对选定节点/电子 API 的访问。

Here is the single contextBridge usage example I've managed to find online but it only contains one contextBridge .是我设法在网上找到的单个 contextBridge 用法示例,但它只包含一个contextBridge

I understand how to use contextBridge my question is, Is there a limit to how many contextBridge si can use in one preload.js file and if I can use multiple contextBridges then what do you suggest I should use a template folder structure to import them into one preload.js我了解如何使用contextBridge我的问题是,在一个preload.js文件中可以使用多少contextBridge si 是否有限制,如果我可以使用多个 contextBridges 那么你建议我应该使用模板文件夹结构将它们导入一个preload.js

You can create multiple contextBridge s.您可以创建多个contextBridge As for the folder structure, that's really up to you and depends on the nature of the project (like whether you're sharing some APIs between different preloads).至于文件夹结构,这完全取决于您,并且取决于项目的性质(例如您是否在不同的预加载之间共享一些 API)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ContextBridge 在 preload.js 中仍未定义,给出错误:无法在打包的 Electron 应用程序中读取未定义的属性“exposeInMainWorld”? - ContextBridge remains undefined in preload.js giving error: Cannot read property 'exposeInMainWorld' of undefined in packaged Electron app? 如何在 Electron 中正确使用 preload.js - How to use preload.js properly in Electron 在 electron.js 中执行“preload.js”时出错 - Getting an error while executing 'preload.js' in electron.js Electron - preload.js 未加载并且在 Windows 10 上发生错误 - Electron - preload.js is not loaded and error is occurred on Windows 10 Electron preload.js 无法正常运行 - Electron preload.js doesn't function the way it is suppose to 如何在 windows 上使用 electron 在 preload.js 中访问 window 的本机 hwnd? - How to access native hwnd of window with electron on windows in preload.js? 如何将 preload.js 脚本添加到 expo-electron 应用程序? - How to add a preload.js script to expo-electron app? Electron 中的 nodeIntegration vs preload.js vs IPC - nodeIntegration vs preload.js vs IPC in Electron Electron:无法加载预加载脚本:Resources/app.asar/src/preload.js - Electron: Unable to load preload script: Resources/app.asar/src/preload.js 阻止Adobe Edge preload.js文件加载jquery - prevent Adobe Edge preload.js file from loading jquery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM