diff --git a/docs/tutorial/tutorial-3-preload.md b/docs/tutorial/tutorial-3-preload.md index 97c45780e354..2074d3c5152c 100644 --- a/docs/tutorial/tutorial-3-preload.md +++ b/docs/tutorial/tutorial-3-preload.md @@ -202,7 +202,7 @@ Then, set up your `handle` listener in the main process. We do this _before_ loading the HTML file so that the handler is guaranteed to be ready before you send out the `invoke` call from the renderer. -```js {1,12} title="main.js" +```js {1,15} title="main.js" const { app, BrowserWindow, ipcMain } = require('electron') const path = require('path') @@ -214,10 +214,12 @@ const createWindow = () => { preload: path.join(__dirname, 'preload.js'), }, }) - ipcMain.handle('ping', () => 'pong') win.loadFile('index.html') } -app.whenReady().then(createWindow) +app.whenReady().then(() => { + ipcMain.handle('ping', () => 'pong') + createWindow() +}) ``` Once you have the sender and receiver set up, you can now send messages from the renderer