@posthog/rrweb-record 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.
@@ -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 (e) {
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());
@@ -459,6 +374,91 @@ function extractFileExtension(path, baseURL) {
459
374
  const match = url.pathname.match(regex);
460
375
  return (_a2 = match == null ? void 0 : match[1]) != null ? _a2 : null;
461
376
  }
377
+ function fixBrowserCompatibilityIssuesInCSS(cssText) {
378
+ if (cssText.includes(" background-clip: text;") && !cssText.includes(" -webkit-background-clip: text;")) {
379
+ cssText = cssText.replace(
380
+ /\sbackground-clip:\s*text;/g,
381
+ " -webkit-background-clip: text; background-clip: text;"
382
+ );
383
+ }
384
+ return cssText;
385
+ }
386
+ function escapeImportStatement(rule2) {
387
+ const { cssText } = rule2;
388
+ if (cssText.split('"').length < 3) return cssText;
389
+ const statement = ["@import", `url(${JSON.stringify(rule2.href)})`];
390
+ if (rule2.layerName === "") {
391
+ statement.push(`layer`);
392
+ } else if (rule2.layerName) {
393
+ statement.push(`layer(${rule2.layerName})`);
394
+ }
395
+ if (rule2.supportsText) {
396
+ statement.push(`supports(${rule2.supportsText})`);
397
+ }
398
+ if (rule2.media.length) {
399
+ statement.push(rule2.media.mediaText);
400
+ }
401
+ return statement.join(" ") + ";";
402
+ }
403
+ function stringifyStylesheet(s2) {
404
+ try {
405
+ const rules2 = s2.rules || s2.cssRules;
406
+ if (!rules2) {
407
+ return null;
408
+ }
409
+ let sheetHref = s2.href;
410
+ if (!sheetHref && s2.ownerNode) {
411
+ sheetHref = s2.ownerNode.baseURI;
412
+ }
413
+ const stringifiedRules = Array.from(
414
+ rules2,
415
+ (rule2) => stringifyRule(rule2, sheetHref)
416
+ ).join("");
417
+ return fixBrowserCompatibilityIssuesInCSS(stringifiedRules);
418
+ } catch (error) {
419
+ return null;
420
+ }
421
+ }
422
+ function stringifyRule(rule2, sheetHref) {
423
+ var _a2;
424
+ if (isCSSImportRule(rule2)) {
425
+ let importStringified;
426
+ try {
427
+ importStringified = // for same-origin stylesheets,
428
+ // we can access the imported stylesheet rules directly
429
+ stringifyStylesheet(rule2.styleSheet) || // work around browser issues with the raw string `@import url(...)` statement
430
+ escapeImportStatement(rule2);
431
+ } catch (error) {
432
+ importStringified = rule2.cssText;
433
+ }
434
+ try {
435
+ if (importStringified && ((_a2 = rule2.styleSheet) == null ? void 0 : _a2.href)) {
436
+ return absolutifyURLs(importStringified, rule2.styleSheet.href);
437
+ }
438
+ } catch (e) {
439
+ }
440
+ return importStringified;
441
+ } else {
442
+ let ruleStringified = rule2.cssText;
443
+ if (isCSSStyleRule(rule2) && rule2.selectorText.includes(":")) {
444
+ ruleStringified = fixSafariColons(ruleStringified);
445
+ }
446
+ if (sheetHref) {
447
+ return absolutifyURLs(ruleStringified, sheetHref);
448
+ }
449
+ return ruleStringified;
450
+ }
451
+ }
452
+ function fixSafariColons(cssStringified) {
453
+ const regex = /(\[(?:[\w-]+)[^\\])(:(?:[\w-]+)\])/gm;
454
+ return cssStringified.replace(regex, "$1\\$2");
455
+ }
456
+ function isCSSImportRule(rule2) {
457
+ return "styleSheet" in rule2;
458
+ }
459
+ function isCSSStyleRule(rule2) {
460
+ return "selectorText" in rule2;
461
+ }
462
462
  function extractOrigin(url) {
463
463
  let origin = "";
464
464
  if (url.indexOf("//") > -1) {
@@ -11864,9 +11864,9 @@ const saveWebGLVar = (value, win, ctx) => {
11864
11864
  }
11865
11865
  return index2;
11866
11866
  };
11867
- function serializeArg(value, win, ctx) {
11867
+ function serializeArg(value, win, ctx, dataURLOptions) {
11868
11868
  if (value instanceof Array) {
11869
- return value.map((arg) => serializeArg(arg, win, ctx));
11869
+ return value.map((arg) => serializeArg(arg, win, ctx, dataURLOptions));
11870
11870
  } else if (value === null) {
11871
11871
  return value;
11872
11872
  } 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) {
@@ -11892,7 +11892,7 @@ function serializeArg(value, win, ctx) {
11892
11892
  return {
11893
11893
  rr_type: name,
11894
11894
  args: [
11895
- serializeArg(value.buffer, win, ctx),
11895
+ serializeArg(value.buffer, win, ctx, dataURLOptions),
11896
11896
  value.byteOffset,
11897
11897
  value.byteLength
11898
11898
  ]
@@ -11906,7 +11906,7 @@ function serializeArg(value, win, ctx) {
11906
11906
  };
11907
11907
  } else if (value instanceof HTMLCanvasElement) {
11908
11908
  const name = "HTMLImageElement";
11909
- const src = value.toDataURL();
11909
+ const src = value.toDataURL(dataURLOptions.type, dataURLOptions.quality);
11910
11910
  return {
11911
11911
  rr_type: name,
11912
11912
  src
@@ -11915,7 +11915,11 @@ function serializeArg(value, win, ctx) {
11915
11915
  const name = value.constructor.name;
11916
11916
  return {
11917
11917
  rr_type: name,
11918
- args: [serializeArg(value.data, win, ctx), value.width, value.height]
11918
+ args: [
11919
+ serializeArg(value.data, win, ctx, dataURLOptions),
11920
+ value.width,
11921
+ value.height
11922
+ ]
11919
11923
  };
11920
11924
  } else if (isInstanceOfWebGLObject(value, win) || typeof value === "object") {
11921
11925
  const name = value.constructor.name;
@@ -11927,8 +11931,8 @@ function serializeArg(value, win, ctx) {
11927
11931
  }
11928
11932
  return value;
11929
11933
  }
11930
- const serializeArgs = (args, win, ctx) => {
11931
- return args.map((arg) => serializeArg(arg, win, ctx));
11934
+ const serializeArgs = (args, win, ctx, dataURLOptions) => {
11935
+ return args.map((arg) => serializeArg(arg, win, ctx, dataURLOptions));
11932
11936
  };
11933
11937
  const isInstanceOfWebGLObject = (value, win) => {
11934
11938
  const webGLConstructorNames = [
@@ -11954,7 +11958,7 @@ const isInstanceOfWebGLObject = (value, win) => {
11954
11958
  )
11955
11959
  );
11956
11960
  };
11957
- function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector) {
11961
+ function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector, dataURLOptions) {
11958
11962
  const handlers = [];
11959
11963
  const props2D = Object.getOwnPropertyNames(
11960
11964
  win.CanvasRenderingContext2D.prototype
@@ -11971,7 +11975,12 @@ function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector) {
11971
11975
  return function(...args) {
11972
11976
  if (!isBlocked(this.canvas, blockClass, blockSelector, true)) {
11973
11977
  setTimeout(() => {
11974
- const recordArgs = serializeArgs(args, win, this);
11978
+ const recordArgs = serializeArgs(
11979
+ args,
11980
+ win,
11981
+ this,
11982
+ dataURLOptions
11983
+ );
11975
11984
  cb(this.canvas, {
11976
11985
  type: CanvasContext["2D"],
11977
11986
  property: prop,
@@ -12045,7 +12054,7 @@ function initCanvasContextObserver(win, blockClass, blockSelector, setPreserveDr
12045
12054
  handlers.forEach((h) => h());
12046
12055
  };
12047
12056
  }
12048
- function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win) {
12057
+ function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win, dataURLOptions) {
12049
12058
  const handlers = [];
12050
12059
  const props = Object.getOwnPropertyNames(prototype);
12051
12060
  for (const prop of props) {
@@ -12072,7 +12081,7 @@ function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win) {
12072
12081
  const result2 = original.apply(this, args);
12073
12082
  saveWebGLVar(result2, win, this);
12074
12083
  if ("tagName" in this.canvas && !isBlocked(this.canvas, blockClass, blockSelector, true)) {
12075
- const recordArgs = serializeArgs(args, win, this);
12084
+ const recordArgs = serializeArgs(args, win, this, dataURLOptions);
12076
12085
  const mutation = {
12077
12086
  type,
12078
12087
  property: prop,
@@ -12101,7 +12110,7 @@ function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win) {
12101
12110
  }
12102
12111
  return handlers;
12103
12112
  }
12104
- function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector) {
12113
+ function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector, dataURLOptions) {
12105
12114
  const handlers = [];
12106
12115
  handlers.push(
12107
12116
  ...patchGLPrototype(
@@ -12110,7 +12119,8 @@ function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector) {
12110
12119
  cb,
12111
12120
  blockClass,
12112
12121
  blockSelector,
12113
- win
12122
+ win,
12123
+ dataURLOptions
12114
12124
  )
12115
12125
  );
12116
12126
  if (typeof win.WebGL2RenderingContext !== "undefined") {
@@ -12121,7 +12131,8 @@ function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector) {
12121
12131
  cb,
12122
12132
  blockClass,
12123
12133
  blockSelector,
12124
- win
12134
+ win,
12135
+ dataURLOptions
12125
12136
  )
12126
12137
  );
12127
12138
  }
@@ -12183,7 +12194,12 @@ class CanvasManager {
12183
12194
  this.mutationCb = options.mutationCb;
12184
12195
  this.mirror = options.mirror;
12185
12196
  if (recordCanvas && sampling === "all")
12186
- this.initCanvasMutationObserver(win, blockClass, blockSelector);
12197
+ this.initCanvasMutationObserver(
12198
+ win,
12199
+ blockClass,
12200
+ blockSelector,
12201
+ dataURLOptions
12202
+ );
12187
12203
  if (recordCanvas && typeof sampling === "number")
12188
12204
  this.initCanvasFPSObserver(sampling, win, blockClass, blockSelector, {
12189
12205
  dataURLOptions
@@ -12312,7 +12328,7 @@ class CanvasManager {
12312
12328
  cancelAnimationFrame(rafId);
12313
12329
  };
12314
12330
  }
12315
- initCanvasMutationObserver(win, blockClass, blockSelector) {
12331
+ initCanvasMutationObserver(win, blockClass, blockSelector, dataURLOptions) {
12316
12332
  this.startRAFTimestamping();
12317
12333
  this.startPendingCanvasMutationFlusher();
12318
12334
  const canvasContextReset = initCanvasContextObserver(
@@ -12325,13 +12341,15 @@ class CanvasManager {
12325
12341
  this.processMutation.bind(this),
12326
12342
  win,
12327
12343
  blockClass,
12328
- blockSelector
12344
+ blockSelector,
12345
+ dataURLOptions
12329
12346
  );
12330
12347
  const canvasWebGL1and2Reset = initCanvasWebGLMutationObserver(
12331
12348
  this.processMutation.bind(this),
12332
12349
  win,
12333
12350
  blockClass,
12334
- blockSelector
12351
+ blockSelector,
12352
+ dataURLOptions
12335
12353
  );
12336
12354
  this.resetObservers = () => {
12337
12355
  canvasContextReset();