AdguardTeam / AdguardBrowserExtension

AdGuard browser extension
https://adguard.com/
GNU General Public License v3.0
3.15k stars 335 forks source link

WebSocket connections are broken on https://poloniex.com/exchange #307

Closed ameshkov closed 8 years ago

ameshkov commented 8 years ago

Steps to reproduce:

  1. Open https://poloniex.com/exchange
  2. Wait for a minute and open the browser console
  3. You'll see tons of errors there:
WebSocket is already in CLOSING or CLOSED state.value @ VM3171:338(anonymous function) @ plx_exchage.js?v=0716-6:2207
VM3171:320 WebSocket connection to 'wss://api2.poloniex.com/' failed: WebSocket is closed before the connection is established.

The problem is that the page closes WS itself with the following code:

window.conn.onmessage = function(e){
        if (e.target.connectionID != webSocketConnectionID)
            return e.target.close();
        .... code here ....
}

The root cause of this issue is that e.target object is the real WebSocket object and not our wrapper which contains the connectionID field.

To fix this issue we should not simply pass through the on* properties. Instead we should wrap them in our own function which will set the e.target field to the wrapper object.

Mizzick commented 8 years ago

Finally fixed