@posthog/rrweb-record 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.
@@ -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());
@@ -414,6 +329,91 @@ function extractFileExtension(path, baseURL) {
414
329
  const match = url.pathname.match(regex);
415
330
  return (match == null ? void 0 : match[1]) ?? null;
416
331
  }
332
+ function fixBrowserCompatibilityIssuesInCSS(cssText) {
333
+ if (cssText.includes(" background-clip: text;") && !cssText.includes(" -webkit-background-clip: text;")) {
334
+ cssText = cssText.replace(
335
+ /\sbackground-clip:\s*text;/g,
336
+ " -webkit-background-clip: text; background-clip: text;"
337
+ );
338
+ }
339
+ return cssText;
340
+ }
341
+ function escapeImportStatement(rule2) {
342
+ const { cssText } = rule2;
343
+ if (cssText.split('"').length < 3) return cssText;
344
+ const statement = ["@import", `url(${JSON.stringify(rule2.href)})`];
345
+ if (rule2.layerName === "") {
346
+ statement.push(`layer`);
347
+ } else if (rule2.layerName) {
348
+ statement.push(`layer(${rule2.layerName})`);
349
+ }
350
+ if (rule2.supportsText) {
351
+ statement.push(`supports(${rule2.supportsText})`);
352
+ }
353
+ if (rule2.media.length) {
354
+ statement.push(rule2.media.mediaText);
355
+ }
356
+ return statement.join(" ") + ";";
357
+ }
358
+ function stringifyStylesheet(s2) {
359
+ try {
360
+ const rules2 = s2.rules || s2.cssRules;
361
+ if (!rules2) {
362
+ return null;
363
+ }
364
+ let sheetHref = s2.href;
365
+ if (!sheetHref && s2.ownerNode) {
366
+ sheetHref = s2.ownerNode.baseURI;
367
+ }
368
+ const stringifiedRules = Array.from(
369
+ rules2,
370
+ (rule2) => stringifyRule(rule2, sheetHref)
371
+ ).join("");
372
+ return fixBrowserCompatibilityIssuesInCSS(stringifiedRules);
373
+ } catch (error) {
374
+ return null;
375
+ }
376
+ }
377
+ function stringifyRule(rule2, sheetHref) {
378
+ var _a2;
379
+ if (isCSSImportRule(rule2)) {
380
+ let importStringified;
381
+ try {
382
+ importStringified = // for same-origin stylesheets,
383
+ // we can access the imported stylesheet rules directly
384
+ stringifyStylesheet(rule2.styleSheet) || // work around browser issues with the raw string `@import url(...)` statement
385
+ escapeImportStatement(rule2);
386
+ } catch (error) {
387
+ importStringified = rule2.cssText;
388
+ }
389
+ try {
390
+ if (importStringified && ((_a2 = rule2.styleSheet) == null ? void 0 : _a2.href)) {
391
+ return absolutifyURLs(importStringified, rule2.styleSheet.href);
392
+ }
393
+ } catch {
394
+ }
395
+ return importStringified;
396
+ } else {
397
+ let ruleStringified = rule2.cssText;
398
+ if (isCSSStyleRule(rule2) && rule2.selectorText.includes(":")) {
399
+ ruleStringified = fixSafariColons(ruleStringified);
400
+ }
401
+ if (sheetHref) {
402
+ return absolutifyURLs(ruleStringified, sheetHref);
403
+ }
404
+ return ruleStringified;
405
+ }
406
+ }
407
+ function fixSafariColons(cssStringified) {
408
+ const regex = /(\[(?:[\w-]+)[^\\])(:(?:[\w-]+)\])/gm;
409
+ return cssStringified.replace(regex, "$1\\$2");
410
+ }
411
+ function isCSSImportRule(rule2) {
412
+ return "styleSheet" in rule2;
413
+ }
414
+ function isCSSStyleRule(rule2) {
415
+ return "selectorText" in rule2;
416
+ }
417
417
  function extractOrigin(url) {
418
418
  let origin = "";
419
419
  if (url.indexOf("//") > -1) {
@@ -11466,6 +11466,9 @@ class IframeManager {
11466
11466
  addLoadListener(cb) {
11467
11467
  this.loadListener = cb;
11468
11468
  }
11469
+ removeLoadListener() {
11470
+ this.loadListener = void 0;
11471
+ }
11469
11472
  attachIframe(iframeEl, childSn) {
11470
11473
  var _a2;
11471
11474
  this.mutationCb({
@@ -11821,9 +11824,9 @@ const saveWebGLVar = (value, win, ctx) => {
11821
11824
  }
11822
11825
  return index2;
11823
11826
  };
11824
- function serializeArg(value, win, ctx) {
11827
+ function serializeArg(value, win, ctx, dataURLOptions) {
11825
11828
  if (value instanceof Array) {
11826
- return value.map((arg) => serializeArg(arg, win, ctx));
11829
+ return value.map((arg) => serializeArg(arg, win, ctx, dataURLOptions));
11827
11830
  } else if (value === null) {
11828
11831
  return value;
11829
11832
  } 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) {
@@ -11849,7 +11852,7 @@ function serializeArg(value, win, ctx) {
11849
11852
  return {
11850
11853
  rr_type: name,
11851
11854
  args: [
11852
- serializeArg(value.buffer, win, ctx),
11855
+ serializeArg(value.buffer, win, ctx, dataURLOptions),
11853
11856
  value.byteOffset,
11854
11857
  value.byteLength
11855
11858
  ]
@@ -11863,7 +11866,7 @@ function serializeArg(value, win, ctx) {
11863
11866
  };
11864
11867
  } else if (value instanceof HTMLCanvasElement) {
11865
11868
  const name = "HTMLImageElement";
11866
- const src = value.toDataURL();
11869
+ const src = value.toDataURL(dataURLOptions.type, dataURLOptions.quality);
11867
11870
  return {
11868
11871
  rr_type: name,
11869
11872
  src
@@ -11872,7 +11875,11 @@ function serializeArg(value, win, ctx) {
11872
11875
  const name = value.constructor.name;
11873
11876
  return {
11874
11877
  rr_type: name,
11875
- args: [serializeArg(value.data, win, ctx), value.width, value.height]
11878
+ args: [
11879
+ serializeArg(value.data, win, ctx, dataURLOptions),
11880
+ value.width,
11881
+ value.height
11882
+ ]
11876
11883
  };
11877
11884
  } else if (isInstanceOfWebGLObject(value, win) || typeof value === "object") {
11878
11885
  const name = value.constructor.name;
@@ -11884,8 +11891,8 @@ function serializeArg(value, win, ctx) {
11884
11891
  }
11885
11892
  return value;
11886
11893
  }
11887
- const serializeArgs = (args, win, ctx) => {
11888
- return args.map((arg) => serializeArg(arg, win, ctx));
11894
+ const serializeArgs = (args, win, ctx, dataURLOptions) => {
11895
+ return args.map((arg) => serializeArg(arg, win, ctx, dataURLOptions));
11889
11896
  };
11890
11897
  const isInstanceOfWebGLObject = (value, win) => {
11891
11898
  const webGLConstructorNames = [
@@ -11911,7 +11918,7 @@ const isInstanceOfWebGLObject = (value, win) => {
11911
11918
  )
11912
11919
  );
11913
11920
  };
11914
- function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector) {
11921
+ function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector, dataURLOptions) {
11915
11922
  const handlers = [];
11916
11923
  const props2D = Object.getOwnPropertyNames(
11917
11924
  win.CanvasRenderingContext2D.prototype
@@ -11928,7 +11935,12 @@ function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector) {
11928
11935
  return function(...args) {
11929
11936
  if (!isBlocked(this.canvas, blockClass, blockSelector, true)) {
11930
11937
  setTimeout(() => {
11931
- const recordArgs = serializeArgs(args, win, this);
11938
+ const recordArgs = serializeArgs(
11939
+ args,
11940
+ win,
11941
+ this,
11942
+ dataURLOptions
11943
+ );
11932
11944
  cb(this.canvas, {
11933
11945
  type: CanvasContext["2D"],
11934
11946
  property: prop,
@@ -12002,7 +12014,7 @@ function initCanvasContextObserver(win, blockClass, blockSelector, setPreserveDr
12002
12014
  handlers.forEach((h) => h());
12003
12015
  };
12004
12016
  }
12005
- function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win) {
12017
+ function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win, dataURLOptions) {
12006
12018
  const handlers = [];
12007
12019
  const props = Object.getOwnPropertyNames(prototype);
12008
12020
  for (const prop of props) {
@@ -12029,7 +12041,7 @@ function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win) {
12029
12041
  const result2 = original.apply(this, args);
12030
12042
  saveWebGLVar(result2, win, this);
12031
12043
  if ("tagName" in this.canvas && !isBlocked(this.canvas, blockClass, blockSelector, true)) {
12032
- const recordArgs = serializeArgs(args, win, this);
12044
+ const recordArgs = serializeArgs(args, win, this, dataURLOptions);
12033
12045
  const mutation = {
12034
12046
  type,
12035
12047
  property: prop,
@@ -12058,7 +12070,7 @@ function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win) {
12058
12070
  }
12059
12071
  return handlers;
12060
12072
  }
12061
- function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector) {
12073
+ function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector, dataURLOptions) {
12062
12074
  const handlers = [];
12063
12075
  handlers.push(
12064
12076
  ...patchGLPrototype(
@@ -12067,7 +12079,8 @@ function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector) {
12067
12079
  cb,
12068
12080
  blockClass,
12069
12081
  blockSelector,
12070
- win
12082
+ win,
12083
+ dataURLOptions
12071
12084
  )
12072
12085
  );
12073
12086
  if (typeof win.WebGL2RenderingContext !== "undefined") {
@@ -12078,7 +12091,8 @@ function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector) {
12078
12091
  cb,
12079
12092
  blockClass,
12080
12093
  blockSelector,
12081
- win
12094
+ win,
12095
+ dataURLOptions
12082
12096
  )
12083
12097
  );
12084
12098
  }
@@ -12140,7 +12154,12 @@ class CanvasManager {
12140
12154
  this.mutationCb = options.mutationCb;
12141
12155
  this.mirror = options.mirror;
12142
12156
  if (recordCanvas && sampling === "all")
12143
- this.initCanvasMutationObserver(win, blockClass, blockSelector);
12157
+ this.initCanvasMutationObserver(
12158
+ win,
12159
+ blockClass,
12160
+ blockSelector,
12161
+ dataURLOptions
12162
+ );
12144
12163
  if (recordCanvas && typeof sampling === "number")
12145
12164
  this.initCanvasFPSObserver(sampling, win, blockClass, blockSelector, {
12146
12165
  dataURLOptions
@@ -12269,7 +12288,7 @@ class CanvasManager {
12269
12288
  cancelAnimationFrame(rafId);
12270
12289
  };
12271
12290
  }
12272
- initCanvasMutationObserver(win, blockClass, blockSelector) {
12291
+ initCanvasMutationObserver(win, blockClass, blockSelector, dataURLOptions) {
12273
12292
  this.startRAFTimestamping();
12274
12293
  this.startPendingCanvasMutationFlusher();
12275
12294
  const canvasContextReset = initCanvasContextObserver(
@@ -12282,13 +12301,15 @@ class CanvasManager {
12282
12301
  this.processMutation.bind(this),
12283
12302
  win,
12284
12303
  blockClass,
12285
- blockSelector
12304
+ blockSelector,
12305
+ dataURLOptions
12286
12306
  );
12287
12307
  const canvasWebGL1and2Reset = initCanvasWebGLMutationObserver(
12288
12308
  this.processMutation.bind(this),
12289
12309
  win,
12290
12310
  blockClass,
12291
- blockSelector
12311
+ blockSelector,
12312
+ dataURLOptions
12292
12313
  );
12293
12314
  this.resetObservers = () => {
12294
12315
  canvasContextReset();
@@ -12848,13 +12869,14 @@ function record(options = {}) {
12848
12869
  hooks
12849
12870
  );
12850
12871
  };
12851
- iframeManager.addLoadListener((iframeEl) => {
12872
+ const loadListener = (iframeEl) => {
12852
12873
  try {
12853
12874
  handlers.push(observe(iframeEl.contentDocument));
12854
12875
  } catch (error) {
12855
12876
  console.warn(error);
12856
12877
  }
12857
- });
12878
+ };
12879
+ iframeManager.addLoadListener(loadListener);
12858
12880
  const init = () => {
12859
12881
  takeFullSnapshot$1();
12860
12882
  handlers.push(observe(document));
@@ -12889,6 +12911,7 @@ function record(options = {}) {
12889
12911
  return () => {
12890
12912
  handlers.forEach((h) => h());
12891
12913
  processedNodeManager.destroy();
12914
+ iframeManager.removeLoadListener();
12892
12915
  iframeManager.destroy();
12893
12916
  recording = false;
12894
12917
  unregisterErrorHandler();