是否有一种方法或扩展,让我观察“流量”通过WebSocket?出于调试目的,我希望看到客户端和服务器的请求/响应。
当前回答
他们似乎在不断地改变Chrome中的东西,但这里是目前有效的:-)
首先你必须点击红色记录按钮,否则你什么也得不到。 我以前从未注意到WS,但它过滤掉了web套接字 连接。 选择它,然后你可以看到帧(现在称为消息),它将向你显示错误消息等。
其他回答
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扩展名为Simple WebSocket Client v0.1.3,是由用户hakobera发布的。它的使用非常简单,它允许在给定的URL上打开websocket,发送消息并关闭socket连接。它非常简约。
其他答案涵盖了最常见的场景:观察帧的内容(开发人员工具->网络选项卡->右击websocket连接->帧)。
如果你想知道更多的信息,比如哪些套接字当前打开/空闲或能够关闭它们,你会发现这个url很有用
chrome://net-internals/#sockets
如果你想要更好的体验,我建议使用Postman来调试WebSocket请求。它已经作为一个新功能发布。 https://stackoverflow.com/a/43754722/15988851
Chrome 29及以上版本的简短回答:
打开调试器,转到“网络”选项卡 使用websocket加载页面 单击带有服务器升级响应的websocket请求 选择标签“帧”查看websocket帧 再次单击websocket请求刷新帧
推荐文章
- 如何禁用谷歌翻译从HTML在Chrome
- Chrome开发工具:如何找出什么是覆盖CSS规则?
- 资源解释为样式表,但以MIME类型text/html传输(似乎与web服务器无关)
- Chrome iOS(和Safari)的远程调试
- 在Chrome中模拟有限的带宽?
- 资源解释为文档,但使用MIME类型application/zip传输
- 如何让Chrome允许混合内容?
- 了解Chrome网络日志“停滞”状态
- 如何卸载Service Worker?
- jQuery ' .is(":visible") '在Chrome中无效
- 如何保存样式面板的CSS Chrome开发工具的变化?
- 当你双击日文文本时,Chrome如何决定突出显示什么?
- Chrome不会删除会话cookie
- 在Chrome和Firefox中用Javascript报告的神秘的“脚本错误”
- 在Window上执行'btoa'失败:要编码的字符串包含Latin1范围之外的字符。