是否有一种方法或扩展,让我观察“流量”通过WebSocket?出于调试目的,我希望看到客户端和服务器的请求/响应。
当前回答
Chrome开发工具允许看到握手请求在打开连接期间保持等待,但据我所知,你不能看到流量。但是你可以闻一下。
其他回答
Chrome Canary和Chromium现在有WebSocket消息帧检查功能。下面是快速测试的步骤:
Navigate to the WebSocket Echo demo [dead as of 2022], hosted on the websocket.org site https://echo.websocket.events/.ws (run by the company Lob) or you can locally run the Echo Server project. Turn on the Chrome Developer Tools. Click Network, and to filter the traffic shown by the Dev Tools, click WebSockets. In the Echo demo, click Connect. On the Headers tab in Google Dev Tool you can inspect the WebSocket handshake. Click the Send button in the Echo demo. THIS STEP IS IMPORTANT: To see the WebSocket frames in the Chrome Developer Tools, under Name/Path, click the echo.websocket.org entry, representing your WebSocket connection. This refreshes the main panel on the right and makes the WebSocket Frames tab show up with the actual WebSocket message content.
注意:每次发送或接收新消息时,您都必须通过单击左侧的echo.websocket.org条目来刷新主面板。
我还发布了这些步骤的屏幕截图和视频。
我最近出版的书,The Definitive Guide to HTML5 WebSocket,也有一个专门的附录,涵盖了各种检查工具,包括Chrome Dev tools, Chrome net-internals和Wire Shark。
Chrome 29及以上版本的简短回答:
打开调试器,转到“网络”选项卡 使用websocket加载页面 单击带有服务器升级响应的websocket请求 选择标签“帧”查看websocket帧 再次单击websocket请求刷新帧
其他答案涵盖了最常见的场景:观察帧的内容(开发人员工具->网络选项卡->右击websocket连接->帧)。
如果你想知道更多的信息,比如哪些套接字当前打开/空闲或能够关闭它们,你会发现这个url很有用
chrome://net-internals/#sockets
如果你想要更好的体验,我建议使用Postman来调试WebSocket请求。它已经作为一个新功能发布。 https://stackoverflow.com/a/43754722/15988851
我只是发布这篇文章,因为Chrome改变了很多,没有一个答案是最新的。
开放开发工具 刷新您的页面(以便网络选项卡捕获WS连接) 点击你的请求 点击“帧”子选项卡 你应该会看到如下内容:
推荐文章
- 卸载Chrome开发工具
- 如何触发自动填充在谷歌Chrome?
- CSS变换,锯齿边缘在铬
- 为什么Chrome浏览器不正确地确定页面是在不同的语言,并提供翻译?
- Chrome在哪里存储扩展?
- WebSockets和纯TCP之间的根本区别是什么?
- 窗口。亲近与自我。close不关闭Chrome中的窗口
- 防止滚动条增加到Chrome页面的宽度
- URL中的“#:~:text=”位置哈希值到底是什么?
- 很好的初学者教程socket.io?
- 如何禁用谷歌翻译从HTML在Chrome
- Chrome开发工具:如何找出什么是覆盖CSS规则?
- 资源解释为样式表,但以MIME类型text/html传输(似乎与web服务器无关)
- Chrome iOS(和Safari)的远程调试
- 在Chrome中模拟有限的带宽?