Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

access Websocket traffic from chrome extension

There is a page (game), which communicate via WebSocket to the server. I can see the data (frames) in the Chrome Developer Tool. Is it possible to access / modify this communication from a chrom-extension?

like image 781
user1930254 Avatar asked Apr 04 '14 17:04

user1930254


People also ask

Can Fiddler capture WebSocket traffic?

Fiddler is a web debugger proxy server application which can be used to capture HTTP(S) and Web Socket traffic and log it for review.

How do I open WebSocket in browser?

To open a websocket connection, we need to create new WebSocket using the special protocol ws in the url: let socket = new WebSocket("ws://javascript.info"); There's also encrypted wss:// protocol. It's like HTTPS for websockets.


1 Answers

Currently, the only way to access or modify Websocket traffic is to use a content script to inject a script that replaces the WebSocket constructor with your own wrapper. This wrapper should behave like the original WebSocket implementation, but you can add more stuff, like logging the sent/received messages to your extension.

To prevent sites from breaking, you must make sure that your WebSocket wrapper is fully standard-compliant. The interface that has to be implemented is documented at http://www.whatwg.org/specs/web-apps/current-work/multipage/network.html#the-websocket-interface.

For inspiration on how to wrap a DOM constructor, see e.g. my wrapper for Worker. You are free to re-use parts of the code (e.g. the implementation of the EventTarget interface, which is also a requirement of the WebSocket API).

More emphasis: Make sure that your implementation adheres to the interface of the standard WebSocket API, or you could break some sites!

like image 133
Rob W Avatar answered Sep 18 '22 20:09

Rob W