@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.
@@ -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());
@@ -412,6 +327,91 @@ function extractFileExtension(path, baseURL) {
412
327
  const match = url.pathname.match(regex);
413
328
  return (match == null ? void 0 : match[1]) ?? null;
414
329
  }
330
+ function fixBrowserCompatibilityIssuesInCSS(cssText) {
331
+ if (cssText.includes(" background-clip: text;") && !cssText.includes(" -webkit-background-clip: text;")) {
332
+ cssText = cssText.replace(
333
+ /\sbackground-clip:\s*text;/g,
334
+ " -webkit-background-clip: text; background-clip: text;"
335
+ );
336
+ }
337
+ return cssText;
338
+ }
339
+ function escapeImportStatement(rule2) {
340
+ const { cssText } = rule2;
341
+ if (cssText.split('"').length < 3) return cssText;
342
+ const statement = ["@import", `url(${JSON.stringify(rule2.href)})`];
343
+ if (rule2.layerName === "") {
344
+ statement.push(`layer`);
345
+ } else if (rule2.layerName) {
346
+ statement.push(`layer(${rule2.layerName})`);
347
+ }
348
+ if (rule2.supportsText) {
349
+ statement.push(`supports(${rule2.supportsText})`);
350
+ }
351
+ if (rule2.media.length) {
352
+ statement.push(rule2.media.mediaText);
353
+ }
354
+ return statement.join(" ") + ";";
355
+ }
356
+ function stringifyStylesheet(s2) {
357
+ try {
358
+ const rules2 = s2.rules || s2.cssRules;
359
+ if (!rules2) {
360
+ return null;
361
+ }
362
+ let sheetHref = s2.href;
363
+ if (!sheetHref && s2.ownerNode) {
364
+ sheetHref = s2.ownerNode.baseURI;
365
+ }
366
+ const stringifiedRules = Array.from(
367
+ rules2,
368
+ (rule2) => stringifyRule(rule2, sheetHref)
369
+ ).join("");
370
+ return fixBrowserCompatibilityIssuesInCSS(stringifiedRules);
371
+ } catch (error) {
372
+ return null;
373
+ }
374
+ }
375
+ function stringifyRule(rule2, sheetHref) {
376
+ var _a2;
377
+ if (isCSSImportRule(rule2)) {
378
+ let importStringified;
379
+ try {
380
+ importStringified = // for same-origin stylesheets,
381
+ // we can access the imported stylesheet rules directly
382
+ stringifyStylesheet(rule2.styleSheet) || // work around browser issues with the raw string `@import url(...)` statement
383
+ escapeImportStatement(rule2);
384
+ } catch (error) {
385
+ importStringified = rule2.cssText;
386
+ }
387
+ try {
388
+ if (importStringified && ((_a2 = rule2.styleSheet) == null ? void 0 : _a2.href)) {
389
+ return absolutifyURLs(importStringified, rule2.styleSheet.href);
390
+ }
391
+ } catch {
392
+ }
393
+ return importStringified;
394
+ } else {
395
+ let ruleStringified = rule2.cssText;
396
+ if (isCSSStyleRule(rule2) && rule2.selectorText.includes(":")) {
397
+ ruleStringified = fixSafariColons(ruleStringified);
398
+ }
399
+ if (sheetHref) {
400
+ return absolutifyURLs(ruleStringified, sheetHref);
401
+ }
402
+ return ruleStringified;
403
+ }
404
+ }
405
+ function fixSafariColons(cssStringified) {
406
+ const regex = /(\[(?:[\w-]+)[^\\])(:(?:[\w-]+)\])/gm;
407
+ return cssStringified.replace(regex, "$1\\$2");
408
+ }
409
+ function isCSSImportRule(rule2) {
410
+ return "styleSheet" in rule2;
411
+ }
412
+ function isCSSStyleRule(rule2) {
413
+ return "selectorText" in rule2;
414
+ }
415
415
  function extractOrigin(url) {
416
416
  let origin = "";
417
417
  if (url.indexOf("//") > -1) {
@@ -11822,9 +11822,9 @@ const saveWebGLVar = (value, win, ctx) => {
11822
11822
  }
11823
11823
  return index2;
11824
11824
  };
11825
- function serializeArg(value, win, ctx) {
11825
+ function serializeArg(value, win, ctx, dataURLOptions) {
11826
11826
  if (value instanceof Array) {
11827
- return value.map((arg) => serializeArg(arg, win, ctx));
11827
+ return value.map((arg) => serializeArg(arg, win, ctx, dataURLOptions));
11828
11828
  } else if (value === null) {
11829
11829
  return value;
11830
11830
  } 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) {
@@ -11850,7 +11850,7 @@ function serializeArg(value, win, ctx) {
11850
11850
  return {
11851
11851
  rr_type: name,
11852
11852
  args: [
11853
- serializeArg(value.buffer, win, ctx),
11853
+ serializeArg(value.buffer, win, ctx, dataURLOptions),
11854
11854
  value.byteOffset,
11855
11855
  value.byteLength
11856
11856
  ]
@@ -11864,7 +11864,7 @@ function serializeArg(value, win, ctx) {
11864
11864
  };
11865
11865
  } else if (value instanceof HTMLCanvasElement) {
11866
11866
  const name = "HTMLImageElement";
11867
- const src = value.toDataURL();
11867
+ const src = value.toDataURL(dataURLOptions.type, dataURLOptions.quality);
11868
11868
  return {
11869
11869
  rr_type: name,
11870
11870
  src
@@ -11873,7 +11873,11 @@ function serializeArg(value, win, ctx) {
11873
11873
  const name = value.constructor.name;
11874
11874
  return {
11875
11875
  rr_type: name,
11876
- args: [serializeArg(value.data, win, ctx), value.width, value.height]
11876
+ args: [
11877
+ serializeArg(value.data, win, ctx, dataURLOptions),
11878
+ value.width,
11879
+ value.height
11880
+ ]
11877
11881
  };
11878
11882
  } else if (isInstanceOfWebGLObject(value, win) || typeof value === "object") {
11879
11883
  const name = value.constructor.name;
@@ -11885,8 +11889,8 @@ function serializeArg(value, win, ctx) {
11885
11889
  }
11886
11890
  return value;
11887
11891
  }
11888
- const serializeArgs = (args, win, ctx) => {
11889
- return args.map((arg) => serializeArg(arg, win, ctx));
11892
+ const serializeArgs = (args, win, ctx, dataURLOptions) => {
11893
+ return args.map((arg) => serializeArg(arg, win, ctx, dataURLOptions));
11890
11894
  };
11891
11895
  const isInstanceOfWebGLObject = (value, win) => {
11892
11896
  const webGLConstructorNames = [
@@ -11912,7 +11916,7 @@ const isInstanceOfWebGLObject = (value, win) => {
11912
11916
  )
11913
11917
  );
11914
11918
  };
11915
- function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector) {
11919
+ function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector, dataURLOptions) {
11916
11920
  const handlers = [];
11917
11921
  const props2D = Object.getOwnPropertyNames(
11918
11922
  win.CanvasRenderingContext2D.prototype
@@ -11929,7 +11933,12 @@ function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector) {
11929
11933
  return function(...args) {
11930
11934
  if (!isBlocked(this.canvas, blockClass, blockSelector, true)) {
11931
11935
  setTimeout(() => {
11932
- const recordArgs = serializeArgs(args, win, this);
11936
+ const recordArgs = serializeArgs(
11937
+ args,
11938
+ win,
11939
+ this,
11940
+ dataURLOptions
11941
+ );
11933
11942
  cb(this.canvas, {
11934
11943
  type: CanvasContext["2D"],
11935
11944
  property: prop,
@@ -12003,7 +12012,7 @@ function initCanvasContextObserver(win, blockClass, blockSelector, setPreserveDr
12003
12012
  handlers.forEach((h) => h());
12004
12013
  };
12005
12014
  }
12006
- function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win) {
12015
+ function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win, dataURLOptions) {
12007
12016
  const handlers = [];
12008
12017
  const props = Object.getOwnPropertyNames(prototype);
12009
12018
  for (const prop of props) {
@@ -12030,7 +12039,7 @@ function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win) {
12030
12039
  const result2 = original.apply(this, args);
12031
12040
  saveWebGLVar(result2, win, this);
12032
12041
  if ("tagName" in this.canvas && !isBlocked(this.canvas, blockClass, blockSelector, true)) {
12033
- const recordArgs = serializeArgs(args, win, this);
12042
+ const recordArgs = serializeArgs(args, win, this, dataURLOptions);
12034
12043
  const mutation = {
12035
12044
  type,
12036
12045
  property: prop,
@@ -12059,7 +12068,7 @@ function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win) {
12059
12068
  }
12060
12069
  return handlers;
12061
12070
  }
12062
- function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector) {
12071
+ function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector, dataURLOptions) {
12063
12072
  const handlers = [];
12064
12073
  handlers.push(
12065
12074
  ...patchGLPrototype(
@@ -12068,7 +12077,8 @@ function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector) {
12068
12077
  cb,
12069
12078
  blockClass,
12070
12079
  blockSelector,
12071
- win
12080
+ win,
12081
+ dataURLOptions
12072
12082
  )
12073
12083
  );
12074
12084
  if (typeof win.WebGL2RenderingContext !== "undefined") {
@@ -12079,7 +12089,8 @@ function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector) {
12079
12089
  cb,
12080
12090
  blockClass,
12081
12091
  blockSelector,
12082
- win
12092
+ win,
12093
+ dataURLOptions
12083
12094
  )
12084
12095
  );
12085
12096
  }
@@ -12141,7 +12152,12 @@ class CanvasManager {
12141
12152
  this.mutationCb = options.mutationCb;
12142
12153
  this.mirror = options.mirror;
12143
12154
  if (recordCanvas && sampling === "all")
12144
- this.initCanvasMutationObserver(win, blockClass, blockSelector);
12155
+ this.initCanvasMutationObserver(
12156
+ win,
12157
+ blockClass,
12158
+ blockSelector,
12159
+ dataURLOptions
12160
+ );
12145
12161
  if (recordCanvas && typeof sampling === "number")
12146
12162
  this.initCanvasFPSObserver(sampling, win, blockClass, blockSelector, {
12147
12163
  dataURLOptions
@@ -12270,7 +12286,7 @@ class CanvasManager {
12270
12286
  cancelAnimationFrame(rafId);
12271
12287
  };
12272
12288
  }
12273
- initCanvasMutationObserver(win, blockClass, blockSelector) {
12289
+ initCanvasMutationObserver(win, blockClass, blockSelector, dataURLOptions) {
12274
12290
  this.startRAFTimestamping();
12275
12291
  this.startPendingCanvasMutationFlusher();
12276
12292
  const canvasContextReset = initCanvasContextObserver(
@@ -12283,13 +12299,15 @@ class CanvasManager {
12283
12299
  this.processMutation.bind(this),
12284
12300
  win,
12285
12301
  blockClass,
12286
- blockSelector
12302
+ blockSelector,
12303
+ dataURLOptions
12287
12304
  );
12288
12305
  const canvasWebGL1and2Reset = initCanvasWebGLMutationObserver(
12289
12306
  this.processMutation.bind(this),
12290
12307
  win,
12291
12308
  blockClass,
12292
- blockSelector
12309
+ blockSelector,
12310
+ dataURLOptions
12293
12311
  );
12294
12312
  this.resetObservers = () => {
12295
12313
  canvasContextReset();