I can see the "Hello from renderer" alert, but not the "Goodbye from renderer" alert.
Running in Windows 10.
And I can't see the "received!" alert, which I should see it the ipcRenderer.on(...) worked.
index.js
const { app, BrowserWindow} = require("electron");
app.on('ready', () => {
let mainWindow = new BrowserWindow(
{
width: 800,
height: 600,
});
mainWindow.loadURL(`file://${__dirname}/index.html`);
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.webContents.send("from-main", "teste");
});
});
index.html
<html>
<head>
<title>test</title>
<script src="./renderer.js"> </script>
</head>
<body>
Wait...
</body>
</html>
renderer.js
alert('hello from renderer');
const { ipcRenderer } = require('electron');
ipcRenderer.on('from-main', () => { alert('received!');} );
alert('goodbye from renderer');
package.json
{
"name": "xxx",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"start": "electron ."
},
"author": "",
"license": "ISC",
"dependencies": {
"electron": "^8.0.0"
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…