Number of contextBridge in electron preload.js file

Viewed 543

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. In this scenario, Node/Electron APIs will not be available to the main renderer process. 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.

Here is the single contextBridge usage example I've managed to find online but it only contains one contextBridge.

I understand how to use contextBridge my question is, Is there a limit to how many contextBridges i 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

1 Answers

You can create multiple contextBridges. 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).

Related