从Chrome扩展访问Websocket流量 [英] access Websocket traffic from chrome extension

查看:1222
本文介绍了从Chrome扩展访问Websocket流量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个页面(游戏),通过WebSocket与服务器通信。我可以在Chrome开发人员工具中查看数据(框架)。是否可以从chrom-extension访问/修改此通信?

解决方案

目前,访问或修改Websocket流量将使用内容脚本 插入脚本,替换 WebSocket 构造函数与你自己的包装。这个包装应该像原来的WebSocket实现一样,但是你可以添加更多的东西,比如记录发送/接收到的消息到你的扩展。



为了防止网站破坏,你必须确保你的 WebSocket 包装完全符合标准。必须实现的接口记录在 http://www.whatwg.org/specs/web-apps/current-work/multipage/network.html#the-websocket-interface



有关如何包装DOM构造函数的启示,请参阅例如我的 <$ c $的包装C>工人 。您可以自由地重用部分代码(例如 EventTarget 接口的实现,这也是 WebSocket 的要求c $ c> API)。

更强调:确保您的实现符合标准WebSocket API的接口,否则您可能会破坏某些网站!


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?

解决方案

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!

这篇关于从Chrome扩展访问Websocket流量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆