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?
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.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With