| 
									
										
										
										
											2020-06-22 20:32:45 -07:00
										 |  |  | const binding = process._linkedBinding('electron_renderer_context_bridge'); | 
					
						
							| 
									
										
										
										
											2019-10-18 12:57:09 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | const checkContextIsolationEnabled = () => { | 
					
						
							| 
									
										
										
										
											2021-11-08 17:57:56 +01:00
										 |  |  |   if (!process.contextIsolated) throw new Error('contextBridge API can only be used when contextIsolation is enabled'); | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2019-10-18 12:57:09 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-11 13:41:42 -07:00
										 |  |  | const contextBridge: Electron.ContextBridge = { | 
					
						
							| 
									
										
										
										
											2025-01-23 21:12:46 -05:00
										 |  |  |   exposeInMainWorld: (key, api) => { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |     checkContextIsolationEnabled(); | 
					
						
							| 
									
										
										
										
											2022-09-21 23:47:10 +05:30
										 |  |  |     return binding.exposeAPIInWorld(0, key, api); | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2025-01-23 21:12:46 -05:00
										 |  |  |   exposeInIsolatedWorld: (worldId, key, api) => { | 
					
						
							| 
									
										
										
										
											2022-09-21 23:47:10 +05:30
										 |  |  |     checkContextIsolationEnabled(); | 
					
						
							|  |  |  |     return binding.exposeAPIInWorld(worldId, key, api); | 
					
						
							| 
									
										
										
										
											2025-01-23 21:12:46 -05:00
										 |  |  |   }, | 
					
						
							|  |  |  |   executeInMainWorld: (script) => { | 
					
						
							|  |  |  |     checkContextIsolationEnabled(); | 
					
						
							|  |  |  |     return binding.executeInWorld(0, script); | 
					
						
							| 
									
										
										
										
											2020-05-15 11:57:40 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-01-29 21:41:59 +01:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2019-10-18 12:57:09 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | export default contextBridge; | 
					
						
							| 
									
										
										
										
											2020-04-22 12:42:51 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | export const internalContextBridge = { | 
					
						
							| 
									
										
										
										
											2021-11-08 17:57:56 +01:00
										 |  |  |   contextIsolationEnabled: process.contextIsolated, | 
					
						
							| 
									
										
										
										
											2020-04-27 12:46:04 -07:00
										 |  |  |   overrideGlobalValueFromIsolatedWorld: (keys: string[], value: any) => { | 
					
						
							|  |  |  |     return binding._overrideGlobalValueFromIsolatedWorld(keys, value, false); | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   overrideGlobalValueWithDynamicPropsFromIsolatedWorld: (keys: string[], value: any) => { | 
					
						
							|  |  |  |     return binding._overrideGlobalValueFromIsolatedWorld(keys, value, true); | 
					
						
							| 
									
										
										
										
											2020-04-22 12:42:51 -07:00
										 |  |  |   }, | 
					
						
							|  |  |  |   overrideGlobalPropertyFromIsolatedWorld: (keys: string[], getter: Function, setter?: Function) => { | 
					
						
							|  |  |  |     return binding._overrideGlobalPropertyFromIsolatedWorld(keys, getter, setter || null); | 
					
						
							| 
									
										
										
										
											2025-01-23 21:12:46 -05:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-04-22 12:42:51 -07:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-05-11 13:41:42 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-15 11:57:40 -07:00
										 |  |  | if (binding._isDebug) { | 
					
						
							| 
									
										
										
										
											2020-05-11 13:41:42 -07:00
										 |  |  |   contextBridge.internalContextBridge = internalContextBridge; | 
					
						
							|  |  |  | } |