Files
reverse-engineering-anything/src/browser/execution/CdpRuntimeInitiator.ts
T
morluto af062e7a2d refactor(kernel): eliminate remaining record predicate copies and compose cleanup dependencies through shared owner (#11799)
* refactor(kernel): eliminate remaining record predicate copies and compose cleanup dependencies through shared owner

* fix(firmware,tests): remove unused cleanup import and align CI shard and CLI registration tests
2026-11-16 23:09:17 -05:00

31 lines
1.1 KiB
TypeScript

import type { WebExecution } from "../../domain/webExecution.js";
import { sanitizeBrowserUrl } from "../../domain/browserObservation.js";
import { isRecord } from "../../kernel/isRecord.js";
import type { CdpRuntimeSources } from "./CdpRuntimeSources.js";
type Initiator = WebExecution["requests"][number]["reported_initiator"];
const isObject = (value: Initiator[string] | undefined): value is Initiator =>
isRecord(value);
/** Sanitize known transport fields while retaining declarations and every unknown producer field. */
export const sanitizeRuntimeInitiator = (
initiator: Initiator,
sources: Pick<CdpRuntimeSources, "sourceUrl">,
): Initiator => {
if (typeof initiator.url === "string")
initiator.url = sanitizeBrowserUrl(initiator.url).url;
let stack = initiator.stack;
while (isObject(stack)) {
if (Array.isArray(stack.callFrames))
for (const frame of stack.callFrames)
if (
isObject(frame) &&
typeof frame.url === "string" &&
typeof frame.scriptId === "string"
)
frame.url = sources.sourceUrl(frame.scriptId, frame.url);
stack = stack.parent;
}
return initiator;
};