Skip to content

feat(websocket): expand diagnostics channel payloads#4888

Open
islandryu wants to merge 3 commits intonodejs:mainfrom
islandryu:expandWebsocketDiagnostics
Open

feat(websocket): expand diagnostics channel payloads#4888
islandryu wants to merge 3 commits intonodejs:mainfrom
islandryu:expandWebsocketDiagnostics

Conversation

@islandryu
Copy link
Member

This relates to...

Fixes: #4673

Rationale

I would like to extend the WebSocket events in order to send CDP data.

Changes

Introduces undici:websocket:created, undici:websocket:handshakeRequest, frameSent, frameReceived, and frameError coverage.

Features

Bug Fixes

N/A

Breaking Changes and Deprecations

Status

@codecov-commenter
Copy link

codecov-commenter commented Mar 13, 2026

Codecov Report

❌ Patch coverage is 68.87417% with 47 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.79%. Comparing base (0d7ec33) to head (aa50095).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
lib/core/diagnostics.js 13.51% 32 Missing ⚠️
lib/web/websocket/sender.js 86.53% 7 Missing ⚠️
lib/web/websocket/stream/websocketstream.js 0.00% 4 Missing ⚠️
lib/web/websocket/websocket.js 71.42% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4888      +/-   ##
==========================================
- Coverage   92.89%   92.79%   -0.11%     
==========================================
  Files         112      112              
  Lines       35665    35774     +109     
==========================================
+ Hits        33131    33195      +64     
- Misses       2534     2579      +45     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@metcoder95 metcoder95 requested a review from KhafraDev March 13, 2026 11:21
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm


for (let i = 0; i < payloadData.length; ++i) {
payloadData[i] = frame[payloadOffset + i] ^ maskKey[i & 3]
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diagnostics channels are meant to be low overhead. This is the opposite of that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to use the data before masking.

Copy link
Member

@KhafraDev KhafraDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the changes. Diagnostics channels should be unobtrusive.

this.#socket.uncork()
} else {
// direct writing
publishFrame(this.#websocket, hint === sendHints.text ? opcodes.TEXT : opcodes.BINARY, true, toBuffer(item, hint))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the toBuffer will make WebSocket slower for the majority of people not using diagnostics channels

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the toBuffer call after the hasSubscribers check.

const node = {
promise: item.arrayBuffer().then((ab) => {
node.promise = null
publishFrame(this.#websocket, opcodes.BINARY, true, new Uint8Array(ab))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add WebSocket lifecycle, frame, and frame-error diagnostic events for DevTools Protocol support

4 participants