#Sharing contextBridge functionality across preload scripts

1 messages · Page 1 of 1 (latest)

patent ivy
#

Hi all. Probably a simple question. I have two separate pre-load scripts, and both expose a common API. I.e.:

contextBridge.exposeInMainWorld('Prompts', {
    ShowMessageBox: options => ipcRenderer.invoke('dialog:showMessageBox', options),
});

What would be the way to share this across both scripts? I've tried simply require()ing a shared-preload.js file, but this throws me the error Cannot bind an API on top of an existing property on the window object. What am I missing here?

nocturne tulip
#

using require should work

#

what do you have in these preload files?

#

I think the error means you're not allowed to use the same apiKey

patent ivy
#

...I was being really dumb. Copying the code here I noticed I was requiring the wrong file (exporter-preload instead of shared-preload)

Sorry about that! Thanks for the reply