Intercepting or disabling network traffic


#1

Hi!

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

protocol.unregisterProtocol('http')
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?

Thanks!


#2

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.


#3

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().


#4

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