MCPcopy
hub / github.com/rrweb-io/rrweb / stringifySnapshots

Function stringifySnapshots

packages/rrweb/test/utils.ts:108–249  ·  view source on GitHub ↗
(snapshots: eventWithTime[])

Source from the content-addressed store, hash-verified

106 * @param snapshots incrementalSnapshotEvent[]
107 */
108export function stringifySnapshots(snapshots: eventWithTime[]): string {
109 return JSON.stringify(
110 snapshots
111 .filter((s) => {
112 if (
113 // mouse move or viewport resize can happen on accidental user interference
114 // so we ignore them
115 (s.type === EventType.IncrementalSnapshot &&
116 (s.data.source === IncrementalSource.MouseMove ||
117 s.data.source === IncrementalSource.ViewportResize)) ||
118 // ignore '[vite] connected' messages from vite
119 (s.type === EventType.Plugin &&
120 s.data.plugin === 'rrweb/console@1' &&
121 (s.data.payload as { payload: string[] })?.payload?.find((msg) =>
122 msg.includes('[vite] connected'),
123 ))
124 ) {
125 return false;
126 }
127 return true;
128 })
129 .map((s) => {
130 if (s.type === EventType.Meta) {
131 s.data.href = 'about:blank';
132 }
133 // FIXME: travis coordinates seems different with my laptop
134 const coordinatesReg =
135 /(bottom|top|left|right|width|height): \d+(\.\d+)?px/g;
136 if (
137 s.type === EventType.IncrementalSnapshot &&
138 s.data.source === IncrementalSource.MouseInteraction
139 ) {
140 delete (s.data as Optional<mouseInteractionData, 'x'>).x;
141 delete (s.data as Optional<mouseInteractionData, 'y'>).y;
142 }
143 if (
144 s.type === EventType.IncrementalSnapshot &&
145 s.data.source === IncrementalSource.Mutation
146 ) {
147 s.data.attributes.forEach((a) => {
148 if ('style' in a.attributes && a.attributes.style) {
149 if (typeof a.attributes.style === 'object') {
150 for (const [k, v] of Object.entries(a.attributes.style)) {
151 if (Array.isArray(v)) {
152 if (coordinatesReg.test(k + ': ' + v[0])) {
153 // TODO: could round the number here instead depending on what's coming out of various test envs
154 a.attributes.style[k] = ['Npx', v[1]];
155 }
156 } else if (typeof v === 'string') {
157 if (coordinatesReg.test(k + ': ' + v)) {
158 a.attributes.style[k] = 'Npx';
159 }
160 }
161 coordinatesReg.lastIndex = 0; // wow, a real wart in ECMAScript
162 }
163 } else if (coordinatesReg.test(a.attributes.style)) {
164 a.attributes.style = a.attributes.style.replace(
165 coordinatesReg,

Callers 1

assertSnapshotFunction · 0.70

Calls 2

replaceMethod · 0.65

Tested by

no test coverage detected