Intercepting or disabling network traffic



I’m working on a project that runs multiple HTML5 “apps.” There are tight bandwidth constraints, so we have libraries that apps may use to send and receive data over the network. We replace common window scoped objects like XMLHttpRequet with proxies that forward traffic over our managed connection.

However, “apps” can always trigger a Chrome ResourceLoader by, say, dropping an image on the DOM with a http://… source.

I would like to either intercept all network traffic, or disable it entirely for a window and force it to use its proxies.

My first attempt has been trying to intercept the protocol. I get the following results:

protocol.interceptProtocol('http', ...
Error: Scheme does not exist

protocol.registerProtocol('http', ...
Error: The scheme is already registered

Error: The scheme has not been registered

In order to use atom-shell, the only thing I can figure at the moment is to have a parent process fork it, unshare the networking namespace, and leverage some kind of IPC between the two.

I’ve tried hooking in to DOM events to try to catch elements that would cause a ResourceLoader to call out to the network, but that didn’t seem reliable at all.

Anything I’ve overlooked?



As far as I know, there is no API support in atom-shell for intercepting and blocking/cancelling an URL request for now. So you can try to intercept it (could still be buggy anyway) but there is no way to block it. And it’d be really nice to have an API like webView:shouldStartLoadWithRequest:navigationType: in iOS or shouldOverrideUrlLoading in Android. I was actually looking into the atom-shell code but it’s kind of tricky to find a right place to squeeze in this feature.


Just notice that it seems like we can listen to app’s open-url event and then cancel the default action of the event with preventDefault().


I meet the same problem. It seems that the intercept related API just doesn’t work.
do you have any workaround ?