@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.
package/dist/rrweb.cjs CHANGED
@@ -207,91 +207,6 @@ 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
- }
295
210
  class Mirror {
296
211
  constructor() {
297
212
  __publicField$1(this, "idNodeMap", /* @__PURE__ */ new Map());
@@ -426,6 +341,91 @@ function extractFileExtension(path, baseURL) {
426
341
  const match = url.pathname.match(regex);
427
342
  return (match == null ? void 0 : match[1]) ?? null;
428
343
  }
344
+ function fixBrowserCompatibilityIssuesInCSS(cssText) {
345
+ if (cssText.includes(" background-clip: text;") && !cssText.includes(" -webkit-background-clip: text;")) {
346
+ cssText = cssText.replace(
347
+ /\sbackground-clip:\s*text;/g,
348
+ " -webkit-background-clip: text; background-clip: text;"
349
+ );
350
+ }
351
+ return cssText;
352
+ }
353
+ function escapeImportStatement(rule2) {
354
+ const { cssText } = rule2;
355
+ if (cssText.split('"').length < 3) return cssText;
356
+ const statement = ["@import", `url(${JSON.stringify(rule2.href)})`];
357
+ if (rule2.layerName === "") {
358
+ statement.push(`layer`);
359
+ } else if (rule2.layerName) {
360
+ statement.push(`layer(${rule2.layerName})`);
361
+ }
362
+ if (rule2.supportsText) {
363
+ statement.push(`supports(${rule2.supportsText})`);
364
+ }
365
+ if (rule2.media.length) {
366
+ statement.push(rule2.media.mediaText);
367
+ }
368
+ return statement.join(" ") + ";";
369
+ }
370
+ function stringifyStylesheet(s2) {
371
+ try {
372
+ const rules2 = s2.rules || s2.cssRules;
373
+ if (!rules2) {
374
+ return null;
375
+ }
376
+ let sheetHref = s2.href;
377
+ if (!sheetHref && s2.ownerNode) {
378
+ sheetHref = s2.ownerNode.baseURI;
379
+ }
380
+ const stringifiedRules = Array.from(
381
+ rules2,
382
+ (rule2) => stringifyRule(rule2, sheetHref)
383
+ ).join("");
384
+ return fixBrowserCompatibilityIssuesInCSS(stringifiedRules);
385
+ } catch (error) {
386
+ return null;
387
+ }
388
+ }
389
+ function stringifyRule(rule2, sheetHref) {
390
+ var _a2;
391
+ if (isCSSImportRule(rule2)) {
392
+ let importStringified;
393
+ try {
394
+ importStringified = // for same-origin stylesheets,
395
+ // we can access the imported stylesheet rules directly
396
+ stringifyStylesheet(rule2.styleSheet) || // work around browser issues with the raw string `@import url(...)` statement
397
+ escapeImportStatement(rule2);
398
+ } catch (error) {
399
+ importStringified = rule2.cssText;
400
+ }
401
+ try {
402
+ if (importStringified && ((_a2 = rule2.styleSheet) == null ? void 0 : _a2.href)) {
403
+ return absolutifyURLs(importStringified, rule2.styleSheet.href);
404
+ }
405
+ } catch {
406
+ }
407
+ return importStringified;
408
+ } else {
409
+ let ruleStringified = rule2.cssText;
410
+ if (isCSSStyleRule(rule2) && rule2.selectorText.includes(":")) {
411
+ ruleStringified = fixSafariColons(ruleStringified);
412
+ }
413
+ if (sheetHref) {
414
+ return absolutifyURLs(ruleStringified, sheetHref);
415
+ }
416
+ return ruleStringified;
417
+ }
418
+ }
419
+ function fixSafariColons(cssStringified) {
420
+ const regex = /(\[(?:[\w-]+)[^\\])(:(?:[\w-]+)\])/gm;
421
+ return cssStringified.replace(regex, "$1\\$2");
422
+ }
423
+ function isCSSImportRule(rule2) {
424
+ return "styleSheet" in rule2;
425
+ }
426
+ function isCSSStyleRule(rule2) {
427
+ return "selectorText" in rule2;
428
+ }
429
429
  function extractOrigin(url) {
430
430
  let origin = "";
431
431
  if (url.indexOf("//") > -1) {
@@ -5332,6 +5332,22 @@ postcss$1.Input;
5332
5332
  postcss$1.Rule;
5333
5333
  postcss$1.Root;
5334
5334
  postcss$1.Node;
5335
+ function adaptCssForReplay(cssText, cache) {
5336
+ const cachedStyle = cache == null ? void 0 : cache.stylesWithHoverClass.get(cssText);
5337
+ if (cachedStyle) return cachedStyle;
5338
+ let result2 = cssText;
5339
+ try {
5340
+ const ast = postcss$1([
5341
+ mediaSelectorPlugin,
5342
+ pseudoClassPlugin
5343
+ ]).process(cssText, { parser: safeParser });
5344
+ result2 = ast.css;
5345
+ } catch (error) {
5346
+ console.warn("Failed to adapt css for replay", error);
5347
+ }
5348
+ cache == null ? void 0 : cache.stylesWithHoverClass.set(cssText, result2);
5349
+ return result2;
5350
+ }
5335
5351
  const tagMap = {
5336
5352
  script: "noscript",
5337
5353
  // camel case svg element tag names
@@ -5379,22 +5395,6 @@ function getTagName(n2) {
5379
5395
  }
5380
5396
  return tagName;
5381
5397
  }
5382
- function adaptCssForReplay(cssText, cache) {
5383
- const cachedStyle = cache == null ? void 0 : cache.stylesWithHoverClass.get(cssText);
5384
- if (cachedStyle) return cachedStyle;
5385
- let result2 = cssText;
5386
- try {
5387
- const ast = postcss$1([
5388
- mediaSelectorPlugin,
5389
- pseudoClassPlugin
5390
- ]).process(cssText, { parser: safeParser });
5391
- result2 = ast.css;
5392
- } catch (error) {
5393
- console.warn("Failed to adapt css for replay", error);
5394
- }
5395
- cache == null ? void 0 : cache.stylesWithHoverClass.set(cssText, result2);
5396
- return result2;
5397
- }
5398
5398
  function createCache() {
5399
5399
  const stylesWithHoverClass = /* @__PURE__ */ new Map();
5400
5400
  return {
@@ -13342,6 +13342,9 @@ class IframeManager {
13342
13342
  addLoadListener(cb) {
13343
13343
  this.loadListener = cb;
13344
13344
  }
13345
+ removeLoadListener() {
13346
+ this.loadListener = void 0;
13347
+ }
13345
13348
  attachIframe(iframeEl, childSn) {
13346
13349
  var _a2;
13347
13350
  this.mutationCb({
@@ -13717,9 +13720,9 @@ const saveWebGLVar = (value, win, ctx) => {
13717
13720
  }
13718
13721
  return index2;
13719
13722
  };
13720
- function serializeArg(value, win, ctx) {
13723
+ function serializeArg(value, win, ctx, dataURLOptions) {
13721
13724
  if (value instanceof Array) {
13722
- return value.map((arg) => serializeArg(arg, win, ctx));
13725
+ return value.map((arg) => serializeArg(arg, win, ctx, dataURLOptions));
13723
13726
  } else if (value === null) {
13724
13727
  return value;
13725
13728
  } 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) {
@@ -13745,7 +13748,7 @@ function serializeArg(value, win, ctx) {
13745
13748
  return {
13746
13749
  rr_type: name,
13747
13750
  args: [
13748
- serializeArg(value.buffer, win, ctx),
13751
+ serializeArg(value.buffer, win, ctx, dataURLOptions),
13749
13752
  value.byteOffset,
13750
13753
  value.byteLength
13751
13754
  ]
@@ -13759,7 +13762,7 @@ function serializeArg(value, win, ctx) {
13759
13762
  };
13760
13763
  } else if (value instanceof HTMLCanvasElement) {
13761
13764
  const name = "HTMLImageElement";
13762
- const src = value.toDataURL();
13765
+ const src = value.toDataURL(dataURLOptions.type, dataURLOptions.quality);
13763
13766
  return {
13764
13767
  rr_type: name,
13765
13768
  src
@@ -13768,7 +13771,11 @@ function serializeArg(value, win, ctx) {
13768
13771
  const name = value.constructor.name;
13769
13772
  return {
13770
13773
  rr_type: name,
13771
- args: [serializeArg(value.data, win, ctx), value.width, value.height]
13774
+ args: [
13775
+ serializeArg(value.data, win, ctx, dataURLOptions),
13776
+ value.width,
13777
+ value.height
13778
+ ]
13772
13779
  };
13773
13780
  } else if (isInstanceOfWebGLObject(value, win) || typeof value === "object") {
13774
13781
  const name = value.constructor.name;
@@ -13780,8 +13787,8 @@ function serializeArg(value, win, ctx) {
13780
13787
  }
13781
13788
  return value;
13782
13789
  }
13783
- const serializeArgs = (args, win, ctx) => {
13784
- return args.map((arg) => serializeArg(arg, win, ctx));
13790
+ const serializeArgs = (args, win, ctx, dataURLOptions) => {
13791
+ return args.map((arg) => serializeArg(arg, win, ctx, dataURLOptions));
13785
13792
  };
13786
13793
  const isInstanceOfWebGLObject = (value, win) => {
13787
13794
  const webGLConstructorNames = [
@@ -13807,7 +13814,7 @@ const isInstanceOfWebGLObject = (value, win) => {
13807
13814
  )
13808
13815
  );
13809
13816
  };
13810
- function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector) {
13817
+ function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector, dataURLOptions) {
13811
13818
  const handlers = [];
13812
13819
  const props2D = Object.getOwnPropertyNames(
13813
13820
  win.CanvasRenderingContext2D.prototype
@@ -13824,7 +13831,12 @@ function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector) {
13824
13831
  return function(...args) {
13825
13832
  if (!isBlocked(this.canvas, blockClass, blockSelector, true)) {
13826
13833
  setTimeout(() => {
13827
- const recordArgs = serializeArgs(args, win, this);
13834
+ const recordArgs = serializeArgs(
13835
+ args,
13836
+ win,
13837
+ this,
13838
+ dataURLOptions
13839
+ );
13828
13840
  cb(this.canvas, {
13829
13841
  type: CanvasContext["2D"],
13830
13842
  property: prop,
@@ -13898,7 +13910,7 @@ function initCanvasContextObserver(win, blockClass, blockSelector, setPreserveDr
13898
13910
  handlers.forEach((h) => h());
13899
13911
  };
13900
13912
  }
13901
- function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win) {
13913
+ function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win, dataURLOptions) {
13902
13914
  const handlers = [];
13903
13915
  const props = Object.getOwnPropertyNames(prototype);
13904
13916
  for (const prop of props) {
@@ -13925,7 +13937,7 @@ function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win) {
13925
13937
  const result2 = original.apply(this, args);
13926
13938
  saveWebGLVar(result2, win, this);
13927
13939
  if ("tagName" in this.canvas && !isBlocked(this.canvas, blockClass, blockSelector, true)) {
13928
- const recordArgs = serializeArgs(args, win, this);
13940
+ const recordArgs = serializeArgs(args, win, this, dataURLOptions);
13929
13941
  const mutation = {
13930
13942
  type,
13931
13943
  property: prop,
@@ -13954,7 +13966,7 @@ function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win) {
13954
13966
  }
13955
13967
  return handlers;
13956
13968
  }
13957
- function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector) {
13969
+ function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector, dataURLOptions) {
13958
13970
  const handlers = [];
13959
13971
  handlers.push(
13960
13972
  ...patchGLPrototype(
@@ -13963,7 +13975,8 @@ function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector) {
13963
13975
  cb,
13964
13976
  blockClass,
13965
13977
  blockSelector,
13966
- win
13978
+ win,
13979
+ dataURLOptions
13967
13980
  )
13968
13981
  );
13969
13982
  if (typeof win.WebGL2RenderingContext !== "undefined") {
@@ -13974,7 +13987,8 @@ function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector) {
13974
13987
  cb,
13975
13988
  blockClass,
13976
13989
  blockSelector,
13977
- win
13990
+ win,
13991
+ dataURLOptions
13978
13992
  )
13979
13993
  );
13980
13994
  }
@@ -14036,7 +14050,12 @@ class CanvasManager {
14036
14050
  this.mutationCb = options.mutationCb;
14037
14051
  this.mirror = options.mirror;
14038
14052
  if (recordCanvas && sampling === "all")
14039
- this.initCanvasMutationObserver(win, blockClass, blockSelector);
14053
+ this.initCanvasMutationObserver(
14054
+ win,
14055
+ blockClass,
14056
+ blockSelector,
14057
+ dataURLOptions
14058
+ );
14040
14059
  if (recordCanvas && typeof sampling === "number")
14041
14060
  this.initCanvasFPSObserver(sampling, win, blockClass, blockSelector, {
14042
14061
  dataURLOptions
@@ -14165,7 +14184,7 @@ class CanvasManager {
14165
14184
  cancelAnimationFrame(rafId);
14166
14185
  };
14167
14186
  }
14168
- initCanvasMutationObserver(win, blockClass, blockSelector) {
14187
+ initCanvasMutationObserver(win, blockClass, blockSelector, dataURLOptions) {
14169
14188
  this.startRAFTimestamping();
14170
14189
  this.startPendingCanvasMutationFlusher();
14171
14190
  const canvasContextReset = initCanvasContextObserver(
@@ -14178,13 +14197,15 @@ class CanvasManager {
14178
14197
  this.processMutation.bind(this),
14179
14198
  win,
14180
14199
  blockClass,
14181
- blockSelector
14200
+ blockSelector,
14201
+ dataURLOptions
14182
14202
  );
14183
14203
  const canvasWebGL1and2Reset = initCanvasWebGLMutationObserver(
14184
14204
  this.processMutation.bind(this),
14185
14205
  win,
14186
14206
  blockClass,
14187
- blockSelector
14207
+ blockSelector,
14208
+ dataURLOptions
14188
14209
  );
14189
14210
  this.resetObservers = () => {
14190
14211
  canvasContextReset();
@@ -14744,13 +14765,14 @@ function record(options = {}) {
14744
14765
  hooks
14745
14766
  );
14746
14767
  };
14747
- iframeManager.addLoadListener((iframeEl) => {
14768
+ const loadListener = (iframeEl) => {
14748
14769
  try {
14749
14770
  handlers.push(observe(iframeEl.contentDocument));
14750
14771
  } catch (error) {
14751
14772
  console.warn(error);
14752
14773
  }
14753
- });
14774
+ };
14775
+ iframeManager.addLoadListener(loadListener);
14754
14776
  const init = () => {
14755
14777
  takeFullSnapshot$1();
14756
14778
  handlers.push(observe(document));
@@ -14785,6 +14807,7 @@ function record(options = {}) {
14785
14807
  return () => {
14786
14808
  handlers.forEach((h) => h());
14787
14809
  processedNodeManager.destroy();
14810
+ iframeManager.removeLoadListener();
14788
14811
  iframeManager.destroy();
14789
14812
  recording = false;
14790
14813
  unregisterErrorHandler();