fix(browser)!: preserve WebSocket connections and comparable payload coverage
Retain source URLs, empty connections, and ordered frame streams. Compare same-URL streams without relying on transient request IDs, and compare selected shapes and byte counts only through common known coverage. Malformed binary frames retain known metadata with an unknown byte count. BREAKING CHANGE: inspect_web_page network.websocket_events is replaced by network.websocket_connections, whose records contain request_id, url, and events. Frame payload_bytes is nullable when decoding cannot establish its size. No legacy alias is retained. Validation: 78 domain/browser/MCP focused tests, check:fast, docs:check, and real Chrome 154 CDP capture passed. Real capture retained six connections and twelve frames with source URLs and selected shapes. Full browser verifier was interrupted during an unrelated slow scenario stage; its assertions were exercised by the bounded capture proof.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { WebPageInspection } from "../domain/browserObservationSchemas.js";
|
||||
import { sanitizeBrowserUrl } from "../domain/browserObservation.js";
|
||||
import { inferJsonShape } from "../domain/jsonShape.js";
|
||||
import { safeResponseMetadata } from "./CdpSafeMetadata.js";
|
||||
import {
|
||||
@@ -487,23 +488,20 @@ export const handleWebSocketFrame = (
|
||||
direction: "sent" | "received",
|
||||
): void => {
|
||||
const requestId = cdpStringValue(params.requestId);
|
||||
if (
|
||||
requestId === undefined ||
|
||||
(!state.network.has(requestId) && !state.allowedWebSockets.has(requestId))
|
||||
)
|
||||
return;
|
||||
if (requestId === undefined) return;
|
||||
const connection = state.webSocketConnectionsById.get(requestId);
|
||||
if (connection === undefined) return;
|
||||
const response = recordValue(params.response);
|
||||
const payload = cdpStringValue(response?.payloadData) ?? "";
|
||||
const opcode = Math.max(0, Math.trunc(numberValue(response?.opcode) ?? 0));
|
||||
const decoded = opcode === 1 ? undefined : decodeBase64(payload);
|
||||
if (opcode !== 1 && decoded === undefined)
|
||||
state.completeness.exclude("websocket_frames", "invalid_protocol_value");
|
||||
state.websockets.push({
|
||||
request_id: requestId,
|
||||
connection.events.push({
|
||||
direction,
|
||||
opcode,
|
||||
payload_bytes:
|
||||
opcode === 1 ? Buffer.byteLength(payload) : (decoded?.byteLength ?? 0),
|
||||
opcode === 1 ? Buffer.byteLength(payload) : (decoded?.byteLength ?? null),
|
||||
payload_shape: captureWebSocketShape(state, payload, opcode),
|
||||
});
|
||||
};
|
||||
@@ -512,7 +510,7 @@ const captureWebSocketShape = (
|
||||
state: CdpCaptureEventsState,
|
||||
payload: string,
|
||||
opcode: number,
|
||||
): WebPageInspection["network"]["websocket_events"][number]["payload_shape"] => {
|
||||
): WebPageInspection["network"]["websocket_connections"][number]["events"][number]["payload_shape"] => {
|
||||
if (!state.input.include_websocket_shapes) return null;
|
||||
if (opcode !== 1) return { format: "binary", json_shape: null };
|
||||
const shape = inferJsonShape(payload);
|
||||
@@ -542,9 +540,10 @@ export const handleWebSocketCreated = (
|
||||
);
|
||||
return;
|
||||
}
|
||||
const sourceUrl = sanitizeBrowserUrl(rawUrl).url;
|
||||
let parsed: URL;
|
||||
try {
|
||||
parsed = new URL(rawUrl);
|
||||
parsed = new URL(sourceUrl);
|
||||
} catch (cause: unknown) {
|
||||
// Unparseable URLs are recorded as unsupported, not as failures.
|
||||
void cause;
|
||||
@@ -561,7 +560,18 @@ export const handleWebSocketCreated = (
|
||||
state.completeness.exclude("websocket_connections", "disallowed_origin");
|
||||
return;
|
||||
}
|
||||
state.allowedWebSockets.add(requestId);
|
||||
if (state.webSocketConnectionsById.has(requestId)) {
|
||||
state.completeness.exclude(
|
||||
"websocket_connections",
|
||||
"invalid_protocol_value",
|
||||
);
|
||||
return;
|
||||
}
|
||||
state.webSocketConnectionsById.set(requestId, {
|
||||
request_id: requestId,
|
||||
url: sourceUrl,
|
||||
events: [],
|
||||
});
|
||||
};
|
||||
|
||||
export const handleFrameNavigated = (
|
||||
|
||||
Reference in New Issue
Block a user