fix(observation): validate document consistency during capture

This commit is contained in:
Ljy-0827
2026-09-09 15:58:40 +08:00
committed by drakezhang
parent eefbe03258
commit df5ed1a495
8 changed files with 135 additions and 0 deletions
@@ -21,6 +21,7 @@ export interface FrameContext {
export interface NormalizedDocument {
nodes: NodeFacts[];
index: DocumentIndex;
documentElementBackendNodeId?: number;
}
/** Interpret one document using a supplied projection. No live reads or frame scheduling. */
@@ -74,5 +75,11 @@ export async function normalizeDocument(
(node) => !node.tag.startsWith("#") && !index.excludedBackendNodeIds.has(node.backendNodeId),
),
index,
documentElementBackendNodeId: nodes.find(
(node) =>
node.nodeType === 1 &&
node.parentBackendNodeId !== null &&
index.nodes.get(node.parentBackendNodeId)?.nodeType === 9,
)?.backendNodeId,
};
}