@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.
@@ -251,6 +251,91 @@ function isShadowRoot(n2) {
251
251
  function isNativeShadowDom(shadowRoot2) {
252
252
  return Object.prototype.toString.call(shadowRoot2) === "[object ShadowRoot]";
253
253
  }
254
+ function fixBrowserCompatibilityIssuesInCSS(cssText) {
255
+ if (cssText.includes(" background-clip: text;") && !cssText.includes(" -webkit-background-clip: text;")) {
256
+ cssText = cssText.replace(
257
+ /\sbackground-clip:\s*text;/g,
258
+ " -webkit-background-clip: text; background-clip: text;"
259
+ );
260
+ }
261
+ return cssText;
262
+ }
263
+ function escapeImportStatement(rule2) {
264
+ const { cssText } = rule2;
265
+ if (cssText.split('"').length < 3) return cssText;
266
+ const statement = ["@import", `url(${JSON.stringify(rule2.href)})`];
267
+ if (rule2.layerName === "") {
268
+ statement.push(`layer`);
269
+ } else if (rule2.layerName) {
270
+ statement.push(`layer(${rule2.layerName})`);
271
+ }
272
+ if (rule2.supportsText) {
273
+ statement.push(`supports(${rule2.supportsText})`);
274
+ }
275
+ if (rule2.media.length) {
276
+ statement.push(rule2.media.mediaText);
277
+ }
278
+ return statement.join(" ") + ";";
279
+ }
280
+ function stringifyStylesheet(s2) {
281
+ try {
282
+ const rules2 = s2.rules || s2.cssRules;
283
+ if (!rules2) {
284
+ return null;
285
+ }
286
+ let sheetHref = s2.href;
287
+ if (!sheetHref && s2.ownerNode) {
288
+ sheetHref = s2.ownerNode.baseURI;
289
+ }
290
+ const stringifiedRules = Array.from(
291
+ rules2,
292
+ (rule2) => stringifyRule(rule2, sheetHref)
293
+ ).join("");
294
+ return fixBrowserCompatibilityIssuesInCSS(stringifiedRules);
295
+ } catch (error) {
296
+ return null;
297
+ }
298
+ }
299
+ function stringifyRule(rule2, sheetHref) {
300
+ var _a2;
301
+ if (isCSSImportRule(rule2)) {
302
+ let importStringified;
303
+ try {
304
+ importStringified = // for same-origin stylesheets,
305
+ // we can access the imported stylesheet rules directly
306
+ stringifyStylesheet(rule2.styleSheet) || // work around browser issues with the raw string `@import url(...)` statement
307
+ escapeImportStatement(rule2);
308
+ } catch (error) {
309
+ importStringified = rule2.cssText;
310
+ }
311
+ try {
312
+ if (importStringified && ((_a2 = rule2.styleSheet) == null ? void 0 : _a2.href)) {
313
+ return absolutifyURLs(importStringified, rule2.styleSheet.href);
314
+ }
315
+ } catch (e) {
316
+ }
317
+ return importStringified;
318
+ } else {
319
+ let ruleStringified = rule2.cssText;
320
+ if (isCSSStyleRule(rule2) && rule2.selectorText.includes(":")) {
321
+ ruleStringified = fixSafariColons(ruleStringified);
322
+ }
323
+ if (sheetHref) {
324
+ return absolutifyURLs(ruleStringified, sheetHref);
325
+ }
326
+ return ruleStringified;
327
+ }
328
+ }
329
+ function fixSafariColons(cssStringified) {
330
+ const regex = /(\[(?:[\w-]+)[^\\])(:(?:[\w-]+)\])/gm;
331
+ return cssStringified.replace(regex, "$1\\$2");
332
+ }
333
+ function isCSSImportRule(rule2) {
334
+ return "styleSheet" in rule2;
335
+ }
336
+ function isCSSStyleRule(rule2) {
337
+ return "selectorText" in rule2;
338
+ }
254
339
  class Mirror {
255
340
  constructor() {
256
341
  __publicField$1(this, "idNodeMap", /* @__PURE__ */ new Map());
@@ -374,91 +459,6 @@ function extractFileExtension(path, baseURL) {
374
459
  const match = url.pathname.match(regex);
375
460
  return (_a2 = match == null ? void 0 : match[1]) != null ? _a2 : null;
376
461
  }
377
- function fixBrowserCompatibilityIssuesInCSS(cssText) {
378
- if (cssText.includes(" background-clip: text;") && !cssText.includes(" -webkit-background-clip: text;")) {
379
- cssText = cssText.replace(
380
- /\sbackground-clip:\s*text;/g,
381
- " -webkit-background-clip: text; background-clip: text;"
382
- );
383
- }
384
- return cssText;
385
- }
386
- function escapeImportStatement(rule2) {
387
- const { cssText } = rule2;
388
- if (cssText.split('"').length < 3) return cssText;
389
- const statement = ["@import", `url(${JSON.stringify(rule2.href)})`];
390
- if (rule2.layerName === "") {
391
- statement.push(`layer`);
392
- } else if (rule2.layerName) {
393
- statement.push(`layer(${rule2.layerName})`);
394
- }
395
- if (rule2.supportsText) {
396
- statement.push(`supports(${rule2.supportsText})`);
397
- }
398
- if (rule2.media.length) {
399
- statement.push(rule2.media.mediaText);
400
- }
401
- return statement.join(" ") + ";";
402
- }
403
- function stringifyStylesheet(s2) {
404
- try {
405
- const rules2 = s2.rules || s2.cssRules;
406
- if (!rules2) {
407
- return null;
408
- }
409
- let sheetHref = s2.href;
410
- if (!sheetHref && s2.ownerNode) {
411
- sheetHref = s2.ownerNode.baseURI;
412
- }
413
- const stringifiedRules = Array.from(
414
- rules2,
415
- (rule2) => stringifyRule(rule2, sheetHref)
416
- ).join("");
417
- return fixBrowserCompatibilityIssuesInCSS(stringifiedRules);
418
- } catch (error) {
419
- return null;
420
- }
421
- }
422
- function stringifyRule(rule2, sheetHref) {
423
- var _a2;
424
- if (isCSSImportRule(rule2)) {
425
- let importStringified;
426
- try {
427
- importStringified = // for same-origin stylesheets,
428
- // we can access the imported stylesheet rules directly
429
- stringifyStylesheet(rule2.styleSheet) || // work around browser issues with the raw string `@import url(...)` statement
430
- escapeImportStatement(rule2);
431
- } catch (error) {
432
- importStringified = rule2.cssText;
433
- }
434
- try {
435
- if (importStringified && ((_a2 = rule2.styleSheet) == null ? void 0 : _a2.href)) {
436
- return absolutifyURLs(importStringified, rule2.styleSheet.href);
437
- }
438
- } catch (e) {
439
- }
440
- return importStringified;
441
- } else {
442
- let ruleStringified = rule2.cssText;
443
- if (isCSSStyleRule(rule2) && rule2.selectorText.includes(":")) {
444
- ruleStringified = fixSafariColons(ruleStringified);
445
- }
446
- if (sheetHref) {
447
- return absolutifyURLs(ruleStringified, sheetHref);
448
- }
449
- return ruleStringified;
450
- }
451
- }
452
- function fixSafariColons(cssStringified) {
453
- const regex = /(\[(?:[\w-]+)[^\\])(:(?:[\w-]+)\])/gm;
454
- return cssStringified.replace(regex, "$1\\$2");
455
- }
456
- function isCSSImportRule(rule2) {
457
- return "styleSheet" in rule2;
458
- }
459
- function isCSSStyleRule(rule2) {
460
- return "selectorText" in rule2;
461
- }
462
462
  function extractOrigin(url) {
463
463
  let origin = "";
464
464
  if (url.indexOf("//") > -1) {
@@ -10337,6 +10337,11 @@ class MutationBuffer {
10337
10337
  this.shadowDomManager.reset();
10338
10338
  this.canvasManager.reset();
10339
10339
  }
10340
+ destroy() {
10341
+ while (this.mapRemoves.length) {
10342
+ this.mirror.removeNodeFromMap(this.mapRemoves.shift());
10343
+ }
10344
+ }
10340
10345
  }
10341
10346
  function deepDelete(addsSet, n2) {
10342
10347
  addsSet.delete(n2);
@@ -11381,6 +11386,7 @@ function initObservers(o2, hooks = {}) {
11381
11386
  );
11382
11387
  }
11383
11388
  return callbackWrapper(() => {
11389
+ mutationBuffers.forEach((b) => b.destroy());
11384
11390
  mutationBuffers.forEach((b) => b.reset());
11385
11391
  mutationObserver == null ? void 0 : mutationObserver.disconnect();
11386
11392
  mousemoveHandler();
@@ -11718,6 +11724,8 @@ class IframeManager {
11718
11724
  contentWindow.removeEventListener("message", handler);
11719
11725
  });
11720
11726
  this.nestedIframeListeners.clear();
11727
+ this.crossOriginIframeMirror.reset();
11728
+ this.crossOriginIframeStyleMirror.reset();
11721
11729
  }
11722
11730
  }
11723
11731
  class ShadowDomManager {
@@ -12174,6 +12182,8 @@ class CanvasManager {
12174
12182
  __publicField(this, "resetObservers");
12175
12183
  __publicField(this, "frozen", false);
12176
12184
  __publicField(this, "locked", false);
12185
+ __publicField(this, "rafIdTimestamp", null);
12186
+ __publicField(this, "rafIdFlush", null);
12177
12187
  __publicField(this, "processMutation", (target, mutation) => {
12178
12188
  const newFrame = this.rafStamps.invokeId && this.rafStamps.latestId !== this.rafStamps.invokeId;
12179
12189
  if (newFrame || !this.rafStamps.invokeId)
@@ -12208,6 +12218,14 @@ class CanvasManager {
12208
12218
  reset() {
12209
12219
  this.pendingCanvasMutations.clear();
12210
12220
  this.resetObservers && this.resetObservers();
12221
+ if (this.rafIdTimestamp !== null) {
12222
+ cancelAnimationFrame(this.rafIdTimestamp);
12223
+ this.rafIdTimestamp = null;
12224
+ }
12225
+ if (this.rafIdFlush !== null) {
12226
+ cancelAnimationFrame(this.rafIdFlush);
12227
+ this.rafIdFlush = null;
12228
+ }
12211
12229
  }
12212
12230
  freeze() {
12213
12231
  this.frozen = true;
@@ -12358,14 +12376,16 @@ class CanvasManager {
12358
12376
  };
12359
12377
  }
12360
12378
  startPendingCanvasMutationFlusher() {
12361
- requestAnimationFrame(() => this.flushPendingCanvasMutations());
12379
+ this.rafIdFlush = requestAnimationFrame(
12380
+ () => this.flushPendingCanvasMutations()
12381
+ );
12362
12382
  }
12363
12383
  startRAFTimestamping() {
12364
12384
  const setLatestRAFTimestamp = (timestamp) => {
12365
12385
  this.rafStamps.latestId = timestamp;
12366
- requestAnimationFrame(setLatestRAFTimestamp);
12386
+ this.rafIdTimestamp = requestAnimationFrame(setLatestRAFTimestamp);
12367
12387
  };
12368
- requestAnimationFrame(setLatestRAFTimestamp);
12388
+ this.rafIdTimestamp = requestAnimationFrame(setLatestRAFTimestamp);
12369
12389
  }
12370
12390
  flushPendingCanvasMutations() {
12371
12391
  this.pendingCanvasMutations.forEach(
@@ -12374,7 +12394,9 @@ class CanvasManager {
12374
12394
  this.flushPendingCanvasMutationFor(canvas, id);
12375
12395
  }
12376
12396
  );
12377
- requestAnimationFrame(() => this.flushPendingCanvasMutations());
12397
+ this.rafIdFlush = requestAnimationFrame(
12398
+ () => this.flushPendingCanvasMutations()
12399
+ );
12378
12400
  }
12379
12401
  flushPendingCanvasMutationFor(canvas, id) {
12380
12402
  if (this.frozen || this.locked) {
@@ -12940,6 +12962,7 @@ function record(options = {}) {
12940
12962
  processedNodeManager.destroy();
12941
12963
  iframeManager.removeLoadListener();
12942
12964
  iframeManager.destroy();
12965
+ mirror.reset();
12943
12966
  recording = false;
12944
12967
  unregisterErrorHandler();
12945
12968
  };