Here are the modules available to the renderer process in Electron:

The module describe
desktopCapturer Is used to obtain the available resource, which is available throughgetUserMediaCaptured by
ipcRenderer Is aEventEmitterClass, which provides a limited number of ways to send synchronous or asynchronous messages from the renderer process to the main process, and to receive responses from the main process
remote Provides a simple way to communicate across processes
webFrame Used to customize the rendering of the current page

DesktopCapturer module

The desktopCapturer module is used to retrieve the available resources, which can be accessed using getUserMedia.

Example:
Var desktopCapturer = require('electron'). desktopCapturer.getSources({types: ['window', 'screen']}, function(error, sources) { if (error) throw error; for (var i = 0; i < sources.length; ++i) { if (sources[i].name == "Electron") { navigator.webkitGetUserMedia({ audio: false, video: { mandatory: { chromeMediaSource: 'desktop', chromeMediaSourceId: sources[i].id, minWidth: 1280, maxWidth: 1280, minHeight: 720, maxHeight: 720 } } }, gotStream, getUserMediaError); return; }}}); function gotStream(stream) { document.querySelector('video').src = URL.createObjectURL(stream); } function getUserMediaError(e) { console.log('getUserMediaError'); }

The above code, when calling the navigator. WebkitGetUserMedia create a constraint object, if use desktopCapturer resources, must be set chromeMediaSource as the “desktop”, And audio is false.

If we want to capture audio and video from the entire desktop, we can set ChromeDiasource to “screen” and Audio to true. When using this method, you cannot specify a ChromeDiasourceID.

IpcRenderer module

The ipcRenderer module is an instance of an EventEmitter object that provides methods for sending synchronous or asynchronous messages to the main process and for receiving responses from the main process.

The ipcRenderer module has the following methods to listen for events:

methods describe
on Listening to thechannel, when a new message arriveslistener(event, args...)calllistener
once Add a one-time for this eventlistenerfunction
removeListener From the specifiedchannelThe listener array in thelistener
removeAllListeners Deletes all listeners, or deletes the specifiedchannelOf all the

The ipcRenderer module has the following methods to send messages:

methods describe
send throughchannelSends asynchronous messages to the main process. It can also send any parameters. The parameters will beJSONSerialization, and then no function or prototype chain is included
sendSync throughchannelSends a synchronous message to the main process. It can also send any parameters. The parameters will beJSONSerialization, and then no function or prototype chain is included
sendToHost similaripcRenderer.send, but its event will be sent tohost page<webview>Element, not the main process

Remote module

The Remote module provides an easy way to conduct inter-process communication (IPC) between the renderer process (the Web page) and the main process.

Example:

Here is an example of creating a browser window from the renderer process:

const remote = require('electron').remote;
const BrowserWindow = remote.BrowserWindow;

var win = new BrowserWindow({ width: 800, height: 600 });
win.loadURL('https://github.com');

The methods of the remote module are:

methods describe
require Returns execution in the main processrequire(module)The object that is returned
getCurrentWindow Returns the page to which it belongsBrowserWindowobject
getCurrentWebContents Returns theWebContentsobject
getGlobal Returns the name in the main processnameOf the global variable (i.eglobal[name])
process Returns in the main processprocessobject

WebFrame module

The webFrame module is used to customize the rendering of the current web page.

Example:

For example, enlarge the page to 150% :

var webFrame = require('electron').webFrame;
webFrame.setZoomFactor(2)

The Web-Frame module has the following methods:

methods describe
setZoomFactor Change the scale parameter to the specified value of the parameter. The scale parameter is a percentage scale, so 300% = 3.0
getZoomFactor Returns the value of the current zoom parameter
setZoomLevel Modifies the zoom level to the specified level, originalsizeIs 0, and each increase represents a 20% increase or a 20% decrease
getZoomLevel Returns the current zoom level
setZoomLevelLimits Sets the maximum and minimum values of the zoom level
setSpellCheckProvider Set up a spell check for an input field or text fieldprovider