Files
reverse-engineering-anything/src/browser/execution/CdpRuntimeProtocol.ts
T
morluto 3e0dc29041 fix(browser): type CDP command replies and parse frame trees once (#10604)
* fix(browser): type CDP command replies and parse frame trees once

CdpConnection.send is typed by method name. A command registered in
src/browser/protocol/CdpCommands.ts has its parameters typed from the
protocol table Playwright ships and its reply parsed once by its own result
schema; a mismatch rejects that command with CdpMalformedReply
(protocol_error, command, JSON pointer) without poisoning the connection.
Playwright storage sessions admit replies through the same table.

Page.getFrameTree and Page.getResourceTree are the first registered
commands. Their one parser keeps per-frame facts tolerant (malformed child
entries remain explicit omissions) and replaces the per-site readers:
observeMainFrameUrl, mainFrameUrl, walkFrameTrees, frameTreeResources,
runtimeFrameTreeSchema and the scenario storage frame schema.

A reply without a frame tree used to be retried for two seconds and
reported as target_not_allowed; it is now one protocol_error.

A guard test counts literal CDP command names without a result schema per
source file; the baseline can only shrink.

* fix(browser): consume parsed CDP facts across boundaries
2026-11-14 15:21:00 -05:00

57 lines
1.5 KiB
TypeScript

import { z } from "zod";
import { cdpResourceColumnSchema } from "../../domain/cdpObservationSchemas.js";
const integer = z.int().min(0);
const range = z.object({
startOffset: integer,
endOffset: integer,
count: integer,
});
/** CDP precise coverage preserves every nested producer range. */
export const preciseCoverageSchema = z.object({
timestamp: z.number().min(0),
result: z.array(
z.object({
scriptId: z.string().min(1),
url: z.string(),
functions: z.array(
z.object({
functionName: z.string(),
isBlockCoverage: z.boolean(),
ranges: z.array(range),
}),
),
}),
),
});
/** The full reported synchronous and embedded asynchronous stack is retained. */
export const runtimeStackSchema = z.object({
callFrames: z.array(
z.object({
scriptId: z.string(),
url: z.string(),
lineNumber: integer,
columnNumber: cdpResourceColumnSchema,
functionName: z.string(),
}),
),
parent: z.unknown().optional(),
parentId: z
.object({ id: z.string(), debuggerId: z.string().optional() })
.optional(),
});
/** Native listener descriptors omit live remote handles from portable evidence. */
export const runtimeListenersSchema = z.object({
listeners: z.array(
z.object({
type: z.string(),
useCapture: z.boolean(),
passive: z.boolean(),
once: z.boolean(),
scriptId: z.string(),
lineNumber: integer,
columnNumber: cdpResourceColumnSchema,
}),
),
});