@posthog/rrweb 0.0.26 → 0.0.28

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,91 +251,6 @@ 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 (e2) {
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
- }
339
254
  class Mirror {
340
255
  constructor() {
341
256
  __publicField$1(this, "idNodeMap", /* @__PURE__ */ new Map());
@@ -471,6 +386,91 @@ function extractFileExtension(path, baseURL) {
471
386
  const match = url.pathname.match(regex);
472
387
  return (_a2 = match == null ? void 0 : match[1]) != null ? _a2 : null;
473
388
  }
389
+ function fixBrowserCompatibilityIssuesInCSS(cssText) {
390
+ if (cssText.includes(" background-clip: text;") && !cssText.includes(" -webkit-background-clip: text;")) {
391
+ cssText = cssText.replace(
392
+ /\sbackground-clip:\s*text;/g,
393
+ " -webkit-background-clip: text; background-clip: text;"
394
+ );
395
+ }
396
+ return cssText;
397
+ }
398
+ function escapeImportStatement(rule2) {
399
+ const { cssText } = rule2;
400
+ if (cssText.split('"').length < 3) return cssText;
401
+ const statement = ["@import", `url(${JSON.stringify(rule2.href)})`];
402
+ if (rule2.layerName === "") {
403
+ statement.push(`layer`);
404
+ } else if (rule2.layerName) {
405
+ statement.push(`layer(${rule2.layerName})`);
406
+ }
407
+ if (rule2.supportsText) {
408
+ statement.push(`supports(${rule2.supportsText})`);
409
+ }
410
+ if (rule2.media.length) {
411
+ statement.push(rule2.media.mediaText);
412
+ }
413
+ return statement.join(" ") + ";";
414
+ }
415
+ function stringifyStylesheet(s2) {
416
+ try {
417
+ const rules2 = s2.rules || s2.cssRules;
418
+ if (!rules2) {
419
+ return null;
420
+ }
421
+ let sheetHref = s2.href;
422
+ if (!sheetHref && s2.ownerNode) {
423
+ sheetHref = s2.ownerNode.baseURI;
424
+ }
425
+ const stringifiedRules = Array.from(
426
+ rules2,
427
+ (rule2) => stringifyRule(rule2, sheetHref)
428
+ ).join("");
429
+ return fixBrowserCompatibilityIssuesInCSS(stringifiedRules);
430
+ } catch (error) {
431
+ return null;
432
+ }
433
+ }
434
+ function stringifyRule(rule2, sheetHref) {
435
+ var _a2;
436
+ if (isCSSImportRule(rule2)) {
437
+ let importStringified;
438
+ try {
439
+ importStringified = // for same-origin stylesheets,
440
+ // we can access the imported stylesheet rules directly
441
+ stringifyStylesheet(rule2.styleSheet) || // work around browser issues with the raw string `@import url(...)` statement
442
+ escapeImportStatement(rule2);
443
+ } catch (error) {
444
+ importStringified = rule2.cssText;
445
+ }
446
+ try {
447
+ if (importStringified && ((_a2 = rule2.styleSheet) == null ? void 0 : _a2.href)) {
448
+ return absolutifyURLs(importStringified, rule2.styleSheet.href);
449
+ }
450
+ } catch (e2) {
451
+ }
452
+ return importStringified;
453
+ } else {
454
+ let ruleStringified = rule2.cssText;
455
+ if (isCSSStyleRule(rule2) && rule2.selectorText.includes(":")) {
456
+ ruleStringified = fixSafariColons(ruleStringified);
457
+ }
458
+ if (sheetHref) {
459
+ return absolutifyURLs(ruleStringified, sheetHref);
460
+ }
461
+ return ruleStringified;
462
+ }
463
+ }
464
+ function fixSafariColons(cssStringified) {
465
+ const regex = /(\[(?:[\w-]+)[^\\])(:(?:[\w-]+)\])/gm;
466
+ return cssStringified.replace(regex, "$1\\$2");
467
+ }
468
+ function isCSSImportRule(rule2) {
469
+ return "styleSheet" in rule2;
470
+ }
471
+ function isCSSStyleRule(rule2) {
472
+ return "selectorText" in rule2;
473
+ }
474
474
  function extractOrigin(url) {
475
475
  let origin = "";
476
476
  if (url.indexOf("//") > -1) {
@@ -5376,6 +5376,22 @@ postcss$1.Input;
5376
5376
  postcss$1.Rule;
5377
5377
  postcss$1.Root;
5378
5378
  postcss$1.Node;
5379
+ function adaptCssForReplay(cssText, cache) {
5380
+ const cachedStyle = cache == null ? void 0 : cache.stylesWithHoverClass.get(cssText);
5381
+ if (cachedStyle) return cachedStyle;
5382
+ let result2 = cssText;
5383
+ try {
5384
+ const ast = postcss$1([
5385
+ mediaSelectorPlugin,
5386
+ pseudoClassPlugin
5387
+ ]).process(cssText, { parser: safeParser });
5388
+ result2 = ast.css;
5389
+ } catch (error) {
5390
+ console.warn("Failed to adapt css for replay", error);
5391
+ }
5392
+ cache == null ? void 0 : cache.stylesWithHoverClass.set(cssText, result2);
5393
+ return result2;
5394
+ }
5379
5395
  const tagMap = {
5380
5396
  script: "noscript",
5381
5397
  // camel case svg element tag names
@@ -5423,22 +5439,6 @@ function getTagName(n2) {
5423
5439
  }
5424
5440
  return tagName;
5425
5441
  }
5426
- function adaptCssForReplay(cssText, cache) {
5427
- const cachedStyle = cache == null ? void 0 : cache.stylesWithHoverClass.get(cssText);
5428
- if (cachedStyle) return cachedStyle;
5429
- let result2 = cssText;
5430
- try {
5431
- const ast = postcss$1([
5432
- mediaSelectorPlugin,
5433
- pseudoClassPlugin
5434
- ]).process(cssText, { parser: safeParser });
5435
- result2 = ast.css;
5436
- } catch (error) {
5437
- console.warn("Failed to adapt css for replay", error);
5438
- }
5439
- cache == null ? void 0 : cache.stylesWithHoverClass.set(cssText, result2);
5440
- return result2;
5441
- }
5442
5442
  function createCache() {
5443
5443
  const stylesWithHoverClass = /* @__PURE__ */ new Map();
5444
5444
  return {
@@ -13363,6 +13363,9 @@ class IframeManager {
13363
13363
  addLoadListener(cb) {
13364
13364
  this.loadListener = cb;
13365
13365
  }
13366
+ removeLoadListener() {
13367
+ this.loadListener = void 0;
13368
+ }
13366
13369
  attachIframe(iframeEl, childSn) {
13367
13370
  var _a2;
13368
13371
  this.mutationCb({
@@ -13736,9 +13739,9 @@ const saveWebGLVar = (value, win, ctx) => {
13736
13739
  }
13737
13740
  return index2;
13738
13741
  };
13739
- function serializeArg(value, win, ctx) {
13742
+ function serializeArg(value, win, ctx, dataURLOptions) {
13740
13743
  if (value instanceof Array) {
13741
- return value.map((arg) => serializeArg(arg, win, ctx));
13744
+ return value.map((arg) => serializeArg(arg, win, ctx, dataURLOptions));
13742
13745
  } else if (value === null) {
13743
13746
  return value;
13744
13747
  } else if (value instanceof Float32Array || value instanceof Float64Array || value instanceof Int32Array || value instanceof Uint32Array || value instanceof Uint8Array || value instanceof Uint16Array || value instanceof Int16Array || value instanceof Int8Array || value instanceof Uint8ClampedArray) {
@@ -13764,7 +13767,7 @@ function serializeArg(value, win, ctx) {
13764
13767
  return {
13765
13768
  rr_type: name,
13766
13769
  args: [
13767
- serializeArg(value.buffer, win, ctx),
13770
+ serializeArg(value.buffer, win, ctx, dataURLOptions),
13768
13771
  value.byteOffset,
13769
13772
  value.byteLength
13770
13773
  ]
@@ -13778,7 +13781,7 @@ function serializeArg(value, win, ctx) {
13778
13781
  };
13779
13782
  } else if (value instanceof HTMLCanvasElement) {
13780
13783
  const name = "HTMLImageElement";
13781
- const src = value.toDataURL();
13784
+ const src = value.toDataURL(dataURLOptions.type, dataURLOptions.quality);
13782
13785
  return {
13783
13786
  rr_type: name,
13784
13787
  src
@@ -13787,7 +13790,11 @@ function serializeArg(value, win, ctx) {
13787
13790
  const name = value.constructor.name;
13788
13791
  return {
13789
13792
  rr_type: name,
13790
- args: [serializeArg(value.data, win, ctx), value.width, value.height]
13793
+ args: [
13794
+ serializeArg(value.data, win, ctx, dataURLOptions),
13795
+ value.width,
13796
+ value.height
13797
+ ]
13791
13798
  };
13792
13799
  } else if (isInstanceOfWebGLObject(value, win) || typeof value === "object") {
13793
13800
  const name = value.constructor.name;
@@ -13799,8 +13806,8 @@ function serializeArg(value, win, ctx) {
13799
13806
  }
13800
13807
  return value;
13801
13808
  }
13802
- const serializeArgs = (args, win, ctx) => {
13803
- return args.map((arg) => serializeArg(arg, win, ctx));
13809
+ const serializeArgs = (args, win, ctx, dataURLOptions) => {
13810
+ return args.map((arg) => serializeArg(arg, win, ctx, dataURLOptions));
13804
13811
  };
13805
13812
  const isInstanceOfWebGLObject = (value, win) => {
13806
13813
  const webGLConstructorNames = [
@@ -13826,7 +13833,7 @@ const isInstanceOfWebGLObject = (value, win) => {
13826
13833
  )
13827
13834
  );
13828
13835
  };
13829
- function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector) {
13836
+ function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector, dataURLOptions) {
13830
13837
  const handlers = [];
13831
13838
  const props2D = Object.getOwnPropertyNames(
13832
13839
  win.CanvasRenderingContext2D.prototype
@@ -13843,7 +13850,12 @@ function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector) {
13843
13850
  return function(...args) {
13844
13851
  if (!isBlocked(this.canvas, blockClass, blockSelector, true)) {
13845
13852
  setTimeout(() => {
13846
- const recordArgs = serializeArgs(args, win, this);
13853
+ const recordArgs = serializeArgs(
13854
+ args,
13855
+ win,
13856
+ this,
13857
+ dataURLOptions
13858
+ );
13847
13859
  cb(this.canvas, {
13848
13860
  type: CanvasContext["2D"],
13849
13861
  property: prop,
@@ -13917,7 +13929,7 @@ function initCanvasContextObserver(win, blockClass, blockSelector, setPreserveDr
13917
13929
  handlers.forEach((h) => h());
13918
13930
  };
13919
13931
  }
13920
- function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win) {
13932
+ function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win, dataURLOptions) {
13921
13933
  const handlers = [];
13922
13934
  const props = Object.getOwnPropertyNames(prototype);
13923
13935
  for (const prop of props) {
@@ -13944,7 +13956,7 @@ function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win) {
13944
13956
  const result2 = original.apply(this, args);
13945
13957
  saveWebGLVar(result2, win, this);
13946
13958
  if ("tagName" in this.canvas && !isBlocked(this.canvas, blockClass, blockSelector, true)) {
13947
- const recordArgs = serializeArgs(args, win, this);
13959
+ const recordArgs = serializeArgs(args, win, this, dataURLOptions);
13948
13960
  const mutation = {
13949
13961
  type,
13950
13962
  property: prop,
@@ -13973,7 +13985,7 @@ function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win) {
13973
13985
  }
13974
13986
  return handlers;
13975
13987
  }
13976
- function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector) {
13988
+ function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector, dataURLOptions) {
13977
13989
  const handlers = [];
13978
13990
  handlers.push(
13979
13991
  ...patchGLPrototype(
@@ -13982,7 +13994,8 @@ function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector) {
13982
13994
  cb,
13983
13995
  blockClass,
13984
13996
  blockSelector,
13985
- win
13997
+ win,
13998
+ dataURLOptions
13986
13999
  )
13987
14000
  );
13988
14001
  if (typeof win.WebGL2RenderingContext !== "undefined") {
@@ -13993,7 +14006,8 @@ function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector) {
13993
14006
  cb,
13994
14007
  blockClass,
13995
14008
  blockSelector,
13996
- win
14009
+ win,
14010
+ dataURLOptions
13997
14011
  )
13998
14012
  );
13999
14013
  }
@@ -14055,7 +14069,12 @@ class CanvasManager {
14055
14069
  this.mutationCb = options.mutationCb;
14056
14070
  this.mirror = options.mirror;
14057
14071
  if (recordCanvas && sampling === "all")
14058
- this.initCanvasMutationObserver(win, blockClass, blockSelector);
14072
+ this.initCanvasMutationObserver(
14073
+ win,
14074
+ blockClass,
14075
+ blockSelector,
14076
+ dataURLOptions
14077
+ );
14059
14078
  if (recordCanvas && typeof sampling === "number")
14060
14079
  this.initCanvasFPSObserver(sampling, win, blockClass, blockSelector, {
14061
14080
  dataURLOptions
@@ -14184,7 +14203,7 @@ class CanvasManager {
14184
14203
  cancelAnimationFrame(rafId);
14185
14204
  };
14186
14205
  }
14187
- initCanvasMutationObserver(win, blockClass, blockSelector) {
14206
+ initCanvasMutationObserver(win, blockClass, blockSelector, dataURLOptions) {
14188
14207
  this.startRAFTimestamping();
14189
14208
  this.startPendingCanvasMutationFlusher();
14190
14209
  const canvasContextReset = initCanvasContextObserver(
@@ -14197,13 +14216,15 @@ class CanvasManager {
14197
14216
  this.processMutation.bind(this),
14198
14217
  win,
14199
14218
  blockClass,
14200
- blockSelector
14219
+ blockSelector,
14220
+ dataURLOptions
14201
14221
  );
14202
14222
  const canvasWebGL1and2Reset = initCanvasWebGLMutationObserver(
14203
14223
  this.processMutation.bind(this),
14204
14224
  win,
14205
14225
  blockClass,
14206
- blockSelector
14226
+ blockSelector,
14227
+ dataURLOptions
14207
14228
  );
14208
14229
  this.resetObservers = () => {
14209
14230
  canvasContextReset();
@@ -14750,13 +14771,14 @@ function record(options = {}) {
14750
14771
  hooks
14751
14772
  );
14752
14773
  };
14753
- iframeManager.addLoadListener((iframeEl) => {
14774
+ const loadListener = (iframeEl) => {
14754
14775
  try {
14755
14776
  handlers.push(observe(iframeEl.contentDocument));
14756
14777
  } catch (error) {
14757
14778
  console.warn(error);
14758
14779
  }
14759
- });
14780
+ };
14781
+ iframeManager.addLoadListener(loadListener);
14760
14782
  const init = () => {
14761
14783
  takeFullSnapshot$1();
14762
14784
  handlers.push(observe(document));
@@ -14791,6 +14813,7 @@ function record(options = {}) {
14791
14813
  return () => {
14792
14814
  handlers.forEach((h) => h());
14793
14815
  processedNodeManager.destroy();
14816
+ iframeManager.removeLoadListener();
14794
14817
  iframeManager.destroy();
14795
14818
  recording = false;
14796
14819
  unregisterErrorHandler();