diff --git a/docs/guides/web/web-network-captures.md b/docs/guides/web/web-network-captures.md index 6882d50a1e..0df94ac0ee 100644 --- a/docs/guides/web/web-network-captures.md +++ b/docs/guides/web/web-network-captures.md @@ -94,9 +94,9 @@ The observed mitmproxy 12.2.3 `SaveHar` profile can emit `postData.text: null` for a missing request body. REA preserves that reported null, omitting the optional field only from its validation copy for this exact producer profile; it does not invent an empty string or body bytes. -The observed Playwright 1.58.2 profile can report a bracketed IPv6 +The observed Playwright 1.58.2 and 1.64.1 profiles can report a bracketed IPv6 `serverIPAddress`, forwarded from Chromium's `remoteIPAddress` through -[Playwright's HAR tracer](https://github.com/microsoft/playwright/blob/v1.58.2/packages/playwright-core/src/server/har/harTracer.ts). +[Playwright's HAR tracer](https://github.com/microsoft/playwright/blob/v1.64.1/packages/playwright-core/src/server/har/harTracer.ts). Chromium DevTools exports (declared as `WebInspector` `537.36`, the frozen AppleWebKit version in Chromium's user agent) report the same bracketed form: [its HAR writer](https://github.com/ChromeDevTools/devtools-frontend/blob/63739e8ec45ca01b9e4be9b8b05946acdadd8f1f/front_end/models/har/Log.ts) diff --git a/src/browser/history/HarCapture.test.ts b/src/browser/history/HarCapture.test.ts index cec83ef027..fc0fa04369 100644 --- a/src/browser/history/HarCapture.test.ts +++ b/src/browser/history/HarCapture.test.ts @@ -767,16 +767,20 @@ it("preserves observed SaveHar null post-data without broadening arbitrary HAR p ).toThrow("HAR schema validation failed"); }); -it.each(["[2001:db8::1]", "[::1]", "[::ffff:192.0.2.1]"])( - "retains Playwright 1.58.2 bracketed IPv6 spelling in reported Evidence: %s", - (address) => { +it.each([ + { version: "1.58.2", address: "[2001:db8::1]" }, + { version: "1.64.1", address: "[::1]" }, + { version: "1.58.2", address: "[::ffff:192.0.2.1]" }, +])( + "retains Playwright $version bracketed IPv6 spelling in reported Evidence: $address", + ({ version, address }) => { const fixture = historicalHar(); const first = fixture.log.entries[0]; if (first === undefined) throw new Error("fixture missing"); const input = { log: { ...fixture.log, - creator: { name: "Playwright", version: "1.58.2" }, + creator: { name: "Playwright", version }, entries: [ { ...first, @@ -795,7 +799,7 @@ it.each(["[2001:db8::1]", "[::1]", "[::ffff:192.0.2.1]"])( }, }); const limitation = decoded.records[0]?.limitations.find((line) => - line.includes("Playwright 1.58.2"), + line.includes(`Playwright ${version}`), ); expect(limitation).toMatch(/bracketed IPv6.*serverIPAddress/iu); expect(limitation).toMatch(/original spellings.*retained/iu); diff --git a/src/browser/history/HarCapture.ts b/src/browser/history/HarCapture.ts index d40f9fa4fc..d98b1cb03a 100644 --- a/src/browser/history/HarCapture.ts +++ b/src/browser/history/HarCapture.ts @@ -35,7 +35,8 @@ export const decodeHarCapture = ( const validation = projectHar(raw, [], "validation"); const adaptations = createHarValidator()(validation.reported); const ipv6Adaptation = adaptations.bracketedIpv6; - const failedRequests = new Set(adaptations.failedRequests); + const timingAdaptation = adaptations.failedRequests; + const failedRequests = new Set(timingAdaptation?.entries); const adaptedIpv6Entries = new Set(ipv6Adaptation?.entries); const ipv6Limitations = ipv6Adaptation === null @@ -84,9 +85,9 @@ export const decodeHarCapture = ( limitations: [ "HAR text without an encoding declaration is producer-decoded Unicode. Unsupported declared body encodings remain opaque; original body bytes remain unknown unless content explicitly uses valid base64. Declared sizes are preserved independently of retained bytes. mitmproxy 12.2.3 SaveHar may report null optional postData.text; that null is retained and omitted only from the upstream validation copy.", ...(adaptedIpv6Entries.has(ordinal) ? ipv6Limitations : []), - ...(failedRequests.has(ordinal) + ...(timingAdaptation !== null && failedRequests.has(ordinal) ? [ - "This capture declares Playwright 1.64.1 and records a failed request with unavailable timings (-1). The original failure and timing sentinels are retained; only the validation copy substitutes nonnegative timings. Producer declarations are not authenticated.", + `This capture declares ${timingAdaptation.producer} and records a failed request with unavailable timings (-1). The original failure and timing sentinels are retained; only the validation copy substitutes nonnegative timings. Producer declarations are not authenticated.`, ] : []), ...(recordsExcluded diff --git a/src/browser/history/HarSchema.ts b/src/browser/history/HarSchema.ts index 0789d88732..a0809ec344 100644 --- a/src/browser/history/HarSchema.ts +++ b/src/browser/history/HarSchema.ts @@ -30,27 +30,47 @@ const timingsSchema = { }, }; -// Observed producers that copy Chromium's bracketed IPv6 remote address into -// serverIPAddress. Chromium DevTools declares WebInspector with the frozen -// AppleWebKit version from its user agent. -const BRACKETED_IPV6_PRODUCERS = [ - { name: "Playwright", version: "1.58.2", label: "Playwright 1.58.2" }, +interface HarProducerProfile { + readonly name: string; + readonly version: string; + readonly label?: string; + readonly bracketedIpv6?: true; + readonly unavailableFailedRequestTimings?: true; + readonly nullPostDataText?: true; +} + +// Match exact observed profiles. Chromium DevTools declares WebInspector with +// the frozen AppleWebKit version from its user agent. +const HAR_PRODUCER_PROFILES: readonly HarProducerProfile[] = [ + { + name: "Playwright", + version: "1.58.2", + bracketedIpv6: true, + }, + { + name: "Playwright", + version: "1.64.1", + bracketedIpv6: true, + unavailableFailedRequestTimings: true, + }, { name: "WebInspector", version: "537.36", label: "Chromium DevTools (WebInspector 537.36)", + bracketedIpv6: true, }, -] as const; + { name: "mitmproxy", version: "12.2.3", nullPostDataText: true }, +]; -/** Entries whose bracketed IPv6 address was adapted, and the declared producer. */ -interface BracketedIpv6Adaptation { +/** Validation changes tied to observed spelling and the declared producer. */ +interface HarEntryAdaptation { readonly producer: string; readonly entries: readonly number[]; } interface HarProducerAdaptations { - readonly bracketedIpv6: BracketedIpv6Adaptation | null; - readonly failedRequests: readonly number[]; + readonly bracketedIpv6: HarEntryAdaptation | null; + readonly failedRequests: HarEntryAdaptation | null; } /** Validate with pinned HAR 1.2 draft-06 schemas and the owned schema corrections. */ @@ -118,28 +138,19 @@ export const createHarValidator = (): (( }; }; -/** Name the declared producer when it is observed to bracket IPv6 addresses. */ -const bracketedIpv6ProducerOf = ( - creator: Record, -): string | null => - BRACKETED_IPV6_PRODUCERS.find( - ({ name, version }) => creator.name === name && creator.version === version, - )?.label ?? null; - /** Adapt only observed producer representations in the disposable validation copy. */ const allowObservedProducerRepresentations = ( value: unknown, ): HarProducerAdaptations => { - const none = { bracketedIpv6: null, failedRequests: [] }; + const none = { bracketedIpv6: null, failedRequests: null }; if (!captureObject(value) || !captureObject(value.log)) return none; const log = value.log; - if (!captureObject(log.creator) || !Array.isArray(log.entries)) return none; - const mitmproxy = - log.creator.name === "mitmproxy" && log.creator.version === "12.2.3"; - const bracketedIpv6Producer = bracketedIpv6ProducerOf(log.creator); - const playwright = - log.creator.name === "Playwright" && log.creator.version === "1.64.1"; - if (!mitmproxy && !playwright && bracketedIpv6Producer === null) return none; + const creator = log.creator; + if (!captureObject(creator) || !Array.isArray(log.entries)) return none; + const profile = HAR_PRODUCER_PROFILES.find( + ({ name, version }) => creator.name === name && creator.version === version, + ); + if (profile === undefined) return none; const failedRequests: number[] = []; const adaptedEntries: number[] = []; for (const [ordinal, entry] of log.entries.entries()) { @@ -151,7 +162,7 @@ const allowObservedProducerRepresentations = ( const response = candidate.response; const timings = candidate.timings; if ( - playwright && + profile.unavailableFailedRequestTimings && captureObject(response) && typeof response._failureText === "string" && response._failureText.length > 0 && @@ -167,27 +178,32 @@ const allowObservedProducerRepresentations = ( } const address = candidate.serverIPAddress; if ( - bracketedIpv6Producer !== null && + profile.bracketedIpv6 && typeof address === "string" && address.startsWith("[") && address.endsWith("]") && + !address.includes("%") && isIP(address.slice(1, -1)) === 6 ) { candidate.serverIPAddress = address.slice(1, -1); adaptedEntries.push(ordinal); } - if (!mitmproxy) continue; + if (!profile.nullPostDataText) continue; const request = candidate.request; if (!captureObject(request)) continue; const body = request.postData; if (captureObject(body) && body.text === null) delete body.text; } + const producer = profile.label ?? `${profile.name} ${profile.version}`; return { bracketedIpv6: - bracketedIpv6Producer === null + adaptedEntries.length === 0 ? null - : { producer: bracketedIpv6Producer, entries: adaptedEntries }, - failedRequests, + : { producer, entries: adaptedEntries }, + failedRequests: + failedRequests.length === 0 + ? null + : { producer, entries: failedRequests }, }; };