How to return Javascript value to main process?


I am very new to Electron, just tried to follow the Documentation.
I was able to run a html in Electron and it worked fine.

But I want to get value from JavaScript execude code inside Electron. main process. Is it possible?

My main is this index.js here:

var app = require ('app')
var BrowserWindow = require ('browser-window')
app.on('ready', function(){
    var mainWindow = new BrowserWindow({
    var script = 'console.log("clientWidth: " + document.body.clientWidth)' 
    // OK, display the width of the visible area
    // How to get this value in main process?
    var clientWidth = ??????????


You should see the IPC section of the documentation. It’s exactly what you’re looking for.


You could use ‘ipc’ module, you can see an example here


You can use screen module to get information about the available displays. It works in both the main and renderer processes.