feat: add WebSocket message inspection tools#2370
Open
johan-gorter wants to merge 1 commit into
Open
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Adds list_websocket_connections, list_websocket_messages and get_websocket_message so that WebSocket traffic of the selected page can be inspected. Puppeteer does not expose WebSocket frames, so a per-page WebSocketCollector consumes the CDP Network.webSocket* events from the existing page session, following the same PageCollector pattern as the network and console collectors. Messages are retained per connection with bounded memory: the last 500 data messages within a 2MB per-connection budget, each stored payload capped at 100k characters, with explicit dropped/truncated markers. Control frames (ping/pong) are not recorded. Connections are decided dead on Runtime.executionContextsCleared (cross-document navigations only) rather than framenavigated, and still-open connections are carried across navigation splits, so a socket opened during page boot stays visible when a single-page app rewrites its URL with history.pushState. list_websocket_connections accepts includePreservedConnections to also list connections closed by earlier navigations. The test server gained a dependency-free WebSocket echo endpoint to test against a real connection.
johan-gorter
force-pushed
the
feat/websocket-inspection
branch
2 times, most recently
from
July 16, 2026 06:42
f9f361e to
78148ee
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds three read-only tools that let an agent inspect the WebSocket traffic of
the selected page — the one common network primitive the server currently
can't see, since Puppeteer does not expose WebSocket frames:
list_websocket_connections— connections of the selected page, with astable
wsId, status, and sent/received counts.list_websocket_messages— messages of a connection (oldest first) assingle-line previews, filterable by
directionand by a payload substring,with pagination.
get_websocket_message— the full payload of one message, optionally savedto a file inside the configured workspace roots.
How it works
Because Puppeteer doesn't surface WebSocket frames, a
WebSocketCollectorconsumes the CDP
Network.webSocket*events directly from the page sessionthat is already enabled. It follows the existing
PageCollectorpattern usedby the console and network collectors, so it plugs into the same
per-page/per-navigation storage, disposal, and stable-id machinery with no
base-class changes. The CDP session is obtained via
page._client(), the sameway
PageCollectorandWaitForHelperalready do.Capture starts the moment the page is inspected — reload to capture a
connection from its start. This is documented in the tool descriptions, the
README, and the skill.
Bounded memory
Retention is capped per connection so long-lived sockets can't grow unbounded:
the last 500 data messages within a 2 MB total budget, each stored payload
capped at 100k characters. Dropped and truncated messages are counted and
marked explicitly rather than silently discarded. Control frames (ping/pong)
are not recorded. All constants are exported and easy to tune — happy to adjust
if you'd prefer different defaults.
Single-page-app correctness
Field testing against a real SPA surfaced a subtlety worth calling out: an app
that rewrites its URL with
history.pushStatetriggers Puppeteer'sframenavigated, but that is a same-document navigation and does not closeWebSockets. The collector therefore:
Runtime.executionContextsCleared(cross-document navigations only), not on
framenavigated, andopened during page boot stays visible.
list_websocket_connectionsalso acceptsincludePreservedConnectionsto listconnections closed by earlier navigations.
Docs & tests
npm run gen), CLI options, and thechrome-devtoolsskill are updated.integration tests against a new dependency-free WebSocket echo endpoint in
the test server (capture, direction/text filtering, truncation, same-document
navigation survival, preserved connections, drop accounting, and the
unknown-connection error path).
Open questions for reviewers
different limits or configurability?
includePreservedConnectionsandfilePathsaving add surface area; happyto drop either for a leaner first version if you'd rather.