refactor(domain): extract source-map envelope walk and disambiguate stringValue (#828)

Move the indexed sections walk shared by the browser fetcher and
the artifact reader into domain/sourceMapEnvelope with the
fetchers stricter offset validation as an option; both validators
keep their leaf strictness. Rename the browser CDP stringValue to
cdpStringValue across its 18 files, fold the fingerprint duplicate
into the static helper, and rename the version-keys shadow to
nonEmptyString.
This commit is contained in:
morluto
2026-10-07 11:23:37 +08:00
committed by GitHub
parent 6dd719eaf6
commit 64ebdf4501
24 changed files with 300 additions and 200 deletions
+10 -10
View File
@@ -14,7 +14,7 @@ import {
recordValue,
recordsValue,
requiredRecord,
stringValue,
cdpStringValue,
} from "./CdpCaptureValues.js";
import { walkFrameTrees } from "./CdpCaptureDocuments.js";
import {
@@ -220,9 +220,9 @@ const navigatedFrameId = (event: CdpEvent): string | undefined => {
const params = recordValue(event.params);
if (params === undefined) return undefined;
if (event.method === "Page.frameNavigated")
return stringValue(recordValue(params.frame)?.id);
return cdpStringValue(recordValue(params.frame)?.id);
if (event.method === "Page.navigatedWithinDocument")
return stringValue(params.frameId);
return cdpStringValue(params.frameId);
return undefined;
};
@@ -238,15 +238,15 @@ const captureFrames = async (
completeness.exclude("frames", "invalid_protocol_value"),
)) {
const frame = recordValue(tree.frame);
const frameId = stringValue(frame?.id);
const path = await authorizedElectronFile(stringValue(frame?.url) ?? "");
const frameId = cdpStringValue(frame?.id);
const path = await authorizedElectronFile(cdpStringValue(frame?.url) ?? "");
if (frameId === undefined || path === undefined) {
completeness.exclude("frames", "out_of_target_scope");
continue;
}
frames.push({
frame_id: frameId,
parent_frame_id: stringValue(frame?.parentId) ?? null,
parent_frame_id: cdpStringValue(frame?.parentId) ?? null,
file_path: path,
});
}
@@ -274,7 +274,7 @@ const captureResources = async (
if (tree === undefined) break;
for (const resource of recordsValue(tree.resources)) {
const path = await authorizedElectronFile(
stringValue(resource.url) ?? "",
cdpStringValue(resource.url) ?? "",
);
if (path === undefined) {
completeness.exclude("resources", "out_of_target_scope");
@@ -282,8 +282,8 @@ const captureResources = async (
}
const item = {
file_path: path,
type: stringValue(resource.type) ?? "Other",
mime_type: stringValue(resource.mimeType) ?? "",
type: cdpStringValue(resource.type) ?? "Other",
mime_type: cdpStringValue(resource.mimeType) ?? "",
content_size:
numberValue(resource.contentSize) === undefined
? null
@@ -358,7 +358,7 @@ const captureDom = async (
const mainFilePath = async (result: unknown): Promise<string | undefined> => {
const frameTree = recordValue(requiredRecord(result).frameTree);
const frame = recordValue(frameTree?.frame);
return await authorizedElectronFile(stringValue(frame?.url) ?? "");
return await authorizedElectronFile(cdpStringValue(frame?.url) ?? "");
};
const arrayValue = (value: unknown): readonly unknown[] =>