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

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

问题描述

有一个页面(游戏),它通过 WebSocket 与服务器通信.我可以在 Chrome Developer Tool 中看到数据(帧).是否可以从 chrom 扩展访问/修改此通信?

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?

推荐答案

目前,访问或修改 Websocket 流量的唯一方法是使用 内容脚本注入一个脚本,用您自己的包装器替换 WebSocket 构造函数.此包装器的行为应与原始 WebSocket 实现类似,但您可以添加更多内容,例如将发送/接收的消息记录到您的扩展程序中.

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.

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

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.

有关如何包装 DOM 构造函数的灵感,请参见例如我的 Worker<的包装器/代码>.您可以自由重用部分代码(例如,EventTarget 接口的实现,这也是 WebSocket API 的要求).

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).

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

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

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