shyiko / electron-har

A command-line tool for generating HTTP Archive (HAR) (based on Electron)
https://www.npmjs.com/package/electron-har
MIT License
47 stars 11 forks source link

Thoughts on leveraging network throttling and user agents? #5

Open bmcminn opened 8 years ago

bmcminn commented 8 years ago

One of the primary use cases I have around this project is being able to throttle the network and applying custom user agents to simulate certain desktop and mobile environments. Curious if you've tackled this before or if you think this would be a decent addition?

I'm planning to dig into Electron's docs to see if this is feasible and will be tinkering with a possible integration soon.

shyiko commented 8 years ago

There wasn't a need for anything like this in my case but I totally understand why one might need it. And so I would definitely merge such PR in :)

P.S. I had my doubts about network throttling but it seems they have actually implemented it (https://github.com/atom/electron/pull/2914).

bmcminn commented 8 years ago

I found that and started playing with it. In src/electron-har.js, I've added the following snippet to the app.on('ready') method and it seems to work just fine.

// similar to Chrome's Wifi profile
bw.webContents.session.enableNetworkEmulation({
    latency: 2,
    downloadThroughput: 30000,
    uploadThroughput: 15000
});

I'll see about adding a better interface for defining network profiles or custom profiles as part of the CLI arguments and the standard JS integration as well.

bmcminn commented 8 years ago

I've made some progress on this effort, however the conditional for handling throttle profile config and init doesn't seem to work as consistently as defining it in place per my snippet in my eariler comment.

Would be curious to see how it fairs on another machine if anyone wants to clone my fork down and test it: https://github.com/bmcminn/electron-har

shyiko commented 8 years ago

Looking good, man. What do you mean by "doesn't seem to work as consistently as defining it in place per my snippet"?

bmcminn commented 8 years ago

When using -Y WIFI flag in CLI, I'm seeing HAR results claiming TTFB and page load times greater than 12+ seconds, compared to sub 1 second TTFB/Page Load if I pass the object literal directly in the enableNetworkEmulation() method.

Results are even worse for other profiles I configured, GPRS netting 70+s of latency on TTFB and Page Load.

EDIT: Figured it out, the API specifies upload/download throughput is defined in Bytes/second (Bps) and my spec is defined at 30Kbps, not 30Mbps... So my numbers are off and I was emulating a subpar modem connection :facepunch: