fix(browser): preserve body API provenance through script export
Label new captured response bytes as Playwright body API results and retain the possibility of a credentialed follow-up load. Preserve legacy representations and source limitations through export without treating body-origin uncertainty as missing event coverage. Validated source and filesystem boundary tests plus real Chrome CLI and MCP network workflows covering binary, compressed, empty, unfinished, and same-URL responses and profile cleanup.
This commit is contained in:
@@ -17,6 +17,12 @@ const retained = {
|
||||
|
||||
it("validates the actual retained bytes against canonical base64, count, and digest", () => {
|
||||
expect(browserNetworkBodySchema.safeParse(retained).success).toBe(true);
|
||||
expect(
|
||||
browserNetworkBodySchema.safeParse({
|
||||
...retained,
|
||||
representation: "playwright-response-body-bytes",
|
||||
}).success,
|
||||
).toBe(true);
|
||||
for (const mutation of [
|
||||
{ bytes: 4 },
|
||||
{ sha256: "0".repeat(64) },
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { z } from "zod";
|
||||
|
||||
export const PLAYWRIGHT_RESPONSE_BODY_PROVENANCE_LIMITATION =
|
||||
"Captured response-body bytes are the result of Playwright's Response.body() API. Playwright may satisfy that API with a credentialed follow-up load of the request URL when CDP has no body, so transaction and event links do not verify that retained bytes came from the original network transaction.";
|
||||
|
||||
/** Resolved network content selection recorded by a capture. */
|
||||
export const browserNetworkContentSelectionValuesSchema = z.strictObject({
|
||||
request_body: z.boolean(),
|
||||
@@ -43,6 +46,9 @@ export const browserNetworkBodySchema = z.union([
|
||||
state: z.literal("captured"),
|
||||
representation: z.enum([
|
||||
"browser-exposed-request-bytes",
|
||||
"playwright-response-body-bytes",
|
||||
// Retained for captures produced before response-body provenance was
|
||||
// narrowed to the bytes Playwright exposes through Response.body().
|
||||
"browser-decoded-response-bytes",
|
||||
]),
|
||||
encoding: z.literal("base64"),
|
||||
|
||||
@@ -52,6 +52,9 @@ export const exportedWebScriptSchema = z.strictObject({
|
||||
redacted: z.boolean().nullable(),
|
||||
representation: z.enum([
|
||||
"debugger-source-utf8",
|
||||
"playwright-response-body-bytes",
|
||||
// Accept already-saved exports from before the response representation
|
||||
// was narrowed to the Playwright API result.
|
||||
"browser-decoded-response-bytes",
|
||||
]),
|
||||
}),
|
||||
@@ -116,9 +119,10 @@ export interface CapturedWebScript {
|
||||
readonly sha256: string;
|
||||
readonly media_type: string | null;
|
||||
readonly redacted: boolean | null;
|
||||
readonly representation:
|
||||
| "debugger-source-utf8"
|
||||
| "browser-decoded-response-bytes";
|
||||
readonly representation: Extract<
|
||||
ExportedWebScript["content"],
|
||||
{ readonly state: "exported" }
|
||||
>["representation"];
|
||||
}
|
||||
| Extract<ExportedWebScript["content"], { state: "unavailable" }>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user