0

Trying to get my head around getting a dialog.showMessageBox() in the render process using preload. I'm trying const {dialog} = require( 'electron') but it's returning undefined. What am I missing?

main.js:

    const consoleWindow = new BrowserWindow({
        title: 'TakServer | Console',
        width: DEBUG ? 1000 : 800,
        height: 600,
        resizable: true,
        alwaysOnTop: true,
        show: false,
        webPreferences: {
            nodeIntegration: false, 
            contextIsolation: true, n
            enableRemoteModule: false, 
            preload: path.join(__dirname, "preload.js") 
        }
    })

preload.js:


const { contextBridge, dialog } = require("electron");

console.log( "dialog", dialog ) // !!  undefined

contextBridge.exposeInMainWorld( 'api',
    {
        test: ( x ) => {
            const {fs} = require( 'fs' )

            console.log( "gubbmins", fs  )
            dialog.showMessageBox( { 
                type: "info", 
                message: "stuff" 
            })  
        }
    }
)
Kim Aldis
  • 583
  • 1
  • 4
  • 15
  • the dialog module isn't available in the Renderer. This is kind of a dupe of [this](https://stackoverflow.com/questions/36637201/requiring-electron-dialog-from-render-process-is-undefined) except the answers won't help you much since the `remote` module has been removed. You'll need to use ipc to tell the main process about this. I'll try to find a dupe since I'm sure there is one and if not, will post an answer – pushkin Jan 20 '22 at 15:44
  • posted answer [here](https://stackoverflow.com/a/70789270/3479456) – pushkin Jan 20 '22 at 15:49
  • Does this answer your question? [Requiring electron dialog from render process is undefined](https://stackoverflow.com/questions/36637201/requiring-electron-dialog-from-render-process-is-undefined) – pushkin Jan 20 '22 at 15:50
  • Yes, perfect thanks – Kim Aldis Jan 20 '22 at 20:55

0 Answers0