@posthog/rrweb-record 0.0.28 → 0.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -207,6 +207,91 @@ function isShadowRoot(n2) {
207
207
  function isNativeShadowDom(shadowRoot2) {
208
208
  return Object.prototype.toString.call(shadowRoot2) === "[object ShadowRoot]";
209
209
  }
210
+ function fixBrowserCompatibilityIssuesInCSS(cssText) {
211
+ if (cssText.includes(" background-clip: text;") && !cssText.includes(" -webkit-background-clip: text;")) {
212
+ cssText = cssText.replace(
213
+ /\sbackground-clip:\s*text;/g,
214
+ " -webkit-background-clip: text; background-clip: text;"
215
+ );
216
+ }
217
+ return cssText;
218
+ }
219
+ function escapeImportStatement(rule2) {
220
+ const { cssText } = rule2;
221
+ if (cssText.split('"').length < 3) return cssText;
222
+ const statement = ["@import", `url(${JSON.stringify(rule2.href)})`];
223
+ if (rule2.layerName === "") {
224
+ statement.push(`layer`);
225
+ } else if (rule2.layerName) {
226
+ statement.push(`layer(${rule2.layerName})`);
227
+ }
228
+ if (rule2.supportsText) {
229
+ statement.push(`supports(${rule2.supportsText})`);
230
+ }
231
+ if (rule2.media.length) {
232
+ statement.push(rule2.media.mediaText);
233
+ }
234
+ return statement.join(" ") + ";";
235
+ }
236
+ function stringifyStylesheet(s2) {
237
+ try {
238
+ const rules2 = s2.rules || s2.cssRules;
239
+ if (!rules2) {
240
+ return null;
241
+ }
242
+ let sheetHref = s2.href;
243
+ if (!sheetHref && s2.ownerNode) {
244
+ sheetHref = s2.ownerNode.baseURI;
245
+ }
246
+ const stringifiedRules = Array.from(
247
+ rules2,
248
+ (rule2) => stringifyRule(rule2, sheetHref)
249
+ ).join("");
250
+ return fixBrowserCompatibilityIssuesInCSS(stringifiedRules);
251
+ } catch (error) {
252
+ return null;
253
+ }
254
+ }
255
+ function stringifyRule(rule2, sheetHref) {
256
+ var _a2;
257
+ if (isCSSImportRule(rule2)) {
258
+ let importStringified;
259
+ try {
260
+ importStringified = // for same-origin stylesheets,
261
+ // we can access the imported stylesheet rules directly
262
+ stringifyStylesheet(rule2.styleSheet) || // work around browser issues with the raw string `@import url(...)` statement
263
+ escapeImportStatement(rule2);
264
+ } catch (error) {
265
+ importStringified = rule2.cssText;
266
+ }
267
+ try {
268
+ if (importStringified && ((_a2 = rule2.styleSheet) == null ? void 0 : _a2.href)) {
269
+ return absolutifyURLs(importStringified, rule2.styleSheet.href);
270
+ }
271
+ } catch {
272
+ }
273
+ return importStringified;
274
+ } else {
275
+ let ruleStringified = rule2.cssText;
276
+ if (isCSSStyleRule(rule2) && rule2.selectorText.includes(":")) {
277
+ ruleStringified = fixSafariColons(ruleStringified);
278
+ }
279
+ if (sheetHref) {
280
+ return absolutifyURLs(ruleStringified, sheetHref);
281
+ }
282
+ return ruleStringified;
283
+ }
284
+ }
285
+ function fixSafariColons(cssStringified) {
286
+ const regex = /(\[(?:[\w-]+)[^\\])(:(?:[\w-]+)\])/gm;
287
+ return cssStringified.replace(regex, "$1\\$2");
288
+ }
289
+ function isCSSImportRule(rule2) {
290
+ return "styleSheet" in rule2;
291
+ }
292
+ function isCSSStyleRule(rule2) {
293
+ return "selectorText" in rule2;
294
+ }
210
295
  class Mirror {
211
296
  constructor() {
212
297
  __publicField$1(this, "idNodeMap", /* @__PURE__ */ new Map());
@@ -329,91 +414,6 @@ function extractFileExtension(path, baseURL) {
329
414
  const match = url.pathname.match(regex);
330
415
  return (match == null ? void 0 : match[1]) ?? null;
331
416
  }
332
- function fixBrowserCompatibilityIssuesInCSS(cssText) {
333
- if (cssText.includes(" background-clip: text;") && !cssText.includes(" -webkit-background-clip: text;")) {
334
- cssText = cssText.replace(
335
- /\sbackground-clip:\s*text;/g,
336
- " -webkit-background-clip: text; background-clip: text;"
337
- );
338
- }
339
- return cssText;
340
- }
341
- function escapeImportStatement(rule2) {
342
- const { cssText } = rule2;
343
- if (cssText.split('"').length < 3) return cssText;
344
- const statement = ["@import", `url(${JSON.stringify(rule2.href)})`];
345
- if (rule2.layerName === "") {
346
- statement.push(`layer`);
347
- } else if (rule2.layerName) {
348
- statement.push(`layer(${rule2.layerName})`);
349
- }
350
- if (rule2.supportsText) {
351
- statement.push(`supports(${rule2.supportsText})`);
352
- }
353
- if (rule2.media.length) {
354
- statement.push(rule2.media.mediaText);
355
- }
356
- return statement.join(" ") + ";";
357
- }
358
- function stringifyStylesheet(s2) {
359
- try {
360
- const rules2 = s2.rules || s2.cssRules;
361
- if (!rules2) {
362
- return null;
363
- }
364
- let sheetHref = s2.href;
365
- if (!sheetHref && s2.ownerNode) {
366
- sheetHref = s2.ownerNode.baseURI;
367
- }
368
- const stringifiedRules = Array.from(
369
- rules2,
370
- (rule2) => stringifyRule(rule2, sheetHref)
371
- ).join("");
372
- return fixBrowserCompatibilityIssuesInCSS(stringifiedRules);
373
- } catch (error) {
374
- return null;
375
- }
376
- }
377
- function stringifyRule(rule2, sheetHref) {
378
- var _a2;
379
- if (isCSSImportRule(rule2)) {
380
- let importStringified;
381
- try {
382
- importStringified = // for same-origin stylesheets,
383
- // we can access the imported stylesheet rules directly
384
- stringifyStylesheet(rule2.styleSheet) || // work around browser issues with the raw string `@import url(...)` statement
385
- escapeImportStatement(rule2);
386
- } catch (error) {
387
- importStringified = rule2.cssText;
388
- }
389
- try {
390
- if (importStringified && ((_a2 = rule2.styleSheet) == null ? void 0 : _a2.href)) {
391
- return absolutifyURLs(importStringified, rule2.styleSheet.href);
392
- }
393
- } catch {
394
- }
395
- return importStringified;
396
- } else {
397
- let ruleStringified = rule2.cssText;
398
- if (isCSSStyleRule(rule2) && rule2.selectorText.includes(":")) {
399
- ruleStringified = fixSafariColons(ruleStringified);
400
- }
401
- if (sheetHref) {
402
- return absolutifyURLs(ruleStringified, sheetHref);
403
- }
404
- return ruleStringified;
405
- }
406
- }
407
- function fixSafariColons(cssStringified) {
408
- const regex = /(\[(?:[\w-]+)[^\\])(:(?:[\w-]+)\])/gm;
409
- return cssStringified.replace(regex, "$1\\$2");
410
- }
411
- function isCSSImportRule(rule2) {
412
- return "styleSheet" in rule2;
413
- }
414
- function isCSSStyleRule(rule2) {
415
- return "selectorText" in rule2;
416
- }
417
417
  function extractOrigin(url) {
418
418
  let origin = "";
419
419
  if (url.indexOf("//") > -1) {
@@ -10293,6 +10293,11 @@ class MutationBuffer {
10293
10293
  this.shadowDomManager.reset();
10294
10294
  this.canvasManager.reset();
10295
10295
  }
10296
+ destroy() {
10297
+ while (this.mapRemoves.length) {
10298
+ this.mirror.removeNodeFromMap(this.mapRemoves.shift());
10299
+ }
10300
+ }
10296
10301
  }
10297
10302
  function deepDelete(addsSet, n2) {
10298
10303
  addsSet.delete(n2);
@@ -11339,6 +11344,7 @@ function initObservers(o2, hooks = {}) {
11339
11344
  );
11340
11345
  }
11341
11346
  return callbackWrapper(() => {
11347
+ mutationBuffers.forEach((b) => b.destroy());
11342
11348
  mutationBuffers.forEach((b) => b.reset());
11343
11349
  mutationObserver == null ? void 0 : mutationObserver.disconnect();
11344
11350
  mousemoveHandler();
@@ -11676,6 +11682,8 @@ class IframeManager {
11676
11682
  contentWindow.removeEventListener("message", handler);
11677
11683
  });
11678
11684
  this.nestedIframeListeners.clear();
11685
+ this.crossOriginIframeMirror.reset();
11686
+ this.crossOriginIframeStyleMirror.reset();
11679
11687
  }
11680
11688
  }
11681
11689
  class ShadowDomManager {
@@ -12134,6 +12142,8 @@ class CanvasManager {
12134
12142
  __publicField(this, "resetObservers");
12135
12143
  __publicField(this, "frozen", false);
12136
12144
  __publicField(this, "locked", false);
12145
+ __publicField(this, "rafIdTimestamp", null);
12146
+ __publicField(this, "rafIdFlush", null);
12137
12147
  __publicField(this, "processMutation", (target, mutation) => {
12138
12148
  const newFrame = this.rafStamps.invokeId && this.rafStamps.latestId !== this.rafStamps.invokeId;
12139
12149
  if (newFrame || !this.rafStamps.invokeId)
@@ -12168,6 +12178,14 @@ class CanvasManager {
12168
12178
  reset() {
12169
12179
  this.pendingCanvasMutations.clear();
12170
12180
  this.resetObservers && this.resetObservers();
12181
+ if (this.rafIdTimestamp !== null) {
12182
+ cancelAnimationFrame(this.rafIdTimestamp);
12183
+ this.rafIdTimestamp = null;
12184
+ }
12185
+ if (this.rafIdFlush !== null) {
12186
+ cancelAnimationFrame(this.rafIdFlush);
12187
+ this.rafIdFlush = null;
12188
+ }
12171
12189
  }
12172
12190
  freeze() {
12173
12191
  this.frozen = true;
@@ -12318,14 +12336,16 @@ class CanvasManager {
12318
12336
  };
12319
12337
  }
12320
12338
  startPendingCanvasMutationFlusher() {
12321
- requestAnimationFrame(() => this.flushPendingCanvasMutations());
12339
+ this.rafIdFlush = requestAnimationFrame(
12340
+ () => this.flushPendingCanvasMutations()
12341
+ );
12322
12342
  }
12323
12343
  startRAFTimestamping() {
12324
12344
  const setLatestRAFTimestamp = (timestamp) => {
12325
12345
  this.rafStamps.latestId = timestamp;
12326
- requestAnimationFrame(setLatestRAFTimestamp);
12346
+ this.rafIdTimestamp = requestAnimationFrame(setLatestRAFTimestamp);
12327
12347
  };
12328
- requestAnimationFrame(setLatestRAFTimestamp);
12348
+ this.rafIdTimestamp = requestAnimationFrame(setLatestRAFTimestamp);
12329
12349
  }
12330
12350
  flushPendingCanvasMutations() {
12331
12351
  this.pendingCanvasMutations.forEach(
@@ -12334,7 +12354,9 @@ class CanvasManager {
12334
12354
  this.flushPendingCanvasMutationFor(canvas, id);
12335
12355
  }
12336
12356
  );
12337
- requestAnimationFrame(() => this.flushPendingCanvasMutations());
12357
+ this.rafIdFlush = requestAnimationFrame(
12358
+ () => this.flushPendingCanvasMutations()
12359
+ );
12338
12360
  }
12339
12361
  flushPendingCanvasMutationFor(canvas, id) {
12340
12362
  if (this.frozen || this.locked) {
@@ -12913,6 +12935,7 @@ function record(options = {}) {
12913
12935
  processedNodeManager.destroy();
12914
12936
  iframeManager.removeLoadListener();
12915
12937
  iframeManager.destroy();
12938
+ mirror.reset();
12916
12939
  recording = false;
12917
12940
  unregisterErrorHandler();
12918
12941
  };