chore: clean up context bridge scopes and add specs for internal bridge (#23334)
* chore: clean up context bridge context scopes * spec: add specs for internalContextBridge
This commit is contained in:
parent
cf635c5fac
commit
7f9b7b2e95
4 changed files with 269 additions and 121 deletions
|
@ -7,13 +7,13 @@ const checkContextIsolationEnabled = () => {
|
|||
if (!contextIsolationEnabled) throw new Error('contextBridge API can only be used when contextIsolation is enabled');
|
||||
};
|
||||
|
||||
const contextBridge = {
|
||||
const contextBridge: Electron.ContextBridge = {
|
||||
exposeInMainWorld: (key: string, api: Record<string, any>) => {
|
||||
checkContextIsolationEnabled();
|
||||
return binding.exposeAPIInMainWorld(key, api);
|
||||
},
|
||||
debugGC: () => binding._debugGCMaps({})
|
||||
};
|
||||
} as any;
|
||||
|
||||
if (!binding._debugGCMaps) delete contextBridge.debugGC;
|
||||
|
||||
|
@ -32,3 +32,7 @@ export const internalContextBridge = {
|
|||
},
|
||||
isInMainWorld: () => binding._isCalledFromMainWorld() as boolean
|
||||
};
|
||||
|
||||
if (binding._debugGCMaps) {
|
||||
contextBridge.internalContextBridge = internalContextBridge;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue