Events are sent through mainWindow.webContents.send in the electron main thread and cannot be received by the rendering thread

function to be implemented: click the button on the
page 1 (rendering process 1) to send the event to the main process. After the main process successfully receives the event, it sends the event event through mainWindow.webContents.send. Listen to the event, through the ipcRender.on method in page 2 (rendering process 2). When the event is received, the business processing starts.

problem:
the main process successfully received the event sent by page 1 (rendering process 1), and then sent to event event, page 2 (rendering process 2) via mainWindow.webContents.send in the main process and did not receive it.

Code:

Page 1 (rendering process 1):

const ipcRenderer = require("electron").ipcRenderer;

function playDanmu(){
    ipcRenderer.send("sigPlayDanmu", "123456");
};

main process:

const ipcMain = require("electron").ipcMain;
ipcMain.on("sigPlayDanmu", (event, args) => {
    console.log("sigPlayDanmu is captured");
    mainWindow.webContents.send("ping", "pong");
});

Page 2 (rendering process 2):

    <script>
        require("electron").ipcRenderer.on("ping", (event, message) => {
            ...
        })
    </script>

is there something wrong with the posture?

so I would like to ask you, how does the main thread actively request the rendering thread to call the method of the rendering thread or trigger the event of the rendering thread?

Thank you!

Mar.25,2021

in the main thread, the object calling the webContents.send () method is misused.
the window object is used to call messages to the rendering thread corresponding to the window.
just change the above to page2WindowObject.webContents.send ()

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3783e-34468.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3783e-34468.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?