impl replay the mutations and mouse interactions

This commit is contained in:
Yanzhen Yu
2026-04-01 12:00:00 +08:00
parent f7e4a90751
commit f4ded6b6d1
3 changed files with 86 additions and 10 deletions

View File

@@ -1,3 +1,4 @@
import { idNodeMap, NodeType, serializeNodeWithId } from 'rrweb-snapshot';
import {
Mirror,
throttleOptions,
@@ -29,6 +30,26 @@ export const mirror: Mirror = {
},
};
// TODO: transform this into the snapshot repo
export function getIdNodeMap(doc: Document) {
const map: idNodeMap = {};
function walk(n: Node) {
const node = serializeNodeWithId(n, doc, map);
if (!node) {
return null;
}
if (node.type === NodeType.Document || node.type === NodeType.Element) {
for (const _n of Array.from(n.childNodes)) {
walk(_n);
}
}
}
walk(doc);
return map;
}
// copy from underscore and modified
export function throttle<T>(
func: (arg: T) => void,