@posthog/rrweb 0.0.27 → 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 {
@@ -13718,9 +13718,9 @@ const saveWebGLVar = (value, win, ctx) => {
13718
13718
  }
13719
13719
  return index2;
13720
13720
  };
13721
- function serializeArg(value, win, ctx) {
13721
+ function serializeArg(value, win, ctx, dataURLOptions) {
13722
13722
  if (value instanceof Array) {
13723
- return value.map((arg) => serializeArg(arg, win, ctx));
13723
+ return value.map((arg) => serializeArg(arg, win, ctx, dataURLOptions));
13724
13724
  } else if (value === null) {
13725
13725
  return value;
13726
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) {
@@ -13746,7 +13746,7 @@ function serializeArg(value, win, ctx) {
13746
13746
  return {
13747
13747
  rr_type: name,
13748
13748
  args: [
13749
- serializeArg(value.buffer, win, ctx),
13749
+ serializeArg(value.buffer, win, ctx, dataURLOptions),
13750
13750
  value.byteOffset,
13751
13751
  value.byteLength
13752
13752
  ]
@@ -13760,7 +13760,7 @@ function serializeArg(value, win, ctx) {
13760
13760
  };
13761
13761
  } else if (value instanceof HTMLCanvasElement) {
13762
13762
  const name = "HTMLImageElement";
13763
- const src = value.toDataURL();
13763
+ const src = value.toDataURL(dataURLOptions.type, dataURLOptions.quality);
13764
13764
  return {
13765
13765
  rr_type: name,
13766
13766
  src
@@ -13769,7 +13769,11 @@ function serializeArg(value, win, ctx) {
13769
13769
  const name = value.constructor.name;
13770
13770
  return {
13771
13771
  rr_type: name,
13772
- 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
+ ]
13773
13777
  };
13774
13778
  } else if (isInstanceOfWebGLObject(value, win) || typeof value === "object") {
13775
13779
  const name = value.constructor.name;
@@ -13781,8 +13785,8 @@ function serializeArg(value, win, ctx) {
13781
13785
  }
13782
13786
  return value;
13783
13787
  }
13784
- const serializeArgs = (args, win, ctx) => {
13785
- 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));
13786
13790
  };
13787
13791
  const isInstanceOfWebGLObject = (value, win) => {
13788
13792
  const webGLConstructorNames = [
@@ -13808,7 +13812,7 @@ const isInstanceOfWebGLObject = (value, win) => {
13808
13812
  )
13809
13813
  );
13810
13814
  };
13811
- function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector) {
13815
+ function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector, dataURLOptions) {
13812
13816
  const handlers = [];
13813
13817
  const props2D = Object.getOwnPropertyNames(
13814
13818
  win.CanvasRenderingContext2D.prototype
@@ -13825,7 +13829,12 @@ function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector) {
13825
13829
  return function(...args) {
13826
13830
  if (!isBlocked(this.canvas, blockClass, blockSelector, true)) {
13827
13831
  setTimeout(() => {
13828
- const recordArgs = serializeArgs(args, win, this);
13832
+ const recordArgs = serializeArgs(
13833
+ args,
13834
+ win,
13835
+ this,
13836
+ dataURLOptions
13837
+ );
13829
13838
  cb(this.canvas, {
13830
13839
  type: CanvasContext["2D"],
13831
13840
  property: prop,
@@ -13899,7 +13908,7 @@ function initCanvasContextObserver(win, blockClass, blockSelector, setPreserveDr
13899
13908
  handlers.forEach((h) => h());
13900
13909
  };
13901
13910
  }
13902
- function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win) {
13911
+ function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win, dataURLOptions) {
13903
13912
  const handlers = [];
13904
13913
  const props = Object.getOwnPropertyNames(prototype);
13905
13914
  for (const prop of props) {
@@ -13926,7 +13935,7 @@ function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win) {
13926
13935
  const result2 = original.apply(this, args);
13927
13936
  saveWebGLVar(result2, win, this);
13928
13937
  if ("tagName" in this.canvas && !isBlocked(this.canvas, blockClass, blockSelector, true)) {
13929
- const recordArgs = serializeArgs(args, win, this);
13938
+ const recordArgs = serializeArgs(args, win, this, dataURLOptions);
13930
13939
  const mutation = {
13931
13940
  type,
13932
13941
  property: prop,
@@ -13955,7 +13964,7 @@ function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win) {
13955
13964
  }
13956
13965
  return handlers;
13957
13966
  }
13958
- function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector) {
13967
+ function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector, dataURLOptions) {
13959
13968
  const handlers = [];
13960
13969
  handlers.push(
13961
13970
  ...patchGLPrototype(
@@ -13964,7 +13973,8 @@ function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector) {
13964
13973
  cb,
13965
13974
  blockClass,
13966
13975
  blockSelector,
13967
- win
13976
+ win,
13977
+ dataURLOptions
13968
13978
  )
13969
13979
  );
13970
13980
  if (typeof win.WebGL2RenderingContext !== "undefined") {
@@ -13975,7 +13985,8 @@ function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector) {
13975
13985
  cb,
13976
13986
  blockClass,
13977
13987
  blockSelector,
13978
- win
13988
+ win,
13989
+ dataURLOptions
13979
13990
  )
13980
13991
  );
13981
13992
  }
@@ -14037,7 +14048,12 @@ class CanvasManager {
14037
14048
  this.mutationCb = options.mutationCb;
14038
14049
  this.mirror = options.mirror;
14039
14050
  if (recordCanvas && sampling === "all")
14040
- this.initCanvasMutationObserver(win, blockClass, blockSelector);
14051
+ this.initCanvasMutationObserver(
14052
+ win,
14053
+ blockClass,
14054
+ blockSelector,
14055
+ dataURLOptions
14056
+ );
14041
14057
  if (recordCanvas && typeof sampling === "number")
14042
14058
  this.initCanvasFPSObserver(sampling, win, blockClass, blockSelector, {
14043
14059
  dataURLOptions
@@ -14166,7 +14182,7 @@ class CanvasManager {
14166
14182
  cancelAnimationFrame(rafId);
14167
14183
  };
14168
14184
  }
14169
- initCanvasMutationObserver(win, blockClass, blockSelector) {
14185
+ initCanvasMutationObserver(win, blockClass, blockSelector, dataURLOptions) {
14170
14186
  this.startRAFTimestamping();
14171
14187
  this.startPendingCanvasMutationFlusher();
14172
14188
  const canvasContextReset = initCanvasContextObserver(
@@ -14179,13 +14195,15 @@ class CanvasManager {
14179
14195
  this.processMutation.bind(this),
14180
14196
  win,
14181
14197
  blockClass,
14182
- blockSelector
14198
+ blockSelector,
14199
+ dataURLOptions
14183
14200
  );
14184
14201
  const canvasWebGL1and2Reset = initCanvasWebGLMutationObserver(
14185
14202
  this.processMutation.bind(this),
14186
14203
  win,
14187
14204
  blockClass,
14188
- blockSelector
14205
+ blockSelector,
14206
+ dataURLOptions
14189
14207
  );
14190
14208
  this.resetObservers = () => {
14191
14209
  canvasContextReset();