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