Inspecting web sockets - Firefox Developer Tools 编辑

Since Firefox 71, the Network Monitor has had the ability to inspect web socket connections. This article explores what functionality the Web Socket Inspector makes available.

Accessing the inspector

When you are inspecting a web app that utilizes a web socket connection, the web socket requests are listed in the list of requests in the Network Monitor along with all other requests.

WS filter in the network inspector

You can use the WS button to filter the list for just web socket connections. Only requests with the 101 status code (WebSocket Protocol Handshake) are visible, which indicates that the server is switching to a web socket connection.

Clicking on a web socket request opens the usual sidebar to reveal additional details. Choose the Response tab to inspect web socket frames sent and received through the selected connection.

Messages panel in the web socket inspector

The live-updated table shows data for sent (green arrow) and received (red arrow) frames. Each frame expands on click, so you can inspect the formatted data.

Pausing web socket traffic

You can use the pause/resume button in the Network Monitor toolbar to stop intercepting web socket traffic. This allows you to capture only the frames that you are interested in.

Pausing the web socket inspector

Filtering web socket frames

To focus on specific messages, frames can be filtered using the filter at the top of the Response panel.

web socket frame filter

There are also predefined filters, available in the tool bar of the Response pane, grouped into a selection list.

Screenshot showing the filter menu for WebSocket messages

The following filters are available:

All
Displays all messages (by default, except control messages).
Sent
Displays only messages sent by the browser (by default, except control messages).
Received
Displays only messages received from the server (by default, except control messages).
Control
(Available starting in Firefox 76). Displays messages for control frames (Ping, Pong, or Close). This filter can be combined with the others, to display, for example, only messages for control frames sent by the browser.

Columns in the Response pane

In the Response pane, you can choose to show the following information about each frame:

  • Data
  • Size
  • Time
  • OpCode
  • MaskBit
  • FinBit

The Data and Time columns are visible by default, but you can customize the interface to see more columns by choosing which ones to show from the context menu that is opened by right-clicking in the table header.

columns in the messages panel

Expanding each message

Selecting a message in the list shows a preview of the data being sent in that message, at the bottom of the Response pane.

web socket payload preview

Supported WS protocols

The inspector currently supports the following web socket protocols:

  • Plain JSON
  • Socket.IO
  • SockJS
  • SignalR
  • WAMP
  • STOMP
  • STOMP inside SockJS

The payload based on those protocols is parsed and displayed as an expandable tree for easy inspection, although you can of course still see the raw data (as sent over the wire) as well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:113 次

字数:5686

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文