refactor(browser): return complete observation evidence

This commit is contained in:
morluto committed 2026-09-29 13:56:49 +08:00
1 parent 9d1f88cbe8
commit 0e2738ffb6
69 files changed
+747 -1206

No files matched your search

+7 -26
View File
@@ -1,11 +1,6 @@
import type { CdpEvent } from "./CdpConnection.js";
import { CdpCaptureCompleteness } from "./CdpCaptureCompleteness.js";
import {
boundedText,
numberValue,
recordValue,
stringValue,
} from "./CdpCaptureValues.js";
import { numberValue, recordValue, stringValue } from "./CdpCaptureValues.js";
export interface ElectronScriptDraft {
readonly scriptId: string;
@@ -17,7 +12,7 @@ export interface ElectronScriptDraft {
readonly executionContextKey: string | null;
}
/** Retain only bounded script/frame metadata from passive Electron events. */
/** Retain script/frame metadata from passive Electron events. */
export const ingestElectronScriptEvent = (input: {
readonly event: CdpEvent;
readonly scripts: ElectronScriptDraft[];
@@ -35,18 +30,14 @@ export const ingestElectronScriptEvent = (input: {
return;
}
if (input.event.method === "Runtime.executionContextCreated") {
retainExecutionContext(
input.event,
input.executionContextFrames,
input.completeness,
);
retainExecutionContext(input.event, input.executionContextFrames);
return;
}
if (input.event.method !== "Debugger.scriptParsed") return;
const value = recordValue(input.event.params);
const scriptId = stringValue(value?.scriptId);
const rawUrl = stringValue(value?.url);
if (scriptId === undefined || scriptId.length > 256) {
if (scriptId === undefined) {
input.completeness.exclude("scripts", "invalid_protocol_value");
return;
}
@@ -54,17 +45,13 @@ export const ingestElectronScriptEvent = (input: {
input.completeness.exclude("scripts", "unattributed_origin");
return;
}
if (input.scripts.length >= 2_000) {
input.completeness.drop("scripts");
return;
}
input.scripts.push({
scriptId,
rawUrl,
hash: (stringValue(value?.hash) ?? "").slice(0, 512),
hash: stringValue(value?.hash) ?? "",
length: nonnegativeInteger(value?.length),
isModule: value?.isModule === true,
language: boundedText(value?.scriptLanguage, 100),
language: stringValue(value?.scriptLanguage) ?? null,
executionContextKey: executionContextKey(value?.executionContextId),
});
};
@@ -72,18 +59,12 @@ export const ingestElectronScriptEvent = (input: {
const retainExecutionContext = (
event: CdpEvent,
frames: Map<string, string>,
completeness: CdpCaptureCompleteness,
): void => {
const parameters = recordValue(event.params);
const runtimeContext = recordValue(parameters?.context);
const contextKey = executionContextKey(runtimeContext?.id);
const frameId = stringValue(recordValue(runtimeContext?.auxData)?.frameId);
if (contextKey === null || frameId === undefined || frameId.length > 256)
return;
if (frames.size >= 2_000 && !frames.has(contextKey)) {
completeness.truncate("scripts");
return;
}
if (contextKey === null || frameId === undefined) return;
frames.set(contextKey, frameId);
};