Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Acquire renderer process id in Electron

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 ?

like image 784
hackjutsu Avatar asked May 15 '17 22:05

hackjutsu


People also ask

What is render process in Electron?

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.

How does IPC work in Electron?

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).

How do you find the mainWindow Electron?

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.

What is ipcMain in Electron JS?

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.


1 Answers

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();
like image 169
hackjutsu Avatar answered Sep 22 '22 03:09

hackjutsu