In Electron, the renderer process's pid was exposed by
processId = require('remote').getCurrentWindow().getProcessId()
which, however, is no longer valid in recent releases (1.4.x, 1.5.x, 1.6.x).
Is there any other way to get the pid of the renderer process, i.e. the pid for the Windows ?
The renderer process Each Electron app spawns a separate renderer process for each open BrowserWindow (and each web embed). As its name implies, a renderer is responsible for rendering web content.
IPC channels In Electron, processes communicate by passing messages through developer-defined "channels" with the ipcMain and ipcRenderer modules. These channels are arbitrary (you can name them anything you want) and bidirectional (you can use the same channel name for both modules).
To safely get the mainWindow in electron, I store its ID in a env variable and call BrowserWindow. fromId(ID) when needed. BrowserWindow. getFocusedWindow() will not work in some case, for exemple if you load an URL from a child window to the main window.
ipcMain:This Module is used to communicate from the Main Process to the Renderer Processes. It is defined and used in the Main Process. It handles all synchronous and asynchronous messages being sent from the renderer process.
The method getOSProcessId()
to acquire the renderer's OS pid (not the routing id) was added to Electron v1.7.1. Here is the original pull request.
require('electron').remote.getCurrentWebContents().getOSProcessId();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With