Skip to content

feat(har): adjust capturing WebSocket data based on content config#41124

Open
dcrousso wants to merge 1 commit into
microsoft:mainfrom
dcrousso:feat-har-WebSocket-content
Open

feat(har): adjust capturing WebSocket data based on content config#41124
dcrousso wants to merge 1 commit into
microsoft:mainfrom
dcrousso:feat-har-WebSocket-content

Conversation

@dcrousso
Copy link
Copy Markdown
Contributor

@dcrousso dcrousso commented Jun 3, 2026

only set _webSocketMessages if content: 'embed'

for content: 'attach', save the array as a .json

also, unlike other requests that have a single response, a WebSocket can receive multiple frames, meaning that we don't finish the Entry until the WebSocket is closed, which delays when the captured frames are saved, so make sure to at least save what's already there if the recording is stopped before the WebSocket is closed

@dcrousso dcrousso requested a review from yury-s June 3, 2026 19:14
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Comment thread tests/library/har-websocket.spec.ts Outdated
expect(messages[0].time).toBeLessThanOrEqual(messages[1].time);
});

it('should attach binary websocket messages', async ({ contextFactory, server }, testInfo) => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Somehow it feels like we should combine this and previous tests together.

Comment thread tests/library/har-websocket.spec.ts Outdated
expect(wsEntry.response.content._file).toBeUndefined();
});

it('should omit binary websocket messages', async ({ contextFactory, server }, testInfo) => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same here.


let saveMessages: (() => void) | undefined;
if (this._options.content === 'attach') {
saveMessages = () => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If we want to support websockets in the trace, we'll have to do this separately in HarRecorder vs Tracing. Let's move this out to HarRecorder through HarTracerDelegate right away?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

if it's OK with you, id rather handle this when i actually work on supporting WebSocket in tracing as right now i dont really know what the best approach would be (i.e. i'd hate to implement something for it now and then have to completely change it once i start working on tracing)

i plan to do that next so this shouldn't be "stale" for too long

}),
eventsHelper.addEventListener(webSocket, network.WebSocket.Events.FrameSent, ({ opcode, data, wallTimeMs }: { opcode: number, data: string, wallTimeMs: number }) => {
harEntry._webSocketMessages!.push({ type: 'send', time: this._options.omitTiming ? -1 : wallTimeMs, opcode, data });
if (this._options.content !== 'omit')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this be a separate option? I can imagine not everyone would like websocket traffic (that is sometimes very heavy) to be recorder. Perhaps overall, an option for (not) recording websockets?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we discussed offline and felt that it's probably not supper common for a developer to want the network metadata (e.g. headers, timing, etc.) without also wanting the content for a WebSocket, so in addition to the existing content settings they could easily add a urlFilter to ignore all ws:///wss:// instead

if needed we could add an environment variable, but that might be overeager

@dcrousso dcrousso force-pushed the feat-har-WebSocket-content branch from 5bac817 to 1e68c65 Compare June 5, 2026 16:44
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

Test results for "MCP"

7266 passed, 1119 skipped


Merge workflow run.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

Test results for "tests 1"

6 flaky ⚠️ [chromium-library] › library/chromium/chromium.spec.ts:299 › should report intercepted service worker requests in HAR `@chromium-ubuntu-22.04-arm-node20`
⚠️ [chromium-library] › library/video.spec.ts:719 › screencast › should work with video+trace `@chromium-ubuntu-22.04-arm-node20`
⚠️ [chromium-library] › library/video.spec.ts:275 › screencast › should capture navigation `@chromium-ubuntu-22.04-node24`
⚠️ [chromium-library] › library/chromium/chromium.spec.ts:211 › should intercept service worker requests (main and within) `@chromium-ubuntu-22.04-node20`
⚠️ [chromium-library] › library/video.spec.ts:275 › screencast › should capture navigation `@chromium-ubuntu-22.04-node22`
⚠️ [playwright-test] › ui-mode-trace.spec.ts:704 › should indicate current test status `@windows-latest-node22`

39557 passed, 775 skipped


Merge workflow run.

@dcrousso dcrousso requested a review from dgozman June 5, 2026 19:12
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.

2 participants