Emulating network using session API

Devtools are an essential part of web development. Nowadays, dev tools provide complex features that help us develop a better application. With Chrome Developer Tools, the network tab provides you network emulation feature. Dev tools can emulate various network conditions so that you can check how the application will behave in different network conditions. For a normal Ajax request from your renderer process still, you can use this dev tool feature from Chrome dev tools. As Electron ships with the latest chromium features, you can use any dev tools features right inside your web page from Electron.

From the main process, you can emulate the network condition using session module. This allows you to mock the application into a specific network condition. For example, to emulate a GPRS connection with 50 KBPS throughput and 500 ms latency, the following code snippet can be used:

var appS
hell = new BrowserWindow({ ... });
//...
appShell.webContents.session.enableNetworkEmulation({
latency: 500,
downloadThroughput: 6400,
uploadThroughput: 6400
});

The values are same as the Chrome dev tools options. To emulate the offline mode, set offline to true inside the option:

appShell.webContents.session.enableNetworkEmulation({ offline: true });

Disabling any emulation already active for the session can be done as follows:

appShell.webContents.session.disableNetworkEmulation()
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.239.234