access Websocket traffic from chrome extension

后端 未结 5 576
借酒劲吻你
借酒劲吻你 2021-01-31 06:07

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 communica

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-31 06:40

    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!

提交回复
热议问题