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