3

I'm trying to understand how context isolation works in electron. I want to expose the dialog.showErrorBox function from the electron module to the renderer process. As i understand the following code in preload.js should be sufficient:

import {contextBridge, dialog} from 'electron'

contextBridge.exposeInMainWorld(
  'electron',
  {
      showErrorDialog: dialog.showErrorBox
  }

Then in the renderer process I should be able to call this function as

window.electron.showErrorDialog(string, string)

However when importing electron in preload.js it appears as if it has no property dialog so that the import statement above returns dialog = undefined.

I have a feeling this has more to do with which properties the electron module exposes in the preload.js more than context isolation. It looks to me like there are several APIs which could be useful to expose to the renderer but are unavailable in preload.js (e.g. dialog, inAppPurchase) how is one supposed to use these?

This is basically a duplicate of Requiring electron dialog from render process is undefined however the answers to that question are outdated as they use the remote API which is no longer part of electron.

MGiac
  • 31
  • 1

0 Answers0