@sentry/replay 7.32.1 → 7.34.0-beta.0

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/cjs/index.js CHANGED
@@ -22,12 +22,6 @@ const VISIBILITY_CHANGE_TIMEOUT = SESSION_IDLE_DURATION;
22
22
  // The maximum length of a session
23
23
  const MAX_SESSION_LIFE = 3600000; // 60 minutes
24
24
 
25
- /**
26
- * Defaults for sampling rates
27
- */
28
- const DEFAULT_SESSION_SAMPLE_RATE = 0.1;
29
- const DEFAULT_ERROR_SAMPLE_RATE = 1.0;
30
-
31
25
  /** The select to use for the `maskAllText` option */
32
26
  const MASK_ALL_TEXT_SELECTOR = 'body *:not(style), body *:not(script)';
33
27
 
@@ -134,10 +128,14 @@ function isShadowRoot(n) {
134
128
  return Boolean(host && host.shadowRoot && host.shadowRoot === n);
135
129
  }
136
130
  function maskInputValue(_a) {
137
- var maskInputOptions = _a.maskInputOptions, tagName = _a.tagName, type = _a.type, value = _a.value, maskInputFn = _a.maskInputFn;
131
+ var input = _a.input, maskInputSelector = _a.maskInputSelector, unmaskInputSelector = _a.unmaskInputSelector, maskInputOptions = _a.maskInputOptions, tagName = _a.tagName, type = _a.type, value = _a.value, maskInputFn = _a.maskInputFn;
138
132
  var text = value || '';
133
+ if (unmaskInputSelector && input.matches(unmaskInputSelector)) {
134
+ return text;
135
+ }
139
136
  if (maskInputOptions[tagName.toLowerCase()] ||
140
- maskInputOptions[type]) {
137
+ maskInputOptions[type] ||
138
+ (maskInputSelector && input.matches(maskInputSelector))) {
141
139
  if (maskInputFn) {
142
140
  text = maskInputFn(text);
143
141
  }
@@ -364,7 +362,10 @@ function transformAttribute(doc, tagName, name, value) {
364
362
  return value;
365
363
  }
366
364
  }
367
- function _isBlockedElement(element, blockClass, blockSelector) {
365
+ function _isBlockedElement(element, blockClass, blockSelector, unblockSelector) {
366
+ if (unblockSelector && element.matches(unblockSelector)) {
367
+ return false;
368
+ }
368
369
  if (typeof blockClass === 'string') {
369
370
  if (element.classList.contains(blockClass)) {
370
371
  return true;
@@ -383,11 +384,16 @@ function _isBlockedElement(element, blockClass, blockSelector) {
383
384
  }
384
385
  return false;
385
386
  }
386
- function needMaskingText(node, maskTextClass, maskTextSelector) {
387
+ function needMaskingText(node, maskTextClass, maskTextSelector, unmaskTextSelector) {
387
388
  if (!node) {
388
389
  return false;
389
390
  }
390
391
  if (node.nodeType === node.ELEMENT_NODE) {
392
+ if (unmaskTextSelector) {
393
+ if (node.matches(unmaskTextSelector) || node.closest(unmaskTextSelector)) {
394
+ return false;
395
+ }
396
+ }
391
397
  if (typeof maskTextClass === 'string') {
392
398
  if (node.classList.contains(maskTextClass)) {
393
399
  return true;
@@ -406,12 +412,12 @@ function needMaskingText(node, maskTextClass, maskTextSelector) {
406
412
  return true;
407
413
  }
408
414
  }
409
- return needMaskingText(node.parentNode, maskTextClass, maskTextSelector);
415
+ return needMaskingText(node.parentNode, maskTextClass, maskTextSelector, unmaskTextSelector);
410
416
  }
411
417
  if (node.nodeType === node.TEXT_NODE) {
412
- return needMaskingText(node.parentNode, maskTextClass, maskTextSelector);
418
+ return needMaskingText(node.parentNode, maskTextClass, maskTextSelector, unmaskTextSelector);
413
419
  }
414
- return needMaskingText(node.parentNode, maskTextClass, maskTextSelector);
420
+ return needMaskingText(node.parentNode, maskTextClass, maskTextSelector, unmaskTextSelector);
415
421
  }
416
422
  function onceIframeLoaded(iframeEl, listener, iframeLoadTimeout) {
417
423
  var win = iframeEl.contentWindow;
@@ -451,7 +457,7 @@ function onceIframeLoaded(iframeEl, listener, iframeLoadTimeout) {
451
457
  }
452
458
  function serializeNode(n, options) {
453
459
  var _a;
454
- var doc = options.doc, blockClass = options.blockClass, blockSelector = options.blockSelector, maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, inlineStylesheet = options.inlineStylesheet, _b = options.maskInputOptions, maskInputOptions = _b === void 0 ? {} : _b, maskTextFn = options.maskTextFn, maskInputFn = options.maskInputFn, _c = options.dataURLOptions, dataURLOptions = _c === void 0 ? {} : _c, inlineImages = options.inlineImages, recordCanvas = options.recordCanvas, keepIframeSrcFn = options.keepIframeSrcFn;
460
+ var doc = options.doc, blockClass = options.blockClass, blockSelector = options.blockSelector, unblockSelector = options.unblockSelector, maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, unmaskTextSelector = options.unmaskTextSelector, inlineStylesheet = options.inlineStylesheet, maskInputSelector = options.maskInputSelector, unmaskInputSelector = options.unmaskInputSelector, _b = options.maskInputOptions, maskInputOptions = _b === void 0 ? {} : _b, maskTextFn = options.maskTextFn, maskInputFn = options.maskInputFn, _c = options.dataURLOptions, dataURLOptions = _c === void 0 ? {} : _c, inlineImages = options.inlineImages, recordCanvas = options.recordCanvas, keepIframeSrcFn = options.keepIframeSrcFn;
455
461
  var rootId;
456
462
  if (doc.__sn) {
457
463
  var docId = doc.__sn.id;
@@ -483,7 +489,7 @@ function serializeNode(n, options) {
483
489
  rootId: rootId
484
490
  };
485
491
  case n.ELEMENT_NODE:
486
- var needBlock = _isBlockedElement(n, blockClass, blockSelector);
492
+ var needBlock = _isBlockedElement(n, blockClass, blockSelector, unblockSelector);
487
493
  var tagName = getValidTagName(n);
488
494
  var attributes_1 = {};
489
495
  for (var _i = 0, _d = Array.from(n.attributes); _i < _d.length; _i++) {
@@ -524,9 +530,12 @@ function serializeNode(n, options) {
524
530
  attributes_1.type !== 'button' &&
525
531
  value) {
526
532
  attributes_1.value = maskInputValue({
533
+ input: n,
527
534
  type: attributes_1.type,
528
535
  tagName: tagName,
529
536
  value: value,
537
+ maskInputSelector: maskInputSelector,
538
+ unmaskInputSelector: unmaskInputSelector,
530
539
  maskInputOptions: maskInputOptions,
531
540
  maskInputFn: maskInputFn
532
541
  });
@@ -645,7 +654,7 @@ function serializeNode(n, options) {
645
654
  }
646
655
  if (!isStyle &&
647
656
  !isScript &&
648
- needMaskingText(n, maskTextClass, maskTextSelector) &&
657
+ needMaskingText(n, maskTextClass, maskTextSelector, unmaskTextSelector) &&
649
658
  textContent) {
650
659
  textContent = maskTextFn
651
660
  ? maskTextFn(textContent)
@@ -753,15 +762,19 @@ function slimDOMExcluded(sn, slimDOMOptions) {
753
762
  return false;
754
763
  }
755
764
  function serializeNodeWithId(n, options) {
756
- var doc = options.doc, map = options.map, blockClass = options.blockClass, blockSelector = options.blockSelector, maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, _a = options.skipChild, skipChild = _a === void 0 ? false : _a, _b = options.inlineStylesheet, inlineStylesheet = _b === void 0 ? true : _b, _c = options.maskInputOptions, maskInputOptions = _c === void 0 ? {} : _c, maskTextFn = options.maskTextFn, maskInputFn = options.maskInputFn, slimDOMOptions = options.slimDOMOptions, _d = options.dataURLOptions, dataURLOptions = _d === void 0 ? {} : _d, _e = options.inlineImages, inlineImages = _e === void 0 ? false : _e, _f = options.recordCanvas, recordCanvas = _f === void 0 ? false : _f, onSerialize = options.onSerialize, onIframeLoad = options.onIframeLoad, _g = options.iframeLoadTimeout, iframeLoadTimeout = _g === void 0 ? 5000 : _g, _h = options.keepIframeSrcFn, keepIframeSrcFn = _h === void 0 ? function () { return false; } : _h;
765
+ var doc = options.doc, map = options.map, blockClass = options.blockClass, blockSelector = options.blockSelector, unblockSelector = options.unblockSelector, maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, unmaskTextSelector = options.unmaskTextSelector, _a = options.skipChild, skipChild = _a === void 0 ? false : _a, _b = options.inlineStylesheet, inlineStylesheet = _b === void 0 ? true : _b, maskInputSelector = options.maskInputSelector, unmaskInputSelector = options.unmaskInputSelector, _c = options.maskInputOptions, maskInputOptions = _c === void 0 ? {} : _c, maskTextFn = options.maskTextFn, maskInputFn = options.maskInputFn, slimDOMOptions = options.slimDOMOptions, _d = options.dataURLOptions, dataURLOptions = _d === void 0 ? {} : _d, _e = options.inlineImages, inlineImages = _e === void 0 ? false : _e, _f = options.recordCanvas, recordCanvas = _f === void 0 ? false : _f, onSerialize = options.onSerialize, onIframeLoad = options.onIframeLoad, _g = options.iframeLoadTimeout, iframeLoadTimeout = _g === void 0 ? 5000 : _g, _h = options.keepIframeSrcFn, keepIframeSrcFn = _h === void 0 ? function () { return false; } : _h;
757
766
  var _j = options.preserveWhiteSpace, preserveWhiteSpace = _j === void 0 ? true : _j;
758
767
  var _serializedNode = serializeNode(n, {
759
768
  doc: doc,
760
769
  blockClass: blockClass,
761
770
  blockSelector: blockSelector,
771
+ unblockSelector: unblockSelector,
762
772
  maskTextClass: maskTextClass,
763
773
  maskTextSelector: maskTextSelector,
774
+ unmaskTextSelector: unmaskTextSelector,
764
775
  inlineStylesheet: inlineStylesheet,
776
+ maskInputSelector: maskInputSelector,
777
+ unmaskInputSelector: unmaskInputSelector,
765
778
  maskInputOptions: maskInputOptions,
766
779
  maskTextFn: maskTextFn,
767
780
  maskInputFn: maskInputFn,
@@ -817,10 +830,14 @@ function serializeNodeWithId(n, options) {
817
830
  map: map,
818
831
  blockClass: blockClass,
819
832
  blockSelector: blockSelector,
833
+ unblockSelector: unblockSelector,
820
834
  maskTextClass: maskTextClass,
821
835
  maskTextSelector: maskTextSelector,
836
+ unmaskTextSelector: unmaskTextSelector,
822
837
  skipChild: skipChild,
823
838
  inlineStylesheet: inlineStylesheet,
839
+ maskInputSelector: maskInputSelector,
840
+ unmaskInputSelector: unmaskInputSelector,
824
841
  maskInputOptions: maskInputOptions,
825
842
  maskTextFn: maskTextFn,
826
843
  maskInputFn: maskInputFn,
@@ -865,10 +882,14 @@ function serializeNodeWithId(n, options) {
865
882
  map: map,
866
883
  blockClass: blockClass,
867
884
  blockSelector: blockSelector,
885
+ unblockSelector: unblockSelector,
868
886
  maskTextClass: maskTextClass,
869
887
  maskTextSelector: maskTextSelector,
888
+ unmaskTextSelector: unmaskTextSelector,
870
889
  skipChild: false,
871
890
  inlineStylesheet: inlineStylesheet,
891
+ maskInputSelector: maskInputSelector,
892
+ unmaskInputSelector: unmaskInputSelector,
872
893
  maskInputOptions: maskInputOptions,
873
894
  maskTextFn: maskTextFn,
874
895
  maskInputFn: maskInputFn,
@@ -891,7 +912,7 @@ function serializeNodeWithId(n, options) {
891
912
  return serializedNode;
892
913
  }
893
914
  function snapshot(n, options) {
894
- var _a = options || {}, _b = _a.blockClass, blockClass = _b === void 0 ? 'rr-block' : _b, _c = _a.blockSelector, blockSelector = _c === void 0 ? null : _c, _d = _a.maskTextClass, maskTextClass = _d === void 0 ? 'rr-mask' : _d, _e = _a.maskTextSelector, maskTextSelector = _e === void 0 ? null : _e, _f = _a.inlineStylesheet, inlineStylesheet = _f === void 0 ? true : _f, _g = _a.inlineImages, inlineImages = _g === void 0 ? false : _g, _h = _a.recordCanvas, recordCanvas = _h === void 0 ? false : _h, _j = _a.maskAllInputs, maskAllInputs = _j === void 0 ? false : _j, maskTextFn = _a.maskTextFn, maskInputFn = _a.maskInputFn, _k = _a.slimDOM, slimDOM = _k === void 0 ? false : _k, dataURLOptions = _a.dataURLOptions, preserveWhiteSpace = _a.preserveWhiteSpace, onSerialize = _a.onSerialize, onIframeLoad = _a.onIframeLoad, iframeLoadTimeout = _a.iframeLoadTimeout, _l = _a.keepIframeSrcFn, keepIframeSrcFn = _l === void 0 ? function () { return false; } : _l;
915
+ var _a = options || {}, _b = _a.blockClass, blockClass = _b === void 0 ? 'rr-block' : _b, _c = _a.blockSelector, blockSelector = _c === void 0 ? null : _c, _d = _a.unblockSelector, unblockSelector = _d === void 0 ? null : _d, _e = _a.maskTextClass, maskTextClass = _e === void 0 ? 'rr-mask' : _e, _f = _a.maskTextSelector, maskTextSelector = _f === void 0 ? null : _f, _g = _a.unmaskTextSelector, unmaskTextSelector = _g === void 0 ? null : _g, _h = _a.inlineStylesheet, inlineStylesheet = _h === void 0 ? true : _h, _j = _a.inlineImages, inlineImages = _j === void 0 ? false : _j, _k = _a.recordCanvas, recordCanvas = _k === void 0 ? false : _k, _l = _a.maskInputSelector, maskInputSelector = _l === void 0 ? null : _l, _m = _a.unmaskInputSelector, unmaskInputSelector = _m === void 0 ? null : _m, _o = _a.maskAllInputs, maskAllInputs = _o === void 0 ? false : _o, maskTextFn = _a.maskTextFn, maskInputFn = _a.maskInputFn, _p = _a.slimDOM, slimDOM = _p === void 0 ? false : _p, dataURLOptions = _a.dataURLOptions, preserveWhiteSpace = _a.preserveWhiteSpace, onSerialize = _a.onSerialize, onIframeLoad = _a.onIframeLoad, iframeLoadTimeout = _a.iframeLoadTimeout, _q = _a.keepIframeSrcFn, keepIframeSrcFn = _q === void 0 ? function () { return false; } : _q;
895
916
  var idNodeMap = {};
896
917
  var maskInputOptions = maskAllInputs === true
897
918
  ? {
@@ -940,10 +961,14 @@ function snapshot(n, options) {
940
961
  map: idNodeMap,
941
962
  blockClass: blockClass,
942
963
  blockSelector: blockSelector,
964
+ unblockSelector: unblockSelector,
943
965
  maskTextClass: maskTextClass,
944
966
  maskTextSelector: maskTextSelector,
967
+ unmaskTextSelector: unmaskTextSelector,
945
968
  skipChild: false,
946
969
  inlineStylesheet: inlineStylesheet,
970
+ maskInputSelector: maskInputSelector,
971
+ unmaskInputSelector: unmaskInputSelector,
947
972
  maskInputOptions: maskInputOptions,
948
973
  maskTextFn: maskTextFn,
949
974
  maskInputFn: maskInputFn,
@@ -1419,8 +1444,12 @@ var MutationBuffer = (function () {
1419
1444
  map: _this.mirror.map,
1420
1445
  blockClass: _this.blockClass,
1421
1446
  blockSelector: _this.blockSelector,
1447
+ unblockSelector: _this.unblockSelector,
1422
1448
  maskTextClass: _this.maskTextClass,
1423
1449
  maskTextSelector: _this.maskTextSelector,
1450
+ unmaskTextSelector: _this.unmaskTextSelector,
1451
+ maskInputSelector: _this.maskInputSelector,
1452
+ unmaskInputSelector: _this.unmaskInputSelector,
1424
1453
  skipChild: true,
1425
1454
  inlineStylesheet: _this.inlineStylesheet,
1426
1455
  maskInputOptions: _this.maskInputOptions,
@@ -1566,7 +1595,7 @@ var MutationBuffer = (function () {
1566
1595
  var value = m.target.textContent;
1567
1596
  if (!isBlocked(m.target, _this.blockClass) && value !== m.oldValue) {
1568
1597
  _this.texts.push({
1569
- value: needMaskingText(m.target, _this.maskTextClass, _this.maskTextSelector) && value
1598
+ value: needMaskingText(m.target, _this.maskTextClass, _this.maskTextSelector, _this.unmaskTextSelector) && value
1570
1599
  ? _this.maskTextFn
1571
1600
  ? _this.maskTextFn(value)
1572
1601
  : value.replace(/[\S]/g, '*')
@@ -1581,6 +1610,9 @@ var MutationBuffer = (function () {
1581
1610
  var value = m.target.getAttribute(m.attributeName);
1582
1611
  if (m.attributeName === 'value') {
1583
1612
  value = maskInputValue({
1613
+ input: target,
1614
+ maskInputSelector: _this.maskInputSelector,
1615
+ unmaskInputSelector: _this.unmaskInputSelector,
1584
1616
  maskInputOptions: _this.maskInputOptions,
1585
1617
  tagName: m.target.tagName,
1586
1618
  type: m.target.getAttribute('type'),
@@ -1717,8 +1749,12 @@ var MutationBuffer = (function () {
1717
1749
  'mutationCb',
1718
1750
  'blockClass',
1719
1751
  'blockSelector',
1752
+ 'unblockSelector',
1720
1753
  'maskTextClass',
1721
1754
  'maskTextSelector',
1755
+ 'unmaskTextSelector',
1756
+ 'maskInputSelector',
1757
+ 'unmaskInputSelector',
1722
1758
  'inlineStylesheet',
1723
1759
  'maskInputOptions',
1724
1760
  'maskTextFn',
@@ -1984,7 +2020,7 @@ function wrapEventWithUserTriggeredFlag(v, enable) {
1984
2020
  var INPUT_TAGS = ['INPUT', 'TEXTAREA', 'SELECT'];
1985
2021
  var lastInputValueMap = new WeakMap();
1986
2022
  function initInputObserver(_a) {
1987
- var inputCb = _a.inputCb, doc = _a.doc, mirror = _a.mirror, blockClass = _a.blockClass, ignoreClass = _a.ignoreClass, maskInputOptions = _a.maskInputOptions, maskInputFn = _a.maskInputFn, sampling = _a.sampling, userTriggeredOnInput = _a.userTriggeredOnInput;
2023
+ var inputCb = _a.inputCb, doc = _a.doc, mirror = _a.mirror, blockClass = _a.blockClass, ignoreClass = _a.ignoreClass, ignoreSelector = _a.ignoreSelector, maskInputSelector = _a.maskInputSelector, unmaskInputSelector = _a.unmaskInputSelector, maskInputOptions = _a.maskInputOptions, maskInputFn = _a.maskInputFn, sampling = _a.sampling, userTriggeredOnInput = _a.userTriggeredOnInput;
1988
2024
  function eventHandler(event) {
1989
2025
  var target = getEventTarget(event);
1990
2026
  var userTriggered = event.isTrusted;
@@ -1997,7 +2033,7 @@ function initInputObserver(_a) {
1997
2033
  return;
1998
2034
  }
1999
2035
  var type = target.type;
2000
- if (target.classList.contains(ignoreClass)) {
2036
+ if (target.classList.contains(ignoreClass) || (ignoreSelector && target.matches(ignoreSelector))) {
2001
2037
  return;
2002
2038
  }
2003
2039
  var text = target.value;
@@ -2008,7 +2044,10 @@ function initInputObserver(_a) {
2008
2044
  else if (maskInputOptions[target.tagName.toLowerCase()] ||
2009
2045
  maskInputOptions[type]) {
2010
2046
  text = maskInputValue({
2047
+ input: target,
2011
2048
  maskInputOptions: maskInputOptions,
2049
+ maskInputSelector: maskInputSelector,
2050
+ unmaskInputSelector: unmaskInputSelector,
2012
2051
  tagName: target.tagName,
2013
2052
  type: type,
2014
2053
  value: text,
@@ -2092,6 +2131,9 @@ function getNestedCSSRulePositions(rule) {
2092
2131
  function initStyleSheetObserver(_a, _b) {
2093
2132
  var styleSheetRuleCb = _a.styleSheetRuleCb, mirror = _a.mirror;
2094
2133
  var win = _b.win;
2134
+ if (!win.CSSStyleSheet || !win.CSSStyleSheet.prototype) {
2135
+ return function () { };
2136
+ }
2095
2137
  var insertRule = win.CSSStyleSheet.prototype.insertRule;
2096
2138
  win.CSSStyleSheet.prototype.insertRule = function (rule, index) {
2097
2139
  var id = mirror.getId(this.ownerNode);
@@ -2924,7 +2966,7 @@ var takeFullSnapshot;
2924
2966
  var mirror = createMirror();
2925
2967
  function record(options) {
2926
2968
  if (options === void 0) { options = {}; }
2927
- var emit = options.emit, checkoutEveryNms = options.checkoutEveryNms, checkoutEveryNth = options.checkoutEveryNth, _a = options.blockClass, blockClass = _a === void 0 ? 'rr-block' : _a, _b = options.blockSelector, blockSelector = _b === void 0 ? null : _b, _c = options.ignoreClass, ignoreClass = _c === void 0 ? 'rr-ignore' : _c, _d = options.maskTextClass, maskTextClass = _d === void 0 ? 'rr-mask' : _d, _e = options.maskTextSelector, maskTextSelector = _e === void 0 ? null : _e, _f = options.inlineStylesheet, inlineStylesheet = _f === void 0 ? true : _f, maskAllInputs = options.maskAllInputs, _maskInputOptions = options.maskInputOptions, _slimDOMOptions = options.slimDOMOptions, maskInputFn = options.maskInputFn, maskTextFn = options.maskTextFn, hooks = options.hooks, packFn = options.packFn, _g = options.sampling, sampling = _g === void 0 ? {} : _g, mousemoveWait = options.mousemoveWait, _h = options.recordCanvas, recordCanvas = _h === void 0 ? false : _h, _j = options.userTriggeredOnInput, userTriggeredOnInput = _j === void 0 ? false : _j, _k = options.collectFonts, collectFonts = _k === void 0 ? false : _k, _l = options.inlineImages, inlineImages = _l === void 0 ? false : _l, plugins = options.plugins, _m = options.keepIframeSrcFn, keepIframeSrcFn = _m === void 0 ? function () { return false; } : _m;
2969
+ var emit = options.emit, checkoutEveryNms = options.checkoutEveryNms, checkoutEveryNth = options.checkoutEveryNth, _a = options.blockClass, blockClass = _a === void 0 ? 'rr-block' : _a, _b = options.blockSelector, blockSelector = _b === void 0 ? null : _b, _c = options.unblockSelector, unblockSelector = _c === void 0 ? null : _c, _d = options.ignoreClass, ignoreClass = _d === void 0 ? 'rr-ignore' : _d, _e = options.ignoreSelector, ignoreSelector = _e === void 0 ? null : _e, _f = options.maskTextClass, maskTextClass = _f === void 0 ? 'rr-mask' : _f, _g = options.maskTextSelector, maskTextSelector = _g === void 0 ? null : _g, _h = options.maskInputSelector, maskInputSelector = _h === void 0 ? null : _h, _j = options.unmaskTextSelector, unmaskTextSelector = _j === void 0 ? null : _j, _k = options.unmaskInputSelector, unmaskInputSelector = _k === void 0 ? null : _k, _l = options.inlineStylesheet, inlineStylesheet = _l === void 0 ? true : _l, maskAllInputs = options.maskAllInputs, _maskInputOptions = options.maskInputOptions, _slimDOMOptions = options.slimDOMOptions, maskInputFn = options.maskInputFn, maskTextFn = options.maskTextFn, hooks = options.hooks, packFn = options.packFn, _m = options.sampling, sampling = _m === void 0 ? {} : _m, mousemoveWait = options.mousemoveWait, _o = options.recordCanvas, recordCanvas = _o === void 0 ? false : _o, _p = options.userTriggeredOnInput, userTriggeredOnInput = _p === void 0 ? false : _p, _q = options.collectFonts, collectFonts = _q === void 0 ? false : _q, _r = options.inlineImages, inlineImages = _r === void 0 ? false : _r, plugins = options.plugins, _s = options.keepIframeSrcFn, keepIframeSrcFn = _s === void 0 ? function () { return false; } : _s;
2928
2970
  if (!emit) {
2929
2971
  throw new Error('emit function is required');
2930
2972
  }
@@ -3055,8 +3097,12 @@ function record(options) {
3055
3097
  bypassOptions: {
3056
3098
  blockClass: blockClass,
3057
3099
  blockSelector: blockSelector,
3100
+ unblockSelector: unblockSelector,
3058
3101
  maskTextClass: maskTextClass,
3059
3102
  maskTextSelector: maskTextSelector,
3103
+ unmaskTextSelector: unmaskTextSelector,
3104
+ maskInputSelector: maskInputSelector,
3105
+ unmaskInputSelector: unmaskInputSelector,
3060
3106
  inlineStylesheet: inlineStylesheet,
3061
3107
  maskInputOptions: maskInputOptions,
3062
3108
  maskTextFn: maskTextFn,
@@ -3085,8 +3131,12 @@ function record(options) {
3085
3131
  var _e = __read(snapshot(document, {
3086
3132
  blockClass: blockClass,
3087
3133
  blockSelector: blockSelector,
3134
+ unblockSelector: unblockSelector,
3088
3135
  maskTextClass: maskTextClass,
3089
3136
  maskTextSelector: maskTextSelector,
3137
+ unmaskTextSelector: unmaskTextSelector,
3138
+ maskInputSelector: maskInputSelector,
3139
+ unmaskInputSelector: unmaskInputSelector,
3090
3140
  inlineStylesheet: inlineStylesheet,
3091
3141
  maskAllInputs: maskInputOptions,
3092
3142
  maskTextFn: maskTextFn,
@@ -3200,8 +3250,12 @@ function record(options) {
3200
3250
  },
3201
3251
  blockClass: blockClass,
3202
3252
  ignoreClass: ignoreClass,
3253
+ ignoreSelector: ignoreSelector,
3203
3254
  maskTextClass: maskTextClass,
3204
3255
  maskTextSelector: maskTextSelector,
3256
+ unmaskTextSelector: unmaskTextSelector,
3257
+ maskInputSelector: maskInputSelector,
3258
+ unmaskInputSelector: unmaskInputSelector,
3205
3259
  maskInputOptions: maskInputOptions,
3206
3260
  inlineStylesheet: inlineStylesheet,
3207
3261
  sampling: sampling,
@@ -3213,6 +3267,7 @@ function record(options) {
3213
3267
  maskInputFn: maskInputFn,
3214
3268
  maskTextFn: maskTextFn,
3215
3269
  blockSelector: blockSelector,
3270
+ unblockSelector: unblockSelector,
3216
3271
  slimDOMOptions: slimDOMOptions,
3217
3272
  mirror: mirror,
3218
3273
  iframeManager: iframeManager,
@@ -3236,8 +3291,9 @@ function record(options) {
3236
3291
  iframeManager.addLoadListener(function (iframeEl) {
3237
3292
  try {
3238
3293
  handlers_1.push(observe_1(iframeEl.contentDocument));
3239
- } catch (error) {
3240
- console.warn('error in rrweb iframe observer', error);
3294
+ }
3295
+ catch (error) {
3296
+ console.warn(error);
3241
3297
  }
3242
3298
  });
3243
3299
  var init_1 = function () {
@@ -3288,1087 +3344,1158 @@ record.takeFullSnapshot = function (isCheckout) {
3288
3344
  };
3289
3345
  record.mirror = mirror;
3290
3346
 
3291
- /**
3292
- * Create a breadcrumb for a replay.
3293
- */
3294
- function createBreadcrumb(
3295
- breadcrumb,
3296
- ) {
3297
- return {
3298
- timestamp: new Date().getTime() / 1000,
3299
- type: 'default',
3300
- ...breadcrumb,
3347
+ const NAVIGATION_ENTRY_KEYS = [
3348
+ 'name',
3349
+ 'type',
3350
+ 'startTime',
3351
+ 'transferSize',
3352
+ 'duration',
3353
+ ];
3354
+
3355
+ function isNavigationEntryEqual(a) {
3356
+ return function (b) {
3357
+ return NAVIGATION_ENTRY_KEYS.every(key => a[key] === b[key]);
3301
3358
  };
3302
3359
  }
3303
3360
 
3304
3361
  /**
3305
- * An event handler to react to DOM events.
3362
+ * There are some difficulties diagnosing why there are duplicate navigation
3363
+ * entries. We've witnessed several intermittent results:
3364
+ * - duplicate entries have duration = 0
3365
+ * - duplicate entries are the same object reference
3366
+ * - none of the above
3367
+ *
3368
+ * Compare the values of several keys to determine if the entries are duplicates or not.
3306
3369
  */
3307
- function handleDom(handlerData) {
3308
- // Taken from https://github.com/getsentry/sentry-javascript/blob/master/packages/browser/src/integrations/breadcrumbs.ts#L112
3309
- let target;
3310
- let targetNode;
3370
+ // TODO (high-prio): Figure out wth is returned here
3371
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
3372
+ function dedupePerformanceEntries(
3373
+ currentList,
3374
+ newList,
3375
+ ) {
3376
+ // Partition `currentList` into 3 different lists based on entryType
3377
+ const [existingNavigationEntries, existingLcpEntries, existingEntries] = currentList.reduce(
3378
+ (acc, entry) => {
3379
+ if (entry.entryType === 'navigation') {
3380
+ acc[0].push(entry );
3381
+ } else if (entry.entryType === 'largest-contentful-paint') {
3382
+ acc[1].push(entry );
3383
+ } else {
3384
+ acc[2].push(entry);
3385
+ }
3386
+ return acc;
3387
+ },
3388
+ [[], [], []],
3389
+ );
3311
3390
 
3312
- // Accessing event.target can throw (see getsentry/raven-js#838, #768)
3313
- try {
3314
- targetNode = getTargetNode(handlerData);
3315
- target = utils.htmlTreeAsString(targetNode);
3316
- } catch (e) {
3317
- target = '<unknown>';
3318
- }
3391
+ const newEntries = [];
3392
+ const newNavigationEntries = [];
3393
+ let newLcpEntry = existingLcpEntries.length
3394
+ ? existingLcpEntries[existingLcpEntries.length - 1] // Take the last element as list is sorted
3395
+ : undefined;
3319
3396
 
3320
- if (target.length === 0) {
3321
- return null;
3322
- }
3397
+ newList.forEach(entry => {
3398
+ if (entry.entryType === 'largest-contentful-paint') {
3399
+ // We want the latest LCP event only
3400
+ if (!newLcpEntry || newLcpEntry.startTime < entry.startTime) {
3401
+ newLcpEntry = entry;
3402
+ }
3403
+ return;
3404
+ }
3323
3405
 
3324
- return createBreadcrumb({
3325
- category: `ui.${handlerData.name}`,
3326
- message: target,
3327
- data: {
3328
- // Not sure why this errors, Node should be correct (Argument of type 'Node' is not assignable to parameter of type 'INode')
3329
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3330
- ...(targetNode ? { nodeId: record.mirror.getId(targetNode ) } : {}),
3331
- },
3332
- });
3333
- }
3406
+ if (entry.entryType === 'navigation') {
3407
+ const navigationEntry = entry ;
3334
3408
 
3335
- function getTargetNode(handlerData) {
3336
- if (isEventWithTarget(handlerData.event)) {
3337
- return handlerData.event.target;
3338
- }
3409
+ // Check if the navigation entry is contained in currentList or newList
3410
+ if (
3411
+ // Ignore any navigation entries with duration 0, as they are likely duplicates
3412
+ entry.duration > 0 &&
3413
+ // Ensure new entry does not already exist in existing entries
3414
+ !existingNavigationEntries.find(isNavigationEntryEqual(navigationEntry)) &&
3415
+ // Ensure new entry does not already exist in new list of navigation entries
3416
+ !newNavigationEntries.find(isNavigationEntryEqual(navigationEntry))
3417
+ ) {
3418
+ newNavigationEntries.push(navigationEntry);
3419
+ }
3339
3420
 
3340
- return handlerData.event;
3341
- }
3421
+ // Otherwise this navigation entry is considered a duplicate and is thrown away
3422
+ return;
3423
+ }
3342
3424
 
3343
- function isEventWithTarget(event) {
3344
- return !!(event ).target;
3345
- }
3425
+ newEntries.push(entry);
3426
+ });
3346
3427
 
3347
- let _LAST_BREADCRUMB = null;
3428
+ // Re-combine and sort by startTime
3429
+ return [
3430
+ ...(newLcpEntry ? [newLcpEntry] : []),
3431
+ ...existingNavigationEntries,
3432
+ ...existingEntries,
3433
+ ...newEntries,
3434
+ ...newNavigationEntries,
3435
+ ].sort((a, b) => a.startTime - b.startTime);
3436
+ }
3348
3437
 
3349
3438
  /**
3350
- * An event handler to handle scope changes.
3439
+ * Sets up a PerformanceObserver to listen to all performance entry types.
3351
3440
  */
3352
- function handleScope(scope) {
3353
- const newBreadcrumb = scope.getLastBreadcrumb();
3354
-
3355
- // Listener can be called when breadcrumbs have not changed, so we store the
3356
- // reference to the last crumb and only return a crumb if it has changed
3357
- if (_LAST_BREADCRUMB === newBreadcrumb || !newBreadcrumb) {
3358
- return null;
3359
- }
3441
+ function setupPerformanceObserver(replay) {
3442
+ const performanceObserverHandler = (list) => {
3443
+ // For whatever reason the observer was returning duplicate navigation
3444
+ // entries (the other entry types were not duplicated).
3445
+ const newPerformanceEntries = dedupePerformanceEntries(
3446
+ replay.performanceEvents,
3447
+ list.getEntries() ,
3448
+ );
3449
+ replay.performanceEvents = newPerformanceEntries;
3450
+ };
3360
3451
 
3361
- _LAST_BREADCRUMB = newBreadcrumb;
3452
+ const performanceObserver = new PerformanceObserver(performanceObserverHandler);
3362
3453
 
3363
- if (
3364
- newBreadcrumb.category &&
3365
- (['fetch', 'xhr', 'sentry.event', 'sentry.transaction'].includes(newBreadcrumb.category) ||
3366
- newBreadcrumb.category.startsWith('ui.'))
3367
- ) {
3368
- return null;
3369
- }
3454
+ [
3455
+ 'element',
3456
+ 'event',
3457
+ 'first-input',
3458
+ 'largest-contentful-paint',
3459
+ 'layout-shift',
3460
+ 'longtask',
3461
+ 'navigation',
3462
+ 'paint',
3463
+ 'resource',
3464
+ ].forEach(type => {
3465
+ try {
3466
+ performanceObserver.observe({
3467
+ type,
3468
+ buffered: true,
3469
+ });
3470
+ } catch (e) {
3471
+ // This can throw if an entry type is not supported in the browser.
3472
+ // Ignore these errors.
3473
+ }
3474
+ });
3370
3475
 
3371
- return createBreadcrumb(newBreadcrumb);
3476
+ return performanceObserver;
3372
3477
  }
3373
3478
 
3479
+ const workerString = `/*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) */
3480
+ function t(t){let e=t.length;for(;--e>=0;)t[e]=0}const e=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),a=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),i=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),n=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),s=new Array(576);t(s);const r=new Array(60);t(r);const o=new Array(512);t(o);const l=new Array(256);t(l);const h=new Array(29);t(h);const d=new Array(30);function _(t,e,a,i,n){this.static_tree=t,this.extra_bits=e,this.extra_base=a,this.elems=i,this.max_length=n,this.has_stree=t&&t.length}let f,c,u;function w(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}t(d);const m=t=>t<256?o[t]:o[256+(t>>>7)],b=(t,e)=>{t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},g=(t,e,a)=>{t.bi_valid>16-a?(t.bi_buf|=e<<t.bi_valid&65535,b(t,t.bi_buf),t.bi_buf=e>>16-t.bi_valid,t.bi_valid+=a-16):(t.bi_buf|=e<<t.bi_valid&65535,t.bi_valid+=a)},p=(t,e,a)=>{g(t,a[2*e],a[2*e+1])},k=(t,e)=>{let a=0;do{a|=1&t,t>>>=1,a<<=1}while(--e>0);return a>>>1},v=(t,e,a)=>{const i=new Array(16);let n,s,r=0;for(n=1;n<=15;n++)r=r+a[n-1]<<1,i[n]=r;for(s=0;s<=e;s++){let e=t[2*s+1];0!==e&&(t[2*s]=k(i[e]++,e))}},y=t=>{let e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.sym_next=t.matches=0},x=t=>{t.bi_valid>8?b(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},z=(t,e,a,i)=>{const n=2*e,s=2*a;return t[n]<t[s]||t[n]===t[s]&&i[e]<=i[a]},A=(t,e,a)=>{const i=t.heap[a];let n=a<<1;for(;n<=t.heap_len&&(n<t.heap_len&&z(e,t.heap[n+1],t.heap[n],t.depth)&&n++,!z(e,i,t.heap[n],t.depth));)t.heap[a]=t.heap[n],a=n,n<<=1;t.heap[a]=i},E=(t,i,n)=>{let s,r,o,_,f=0;if(0!==t.sym_next)do{s=255&t.pending_buf[t.sym_buf+f++],s+=(255&t.pending_buf[t.sym_buf+f++])<<8,r=t.pending_buf[t.sym_buf+f++],0===s?p(t,r,i):(o=l[r],p(t,o+256+1,i),_=e[o],0!==_&&(r-=h[o],g(t,r,_)),s--,o=m(s),p(t,o,n),_=a[o],0!==_&&(s-=d[o],g(t,s,_)))}while(f<t.sym_next);p(t,256,i)},R=(t,e)=>{const a=e.dyn_tree,i=e.stat_desc.static_tree,n=e.stat_desc.has_stree,s=e.stat_desc.elems;let r,o,l,h=-1;for(t.heap_len=0,t.heap_max=573,r=0;r<s;r++)0!==a[2*r]?(t.heap[++t.heap_len]=h=r,t.depth[r]=0):a[2*r+1]=0;for(;t.heap_len<2;)l=t.heap[++t.heap_len]=h<2?++h:0,a[2*l]=1,t.depth[l]=0,t.opt_len--,n&&(t.static_len-=i[2*l+1]);for(e.max_code=h,r=t.heap_len>>1;r>=1;r--)A(t,a,r);l=s;do{r=t.heap[1],t.heap[1]=t.heap[t.heap_len--],A(t,a,1),o=t.heap[1],t.heap[--t.heap_max]=r,t.heap[--t.heap_max]=o,a[2*l]=a[2*r]+a[2*o],t.depth[l]=(t.depth[r]>=t.depth[o]?t.depth[r]:t.depth[o])+1,a[2*r+1]=a[2*o+1]=l,t.heap[1]=l++,A(t,a,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],((t,e)=>{const a=e.dyn_tree,i=e.max_code,n=e.stat_desc.static_tree,s=e.stat_desc.has_stree,r=e.stat_desc.extra_bits,o=e.stat_desc.extra_base,l=e.stat_desc.max_length;let h,d,_,f,c,u,w=0;for(f=0;f<=15;f++)t.bl_count[f]=0;for(a[2*t.heap[t.heap_max]+1]=0,h=t.heap_max+1;h<573;h++)d=t.heap[h],f=a[2*a[2*d+1]+1]+1,f>l&&(f=l,w++),a[2*d+1]=f,d>i||(t.bl_count[f]++,c=0,d>=o&&(c=r[d-o]),u=a[2*d],t.opt_len+=u*(f+c),s&&(t.static_len+=u*(n[2*d+1]+c)));if(0!==w){do{for(f=l-1;0===t.bl_count[f];)f--;t.bl_count[f]--,t.bl_count[f+1]+=2,t.bl_count[l]--,w-=2}while(w>0);for(f=l;0!==f;f--)for(d=t.bl_count[f];0!==d;)_=t.heap[--h],_>i||(a[2*_+1]!==f&&(t.opt_len+=(f-a[2*_+1])*a[2*_],a[2*_+1]=f),d--)}})(t,e),v(a,h,t.bl_count)},Z=(t,e,a)=>{let i,n,s=-1,r=e[1],o=0,l=7,h=4;for(0===r&&(l=138,h=3),e[2*(a+1)+1]=65535,i=0;i<=a;i++)n=r,r=e[2*(i+1)+1],++o<l&&n===r||(o<h?t.bl_tree[2*n]+=o:0!==n?(n!==s&&t.bl_tree[2*n]++,t.bl_tree[32]++):o<=10?t.bl_tree[34]++:t.bl_tree[36]++,o=0,s=n,0===r?(l=138,h=3):n===r?(l=6,h=3):(l=7,h=4))},S=(t,e,a)=>{let i,n,s=-1,r=e[1],o=0,l=7,h=4;for(0===r&&(l=138,h=3),i=0;i<=a;i++)if(n=r,r=e[2*(i+1)+1],!(++o<l&&n===r)){if(o<h)do{p(t,n,t.bl_tree)}while(0!=--o);else 0!==n?(n!==s&&(p(t,n,t.bl_tree),o--),p(t,16,t.bl_tree),g(t,o-3,2)):o<=10?(p(t,17,t.bl_tree),g(t,o-3,3)):(p(t,18,t.bl_tree),g(t,o-11,7));o=0,s=n,0===r?(l=138,h=3):n===r?(l=6,h=3):(l=7,h=4)}};let U=!1;const D=(t,e,a,i)=>{g(t,0+(i?1:0),3),x(t),b(t,a),b(t,~a),a&&t.pending_buf.set(t.window.subarray(e,e+a),t.pending),t.pending+=a};var O=(t,e,a,i)=>{let o,l,h=0;t.level>0?(2===t.strm.data_type&&(t.strm.data_type=(t=>{let e,a=4093624447;for(e=0;e<=31;e++,a>>>=1)if(1&a&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0})(t)),R(t,t.l_desc),R(t,t.d_desc),h=(t=>{let e;for(Z(t,t.dyn_ltree,t.l_desc.max_code),Z(t,t.dyn_dtree,t.d_desc.max_code),R(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*n[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e})(t),o=t.opt_len+3+7>>>3,l=t.static_len+3+7>>>3,l<=o&&(o=l)):o=l=a+5,a+4<=o&&-1!==e?D(t,e,a,i):4===t.strategy||l===o?(g(t,2+(i?1:0),3),E(t,s,r)):(g(t,4+(i?1:0),3),((t,e,a,i)=>{let s;for(g(t,e-257,5),g(t,a-1,5),g(t,i-4,4),s=0;s<i;s++)g(t,t.bl_tree[2*n[s]+1],3);S(t,t.dyn_ltree,e-1),S(t,t.dyn_dtree,a-1)})(t,t.l_desc.max_code+1,t.d_desc.max_code+1,h+1),E(t,t.dyn_ltree,t.dyn_dtree)),y(t),i&&x(t)},T={_tr_init:t=>{U||((()=>{let t,n,w,m,b;const g=new Array(16);for(w=0,m=0;m<28;m++)for(h[m]=w,t=0;t<1<<e[m];t++)l[w++]=m;for(l[w-1]=m,b=0,m=0;m<16;m++)for(d[m]=b,t=0;t<1<<a[m];t++)o[b++]=m;for(b>>=7;m<30;m++)for(d[m]=b<<7,t=0;t<1<<a[m]-7;t++)o[256+b++]=m;for(n=0;n<=15;n++)g[n]=0;for(t=0;t<=143;)s[2*t+1]=8,t++,g[8]++;for(;t<=255;)s[2*t+1]=9,t++,g[9]++;for(;t<=279;)s[2*t+1]=7,t++,g[7]++;for(;t<=287;)s[2*t+1]=8,t++,g[8]++;for(v(s,287,g),t=0;t<30;t++)r[2*t+1]=5,r[2*t]=k(t,5);f=new _(s,e,257,286,15),c=new _(r,a,0,30,15),u=new _(new Array(0),i,0,19,7)})(),U=!0),t.l_desc=new w(t.dyn_ltree,f),t.d_desc=new w(t.dyn_dtree,c),t.bl_desc=new w(t.bl_tree,u),t.bi_buf=0,t.bi_valid=0,y(t)},_tr_stored_block:D,_tr_flush_block:O,_tr_tally:(t,e,a)=>(t.pending_buf[t.sym_buf+t.sym_next++]=e,t.pending_buf[t.sym_buf+t.sym_next++]=e>>8,t.pending_buf[t.sym_buf+t.sym_next++]=a,0===e?t.dyn_ltree[2*a]++:(t.matches++,e--,t.dyn_ltree[2*(l[a]+256+1)]++,t.dyn_dtree[2*m(e)]++),t.sym_next===t.sym_end),_tr_align:t=>{g(t,2,3),p(t,256,s),(t=>{16===t.bi_valid?(b(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)})(t)}};var N=(t,e,a,i)=>{let n=65535&t|0,s=t>>>16&65535|0,r=0;for(;0!==a;){r=a>2e3?2e3:a,a-=r;do{n=n+e[i++]|0,s=s+n|0}while(--r);n%=65521,s%=65521}return n|s<<16|0};const F=new Uint32Array((()=>{let t,e=[];for(var a=0;a<256;a++){t=a;for(var i=0;i<8;i++)t=1&t?3988292384^t>>>1:t>>>1;e[a]=t}return e})());var L=(t,e,a,i)=>{const n=F,s=i+a;t^=-1;for(let a=i;a<s;a++)t=t>>>8^n[255&(t^e[a])];return-1^t},I={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},B={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:C,_tr_stored_block:H,_tr_flush_block:M,_tr_tally:j,_tr_align:K}=T,{Z_NO_FLUSH:P,Z_PARTIAL_FLUSH:Y,Z_FULL_FLUSH:G,Z_FINISH:X,Z_BLOCK:J,Z_OK:W,Z_STREAM_END:q,Z_STREAM_ERROR:Q,Z_DATA_ERROR:V,Z_BUF_ERROR:$,Z_DEFAULT_COMPRESSION:tt,Z_FILTERED:et,Z_HUFFMAN_ONLY:at,Z_RLE:it,Z_FIXED:nt,Z_DEFAULT_STRATEGY:st,Z_UNKNOWN:rt,Z_DEFLATED:ot}=B,lt=(t,e)=>(t.msg=I[e],e),ht=t=>2*t-(t>4?9:0),dt=t=>{let e=t.length;for(;--e>=0;)t[e]=0},_t=t=>{let e,a,i,n=t.w_size;e=t.hash_size,i=e;do{a=t.head[--i],t.head[i]=a>=n?a-n:0}while(--e);e=n,i=e;do{a=t.prev[--i],t.prev[i]=a>=n?a-n:0}while(--e)};let ft=(t,e,a)=>(e<<t.hash_shift^a)&t.hash_mask;const ct=t=>{const e=t.state;let a=e.pending;a>t.avail_out&&(a=t.avail_out),0!==a&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+a),t.next_out),t.next_out+=a,e.pending_out+=a,t.total_out+=a,t.avail_out-=a,e.pending-=a,0===e.pending&&(e.pending_out=0))},ut=(t,e)=>{M(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,ct(t.strm)},wt=(t,e)=>{t.pending_buf[t.pending++]=e},mt=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},bt=(t,e,a,i)=>{let n=t.avail_in;return n>i&&(n=i),0===n?0:(t.avail_in-=n,e.set(t.input.subarray(t.next_in,t.next_in+n),a),1===t.state.wrap?t.adler=N(t.adler,e,n,a):2===t.state.wrap&&(t.adler=L(t.adler,e,n,a)),t.next_in+=n,t.total_in+=n,n)},gt=(t,e)=>{let a,i,n=t.max_chain_length,s=t.strstart,r=t.prev_length,o=t.nice_match;const l=t.strstart>t.w_size-262?t.strstart-(t.w_size-262):0,h=t.window,d=t.w_mask,_=t.prev,f=t.strstart+258;let c=h[s+r-1],u=h[s+r];t.prev_length>=t.good_match&&(n>>=2),o>t.lookahead&&(o=t.lookahead);do{if(a=e,h[a+r]===u&&h[a+r-1]===c&&h[a]===h[s]&&h[++a]===h[s+1]){s+=2,a++;do{}while(h[++s]===h[++a]&&h[++s]===h[++a]&&h[++s]===h[++a]&&h[++s]===h[++a]&&h[++s]===h[++a]&&h[++s]===h[++a]&&h[++s]===h[++a]&&h[++s]===h[++a]&&s<f);if(i=258-(f-s),s=f-258,i>r){if(t.match_start=e,r=i,i>=o)break;c=h[s+r-1],u=h[s+r]}}}while((e=_[e&d])>l&&0!=--n);return r<=t.lookahead?r:t.lookahead},pt=t=>{const e=t.w_size;let a,i,n;do{if(i=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-262)&&(t.window.set(t.window.subarray(e,e+e-i),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,t.insert>t.strstart&&(t.insert=t.strstart),_t(t),i+=e),0===t.strm.avail_in)break;if(a=bt(t.strm,t.window,t.strstart+t.lookahead,i),t.lookahead+=a,t.lookahead+t.insert>=3)for(n=t.strstart-t.insert,t.ins_h=t.window[n],t.ins_h=ft(t,t.ins_h,t.window[n+1]);t.insert&&(t.ins_h=ft(t,t.ins_h,t.window[n+3-1]),t.prev[n&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=n,n++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead<262&&0!==t.strm.avail_in)},kt=(t,e)=>{let a,i,n,s=t.pending_buf_size-5>t.w_size?t.w_size:t.pending_buf_size-5,r=0,o=t.strm.avail_in;do{if(a=65535,n=t.bi_valid+42>>3,t.strm.avail_out<n)break;if(n=t.strm.avail_out-n,i=t.strstart-t.block_start,a>i+t.strm.avail_in&&(a=i+t.strm.avail_in),a>n&&(a=n),a<s&&(0===a&&e!==X||e===P||a!==i+t.strm.avail_in))break;r=e===X&&a===i+t.strm.avail_in?1:0,H(t,0,0,r),t.pending_buf[t.pending-4]=a,t.pending_buf[t.pending-3]=a>>8,t.pending_buf[t.pending-2]=~a,t.pending_buf[t.pending-1]=~a>>8,ct(t.strm),i&&(i>a&&(i=a),t.strm.output.set(t.window.subarray(t.block_start,t.block_start+i),t.strm.next_out),t.strm.next_out+=i,t.strm.avail_out-=i,t.strm.total_out+=i,t.block_start+=i,a-=i),a&&(bt(t.strm,t.strm.output,t.strm.next_out,a),t.strm.next_out+=a,t.strm.avail_out-=a,t.strm.total_out+=a)}while(0===r);return o-=t.strm.avail_in,o&&(o>=t.w_size?(t.matches=2,t.window.set(t.strm.input.subarray(t.strm.next_in-t.w_size,t.strm.next_in),0),t.strstart=t.w_size,t.insert=t.strstart):(t.window_size-t.strstart<=o&&(t.strstart-=t.w_size,t.window.set(t.window.subarray(t.w_size,t.w_size+t.strstart),0),t.matches<2&&t.matches++,t.insert>t.strstart&&(t.insert=t.strstart)),t.window.set(t.strm.input.subarray(t.strm.next_in-o,t.strm.next_in),t.strstart),t.strstart+=o,t.insert+=o>t.w_size-t.insert?t.w_size-t.insert:o),t.block_start=t.strstart),t.high_water<t.strstart&&(t.high_water=t.strstart),r?4:e!==P&&e!==X&&0===t.strm.avail_in&&t.strstart===t.block_start?2:(n=t.window_size-t.strstart,t.strm.avail_in>n&&t.block_start>=t.w_size&&(t.block_start-=t.w_size,t.strstart-=t.w_size,t.window.set(t.window.subarray(t.w_size,t.w_size+t.strstart),0),t.matches<2&&t.matches++,n+=t.w_size,t.insert>t.strstart&&(t.insert=t.strstart)),n>t.strm.avail_in&&(n=t.strm.avail_in),n&&(bt(t.strm,t.window,t.strstart,n),t.strstart+=n,t.insert+=n>t.w_size-t.insert?t.w_size-t.insert:n),t.high_water<t.strstart&&(t.high_water=t.strstart),n=t.bi_valid+42>>3,n=t.pending_buf_size-n>65535?65535:t.pending_buf_size-n,s=n>t.w_size?t.w_size:n,i=t.strstart-t.block_start,(i>=s||(i||e===X)&&e!==P&&0===t.strm.avail_in&&i<=n)&&(a=i>n?n:i,r=e===X&&0===t.strm.avail_in&&a===i?1:0,H(t,t.block_start,a,r),t.block_start+=a,ct(t.strm)),r?3:1)},vt=(t,e)=>{let a,i;for(;;){if(t.lookahead<262){if(pt(t),t.lookahead<262&&e===P)return 1;if(0===t.lookahead)break}if(a=0,t.lookahead>=3&&(t.ins_h=ft(t,t.ins_h,t.window[t.strstart+3-1]),a=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==a&&t.strstart-a<=t.w_size-262&&(t.match_length=gt(t,a)),t.match_length>=3)if(i=j(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=ft(t,t.ins_h,t.window[t.strstart+3-1]),a=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=ft(t,t.ins_h,t.window[t.strstart+1]);else i=j(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(i&&(ut(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===X?(ut(t,!0),0===t.strm.avail_out?3:4):t.sym_next&&(ut(t,!1),0===t.strm.avail_out)?1:2},yt=(t,e)=>{let a,i,n;for(;;){if(t.lookahead<262){if(pt(t),t.lookahead<262&&e===P)return 1;if(0===t.lookahead)break}if(a=0,t.lookahead>=3&&(t.ins_h=ft(t,t.ins_h,t.window[t.strstart+3-1]),a=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==a&&t.prev_length<t.max_lazy_match&&t.strstart-a<=t.w_size-262&&(t.match_length=gt(t,a),t.match_length<=5&&(t.strategy===et||3===t.match_length&&t.strstart-t.match_start>4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){n=t.strstart+t.lookahead-3,i=j(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=n&&(t.ins_h=ft(t,t.ins_h,t.window[t.strstart+3-1]),a=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,i&&(ut(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if(i=j(t,0,t.window[t.strstart-1]),i&&ut(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(i=j(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===X?(ut(t,!0),0===t.strm.avail_out?3:4):t.sym_next&&(ut(t,!1),0===t.strm.avail_out)?1:2};function xt(t,e,a,i,n){this.good_length=t,this.max_lazy=e,this.nice_length=a,this.max_chain=i,this.func=n}const zt=[new xt(0,0,0,0,kt),new xt(4,4,8,4,vt),new xt(4,5,16,8,vt),new xt(4,6,32,32,vt),new xt(4,4,16,16,yt),new xt(8,16,32,32,yt),new xt(8,16,128,128,yt),new xt(8,32,128,256,yt),new xt(32,128,258,1024,yt),new xt(32,258,258,4096,yt)];function At(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=ot,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),dt(this.dyn_ltree),dt(this.dyn_dtree),dt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),dt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),dt(this.depth),this.sym_buf=0,this.lit_bufsize=0,this.sym_next=0,this.sym_end=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const Et=t=>{if(!t)return 1;const e=t.state;return!e||e.strm!==t||42!==e.status&&57!==e.status&&69!==e.status&&73!==e.status&&91!==e.status&&103!==e.status&&113!==e.status&&666!==e.status?1:0},Rt=t=>{if(Et(t))return lt(t,Q);t.total_in=t.total_out=0,t.data_type=rt;const e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=2===e.wrap?57:e.wrap?42:113,t.adler=2===e.wrap?0:1,e.last_flush=-2,C(e),W},Zt=t=>{const e=Rt(t);var a;return e===W&&((a=t.state).window_size=2*a.w_size,dt(a.head),a.max_lazy_match=zt[a.level].max_lazy,a.good_match=zt[a.level].good_length,a.nice_match=zt[a.level].nice_length,a.max_chain_length=zt[a.level].max_chain,a.strstart=0,a.block_start=0,a.lookahead=0,a.insert=0,a.match_length=a.prev_length=2,a.match_available=0,a.ins_h=0),e},St=(t,e,a,i,n,s)=>{if(!t)return Q;let r=1;if(e===tt&&(e=6),i<0?(r=0,i=-i):i>15&&(r=2,i-=16),n<1||n>9||a!==ot||i<8||i>15||e<0||e>9||s<0||s>nt||8===i&&1!==r)return lt(t,Q);8===i&&(i=9);const o=new At;return t.state=o,o.strm=t,o.status=42,o.wrap=r,o.gzhead=null,o.w_bits=i,o.w_size=1<<o.w_bits,o.w_mask=o.w_size-1,o.hash_bits=n+7,o.hash_size=1<<o.hash_bits,o.hash_mask=o.hash_size-1,o.hash_shift=~~((o.hash_bits+3-1)/3),o.window=new Uint8Array(2*o.w_size),o.head=new Uint16Array(o.hash_size),o.prev=new Uint16Array(o.w_size),o.lit_bufsize=1<<n+6,o.pending_buf_size=4*o.lit_bufsize,o.pending_buf=new Uint8Array(o.pending_buf_size),o.sym_buf=o.lit_bufsize,o.sym_end=3*(o.lit_bufsize-1),o.level=e,o.strategy=s,o.method=a,Zt(t)};var Ut={deflateInit:(t,e)=>St(t,e,ot,15,8,st),deflateInit2:St,deflateReset:Zt,deflateResetKeep:Rt,deflateSetHeader:(t,e)=>Et(t)||2!==t.state.wrap?Q:(t.state.gzhead=e,W),deflate:(t,e)=>{if(Et(t)||e>J||e<0)return t?lt(t,Q):Q;const a=t.state;if(!t.output||0!==t.avail_in&&!t.input||666===a.status&&e!==X)return lt(t,0===t.avail_out?$:Q);const i=a.last_flush;if(a.last_flush=e,0!==a.pending){if(ct(t),0===t.avail_out)return a.last_flush=-1,W}else if(0===t.avail_in&&ht(e)<=ht(i)&&e!==X)return lt(t,$);if(666===a.status&&0!==t.avail_in)return lt(t,$);if(42===a.status&&0===a.wrap&&(a.status=113),42===a.status){let e=ot+(a.w_bits-8<<4)<<8,i=-1;if(i=a.strategy>=at||a.level<2?0:a.level<6?1:6===a.level?2:3,e|=i<<6,0!==a.strstart&&(e|=32),e+=31-e%31,mt(a,e),0!==a.strstart&&(mt(a,t.adler>>>16),mt(a,65535&t.adler)),t.adler=1,a.status=113,ct(t),0!==a.pending)return a.last_flush=-1,W}if(57===a.status)if(t.adler=0,wt(a,31),wt(a,139),wt(a,8),a.gzhead)wt(a,(a.gzhead.text?1:0)+(a.gzhead.hcrc?2:0)+(a.gzhead.extra?4:0)+(a.gzhead.name?8:0)+(a.gzhead.comment?16:0)),wt(a,255&a.gzhead.time),wt(a,a.gzhead.time>>8&255),wt(a,a.gzhead.time>>16&255),wt(a,a.gzhead.time>>24&255),wt(a,9===a.level?2:a.strategy>=at||a.level<2?4:0),wt(a,255&a.gzhead.os),a.gzhead.extra&&a.gzhead.extra.length&&(wt(a,255&a.gzhead.extra.length),wt(a,a.gzhead.extra.length>>8&255)),a.gzhead.hcrc&&(t.adler=L(t.adler,a.pending_buf,a.pending,0)),a.gzindex=0,a.status=69;else if(wt(a,0),wt(a,0),wt(a,0),wt(a,0),wt(a,0),wt(a,9===a.level?2:a.strategy>=at||a.level<2?4:0),wt(a,3),a.status=113,ct(t),0!==a.pending)return a.last_flush=-1,W;if(69===a.status){if(a.gzhead.extra){let e=a.pending,i=(65535&a.gzhead.extra.length)-a.gzindex;for(;a.pending+i>a.pending_buf_size;){let n=a.pending_buf_size-a.pending;if(a.pending_buf.set(a.gzhead.extra.subarray(a.gzindex,a.gzindex+n),a.pending),a.pending=a.pending_buf_size,a.gzhead.hcrc&&a.pending>e&&(t.adler=L(t.adler,a.pending_buf,a.pending-e,e)),a.gzindex+=n,ct(t),0!==a.pending)return a.last_flush=-1,W;e=0,i-=n}let n=new Uint8Array(a.gzhead.extra);a.pending_buf.set(n.subarray(a.gzindex,a.gzindex+i),a.pending),a.pending+=i,a.gzhead.hcrc&&a.pending>e&&(t.adler=L(t.adler,a.pending_buf,a.pending-e,e)),a.gzindex=0}a.status=73}if(73===a.status){if(a.gzhead.name){let e,i=a.pending;do{if(a.pending===a.pending_buf_size){if(a.gzhead.hcrc&&a.pending>i&&(t.adler=L(t.adler,a.pending_buf,a.pending-i,i)),ct(t),0!==a.pending)return a.last_flush=-1,W;i=0}e=a.gzindex<a.gzhead.name.length?255&a.gzhead.name.charCodeAt(a.gzindex++):0,wt(a,e)}while(0!==e);a.gzhead.hcrc&&a.pending>i&&(t.adler=L(t.adler,a.pending_buf,a.pending-i,i)),a.gzindex=0}a.status=91}if(91===a.status){if(a.gzhead.comment){let e,i=a.pending;do{if(a.pending===a.pending_buf_size){if(a.gzhead.hcrc&&a.pending>i&&(t.adler=L(t.adler,a.pending_buf,a.pending-i,i)),ct(t),0!==a.pending)return a.last_flush=-1,W;i=0}e=a.gzindex<a.gzhead.comment.length?255&a.gzhead.comment.charCodeAt(a.gzindex++):0,wt(a,e)}while(0!==e);a.gzhead.hcrc&&a.pending>i&&(t.adler=L(t.adler,a.pending_buf,a.pending-i,i))}a.status=103}if(103===a.status){if(a.gzhead.hcrc){if(a.pending+2>a.pending_buf_size&&(ct(t),0!==a.pending))return a.last_flush=-1,W;wt(a,255&t.adler),wt(a,t.adler>>8&255),t.adler=0}if(a.status=113,ct(t),0!==a.pending)return a.last_flush=-1,W}if(0!==t.avail_in||0!==a.lookahead||e!==P&&666!==a.status){let i=0===a.level?kt(a,e):a.strategy===at?((t,e)=>{let a;for(;;){if(0===t.lookahead&&(pt(t),0===t.lookahead)){if(e===P)return 1;break}if(t.match_length=0,a=j(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,a&&(ut(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===X?(ut(t,!0),0===t.strm.avail_out?3:4):t.sym_next&&(ut(t,!1),0===t.strm.avail_out)?1:2})(a,e):a.strategy===it?((t,e)=>{let a,i,n,s;const r=t.window;for(;;){if(t.lookahead<=258){if(pt(t),t.lookahead<=258&&e===P)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&(n=t.strstart-1,i=r[n],i===r[++n]&&i===r[++n]&&i===r[++n])){s=t.strstart+258;do{}while(i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&n<s);t.match_length=258-(s-n),t.match_length>t.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(a=j(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(a=j(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),a&&(ut(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===X?(ut(t,!0),0===t.strm.avail_out?3:4):t.sym_next&&(ut(t,!1),0===t.strm.avail_out)?1:2})(a,e):zt[a.level].func(a,e);if(3!==i&&4!==i||(a.status=666),1===i||3===i)return 0===t.avail_out&&(a.last_flush=-1),W;if(2===i&&(e===Y?K(a):e!==J&&(H(a,0,0,!1),e===G&&(dt(a.head),0===a.lookahead&&(a.strstart=0,a.block_start=0,a.insert=0))),ct(t),0===t.avail_out))return a.last_flush=-1,W}return e!==X?W:a.wrap<=0?q:(2===a.wrap?(wt(a,255&t.adler),wt(a,t.adler>>8&255),wt(a,t.adler>>16&255),wt(a,t.adler>>24&255),wt(a,255&t.total_in),wt(a,t.total_in>>8&255),wt(a,t.total_in>>16&255),wt(a,t.total_in>>24&255)):(mt(a,t.adler>>>16),mt(a,65535&t.adler)),ct(t),a.wrap>0&&(a.wrap=-a.wrap),0!==a.pending?W:q)},deflateEnd:t=>{if(Et(t))return Q;const e=t.state.status;return t.state=null,113===e?lt(t,V):W},deflateSetDictionary:(t,e)=>{let a=e.length;if(Et(t))return Q;const i=t.state,n=i.wrap;if(2===n||1===n&&42!==i.status||i.lookahead)return Q;if(1===n&&(t.adler=N(t.adler,e,a,0)),i.wrap=0,a>=i.w_size){0===n&&(dt(i.head),i.strstart=0,i.block_start=0,i.insert=0);let t=new Uint8Array(i.w_size);t.set(e.subarray(a-i.w_size,a),0),e=t,a=i.w_size}const s=t.avail_in,r=t.next_in,o=t.input;for(t.avail_in=a,t.next_in=0,t.input=e,pt(i);i.lookahead>=3;){let t=i.strstart,e=i.lookahead-2;do{i.ins_h=ft(i,i.ins_h,i.window[t+3-1]),i.prev[t&i.w_mask]=i.head[i.ins_h],i.head[i.ins_h]=t,t++}while(--e);i.strstart=t,i.lookahead=2,pt(i)}return i.strstart+=i.lookahead,i.block_start=i.strstart,i.insert=i.lookahead,i.lookahead=0,i.match_length=i.prev_length=2,i.match_available=0,t.next_in=r,t.input=o,t.avail_in=s,i.wrap=n,W},deflateInfo:"pako deflate (from Nodeca project)"};const Dt=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var Ot=function(t){const e=Array.prototype.slice.call(arguments,1);for(;e.length;){const a=e.shift();if(a){if("object"!=typeof a)throw new TypeError(a+"must be non-object");for(const e in a)Dt(a,e)&&(t[e]=a[e])}}return t},Tt=t=>{let e=0;for(let a=0,i=t.length;a<i;a++)e+=t[a].length;const a=new Uint8Array(e);for(let e=0,i=0,n=t.length;e<n;e++){let n=t[e];a.set(n,i),i+=n.length}return a};let Nt=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(t){Nt=!1}const Ft=new Uint8Array(256);for(let t=0;t<256;t++)Ft[t]=t>=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;Ft[254]=Ft[254]=1;var Lt=t=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);let e,a,i,n,s,r=t.length,o=0;for(n=0;n<r;n++)a=t.charCodeAt(n),55296==(64512&a)&&n+1<r&&(i=t.charCodeAt(n+1),56320==(64512&i)&&(a=65536+(a-55296<<10)+(i-56320),n++)),o+=a<128?1:a<2048?2:a<65536?3:4;for(e=new Uint8Array(o),s=0,n=0;s<o;n++)a=t.charCodeAt(n),55296==(64512&a)&&n+1<r&&(i=t.charCodeAt(n+1),56320==(64512&i)&&(a=65536+(a-55296<<10)+(i-56320),n++)),a<128?e[s++]=a:a<2048?(e[s++]=192|a>>>6,e[s++]=128|63&a):a<65536?(e[s++]=224|a>>>12,e[s++]=128|a>>>6&63,e[s++]=128|63&a):(e[s++]=240|a>>>18,e[s++]=128|a>>>12&63,e[s++]=128|a>>>6&63,e[s++]=128|63&a);return e},It=(t,e)=>{const a=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));let i,n;const s=new Array(2*a);for(n=0,i=0;i<a;){let e=t[i++];if(e<128){s[n++]=e;continue}let r=Ft[e];if(r>4)s[n++]=65533,i+=r-1;else{for(e&=2===r?31:3===r?15:7;r>1&&i<a;)e=e<<6|63&t[i++],r--;r>1?s[n++]=65533:e<65536?s[n++]=e:(e-=65536,s[n++]=55296|e>>10&1023,s[n++]=56320|1023&e)}}return((t,e)=>{if(e<65534&&t.subarray&&Nt)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let a="";for(let i=0;i<e;i++)a+=String.fromCharCode(t[i]);return a})(s,n)},Bt=(t,e)=>{(e=e||t.length)>t.length&&(e=t.length);let a=e-1;for(;a>=0&&128==(192&t[a]);)a--;return a<0||0===a?e:a+Ft[t[a]]>e?a:e};var Ct=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};const Ht=Object.prototype.toString,{Z_NO_FLUSH:Mt,Z_SYNC_FLUSH:jt,Z_FULL_FLUSH:Kt,Z_FINISH:Pt,Z_OK:Yt,Z_STREAM_END:Gt,Z_DEFAULT_COMPRESSION:Xt,Z_DEFAULT_STRATEGY:Jt,Z_DEFLATED:Wt}=B;function qt(t){this.options=Ot({level:Xt,method:Wt,chunkSize:16384,windowBits:15,memLevel:8,strategy:Jt},t||{});let e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Ct,this.strm.avail_out=0;let a=Ut.deflateInit2(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(a!==Yt)throw new Error(I[a]);if(e.header&&Ut.deflateSetHeader(this.strm,e.header),e.dictionary){let t;if(t="string"==typeof e.dictionary?Lt(e.dictionary):"[object ArrayBuffer]"===Ht.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,a=Ut.deflateSetDictionary(this.strm,t),a!==Yt)throw new Error(I[a]);this._dict_set=!0}}function Qt(t,e){const a=new qt(e);if(a.push(t,!0),a.err)throw a.msg||I[a.err];return a.result}qt.prototype.push=function(t,e){const a=this.strm,i=this.options.chunkSize;let n,s;if(this.ended)return!1;for(s=e===~~e?e:!0===e?Pt:Mt,"string"==typeof t?a.input=Lt(t):"[object ArrayBuffer]"===Ht.call(t)?a.input=new Uint8Array(t):a.input=t,a.next_in=0,a.avail_in=a.input.length;;)if(0===a.avail_out&&(a.output=new Uint8Array(i),a.next_out=0,a.avail_out=i),(s===jt||s===Kt)&&a.avail_out<=6)this.onData(a.output.subarray(0,a.next_out)),a.avail_out=0;else{if(n=Ut.deflate(a,s),n===Gt)return a.next_out>0&&this.onData(a.output.subarray(0,a.next_out)),n=Ut.deflateEnd(this.strm),this.onEnd(n),this.ended=!0,n===Yt;if(0!==a.avail_out){if(s>0&&a.next_out>0)this.onData(a.output.subarray(0,a.next_out)),a.avail_out=0;else if(0===a.avail_in)break}else this.onData(a.output)}return!0},qt.prototype.onData=function(t){this.chunks.push(t)},qt.prototype.onEnd=function(t){t===Yt&&(this.result=Tt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var Vt={Deflate:qt,deflate:Qt,deflateRaw:function(t,e){return(e=e||{}).raw=!0,Qt(t,e)},gzip:function(t,e){return(e=e||{}).gzip=!0,Qt(t,e)},constants:B};var $t=function(t,e){let a,i,n,s,r,o,l,h,d,_,f,c,u,w,m,b,g,p,k,v,y,x,z,A;const E=t.state;a=t.next_in,z=t.input,i=a+(t.avail_in-5),n=t.next_out,A=t.output,s=n-(e-t.avail_out),r=n+(t.avail_out-257),o=E.dmax,l=E.wsize,h=E.whave,d=E.wnext,_=E.window,f=E.hold,c=E.bits,u=E.lencode,w=E.distcode,m=(1<<E.lenbits)-1,b=(1<<E.distbits)-1;t:do{c<15&&(f+=z[a++]<<c,c+=8,f+=z[a++]<<c,c+=8),g=u[f&m];e:for(;;){if(p=g>>>24,f>>>=p,c-=p,p=g>>>16&255,0===p)A[n++]=65535&g;else{if(!(16&p)){if(0==(64&p)){g=u[(65535&g)+(f&(1<<p)-1)];continue e}if(32&p){E.mode=16191;break t}t.msg="invalid literal/length code",E.mode=16209;break t}k=65535&g,p&=15,p&&(c<p&&(f+=z[a++]<<c,c+=8),k+=f&(1<<p)-1,f>>>=p,c-=p),c<15&&(f+=z[a++]<<c,c+=8,f+=z[a++]<<c,c+=8),g=w[f&b];a:for(;;){if(p=g>>>24,f>>>=p,c-=p,p=g>>>16&255,!(16&p)){if(0==(64&p)){g=w[(65535&g)+(f&(1<<p)-1)];continue a}t.msg="invalid distance code",E.mode=16209;break t}if(v=65535&g,p&=15,c<p&&(f+=z[a++]<<c,c+=8,c<p&&(f+=z[a++]<<c,c+=8)),v+=f&(1<<p)-1,v>o){t.msg="invalid distance too far back",E.mode=16209;break t}if(f>>>=p,c-=p,p=n-s,v>p){if(p=v-p,p>h&&E.sane){t.msg="invalid distance too far back",E.mode=16209;break t}if(y=0,x=_,0===d){if(y+=l-p,p<k){k-=p;do{A[n++]=_[y++]}while(--p);y=n-v,x=A}}else if(d<p){if(y+=l+d-p,p-=d,p<k){k-=p;do{A[n++]=_[y++]}while(--p);if(y=0,d<k){p=d,k-=p;do{A[n++]=_[y++]}while(--p);y=n-v,x=A}}}else if(y+=d-p,p<k){k-=p;do{A[n++]=_[y++]}while(--p);y=n-v,x=A}for(;k>2;)A[n++]=x[y++],A[n++]=x[y++],A[n++]=x[y++],k-=3;k&&(A[n++]=x[y++],k>1&&(A[n++]=x[y++]))}else{y=n-v;do{A[n++]=A[y++],A[n++]=A[y++],A[n++]=A[y++],k-=3}while(k>2);k&&(A[n++]=A[y++],k>1&&(A[n++]=A[y++]))}break}}break}}while(a<i&&n<r);k=c>>3,a-=k,c-=k<<3,f&=(1<<c)-1,t.next_in=a,t.next_out=n,t.avail_in=a<i?i-a+5:5-(a-i),t.avail_out=n<r?r-n+257:257-(n-r),E.hold=f,E.bits=c};const te=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),ee=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),ae=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),ie=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]);var ne=(t,e,a,i,n,s,r,o)=>{const l=o.bits;let h,d,_,f,c,u,w=0,m=0,b=0,g=0,p=0,k=0,v=0,y=0,x=0,z=0,A=null;const E=new Uint16Array(16),R=new Uint16Array(16);let Z,S,U,D=null;for(w=0;w<=15;w++)E[w]=0;for(m=0;m<i;m++)E[e[a+m]]++;for(p=l,g=15;g>=1&&0===E[g];g--);if(p>g&&(p=g),0===g)return n[s++]=20971520,n[s++]=20971520,o.bits=1,0;for(b=1;b<g&&0===E[b];b++);for(p<b&&(p=b),y=1,w=1;w<=15;w++)if(y<<=1,y-=E[w],y<0)return-1;if(y>0&&(0===t||1!==g))return-1;for(R[1]=0,w=1;w<15;w++)R[w+1]=R[w]+E[w];for(m=0;m<i;m++)0!==e[a+m]&&(r[R[e[a+m]]++]=m);if(0===t?(A=D=r,u=20):1===t?(A=te,D=ee,u=257):(A=ae,D=ie,u=0),z=0,m=0,w=b,c=s,k=p,v=0,_=-1,x=1<<p,f=x-1,1===t&&x>852||2===t&&x>592)return 1;for(;;){Z=w-v,r[m]+1<u?(S=0,U=r[m]):r[m]>=u?(S=D[r[m]-u],U=A[r[m]-u]):(S=96,U=0),h=1<<w-v,d=1<<k,b=d;do{d-=h,n[c+(z>>v)+d]=Z<<24|S<<16|U|0}while(0!==d);for(h=1<<w-1;z&h;)h>>=1;if(0!==h?(z&=h-1,z+=h):z=0,m++,0==--E[w]){if(w===g)break;w=e[a+r[m]]}if(w>p&&(z&f)!==_){for(0===v&&(v=p),c+=b,k=w-v,y=1<<k;k+v<g&&(y-=E[k+v],!(y<=0));)k++,y<<=1;if(x+=1<<k,1===t&&x>852||2===t&&x>592)return 1;_=z&f,n[_]=p<<24|k<<16|c-s|0}}return 0!==z&&(n[c+z]=w-v<<24|64<<16|0),o.bits=p,0};const{Z_FINISH:se,Z_BLOCK:re,Z_TREES:oe,Z_OK:le,Z_STREAM_END:he,Z_NEED_DICT:de,Z_STREAM_ERROR:_e,Z_DATA_ERROR:fe,Z_MEM_ERROR:ce,Z_BUF_ERROR:ue,Z_DEFLATED:we}=B,me=16209,be=t=>(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24);function ge(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const pe=t=>{if(!t)return 1;const e=t.state;return!e||e.strm!==t||e.mode<16180||e.mode>16211?1:0},ke=t=>{if(pe(t))return _e;const e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=16180,e.last=0,e.havedict=0,e.flags=-1,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,le},ve=t=>{if(pe(t))return _e;const e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,ke(t)},ye=(t,e)=>{let a;if(pe(t))return _e;const i=t.state;return e<0?(a=0,e=-e):(a=5+(e>>4),e<48&&(e&=15)),e&&(e<8||e>15)?_e:(null!==i.window&&i.wbits!==e&&(i.window=null),i.wrap=a,i.wbits=e,ve(t))},xe=(t,e)=>{if(!t)return _e;const a=new ge;t.state=a,a.strm=t,a.window=null,a.mode=16180;const i=ye(t,e);return i!==le&&(t.state=null),i};let ze,Ae,Ee=!0;const Re=t=>{if(Ee){ze=new Int32Array(512),Ae=new Int32Array(32);let e=0;for(;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(ne(1,t.lens,0,288,ze,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;ne(2,t.lens,0,32,Ae,0,t.work,{bits:5}),Ee=!1}t.lencode=ze,t.lenbits=9,t.distcode=Ae,t.distbits=5},Ze=(t,e,a,i)=>{let n;const s=t.state;return null===s.window&&(s.wsize=1<<s.wbits,s.wnext=0,s.whave=0,s.window=new Uint8Array(s.wsize)),i>=s.wsize?(s.window.set(e.subarray(a-s.wsize,a),0),s.wnext=0,s.whave=s.wsize):(n=s.wsize-s.wnext,n>i&&(n=i),s.window.set(e.subarray(a-i,a-i+n),s.wnext),(i-=n)?(s.window.set(e.subarray(a-i,a),0),s.wnext=i,s.whave=s.wsize):(s.wnext+=n,s.wnext===s.wsize&&(s.wnext=0),s.whave<s.wsize&&(s.whave+=n))),0};var Se={inflateReset:ve,inflateReset2:ye,inflateResetKeep:ke,inflateInit:t=>xe(t,15),inflateInit2:xe,inflate:(t,e)=>{let a,i,n,s,r,o,l,h,d,_,f,c,u,w,m,b,g,p,k,v,y,x,z=0;const A=new Uint8Array(4);let E,R;const Z=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(pe(t)||!t.output||!t.input&&0!==t.avail_in)return _e;a=t.state,16191===a.mode&&(a.mode=16192),r=t.next_out,n=t.output,l=t.avail_out,s=t.next_in,i=t.input,o=t.avail_in,h=a.hold,d=a.bits,_=o,f=l,x=le;t:for(;;)switch(a.mode){case 16180:if(0===a.wrap){a.mode=16192;break}for(;d<16;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}if(2&a.wrap&&35615===h){0===a.wbits&&(a.wbits=15),a.check=0,A[0]=255&h,A[1]=h>>>8&255,a.check=L(a.check,A,2,0),h=0,d=0,a.mode=16181;break}if(a.head&&(a.head.done=!1),!(1&a.wrap)||(((255&h)<<8)+(h>>8))%31){t.msg="incorrect header check",a.mode=me;break}if((15&h)!==we){t.msg="unknown compression method",a.mode=me;break}if(h>>>=4,d-=4,y=8+(15&h),0===a.wbits&&(a.wbits=y),y>15||y>a.wbits){t.msg="invalid window size",a.mode=me;break}a.dmax=1<<a.wbits,a.flags=0,t.adler=a.check=1,a.mode=512&h?16189:16191,h=0,d=0;break;case 16181:for(;d<16;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}if(a.flags=h,(255&a.flags)!==we){t.msg="unknown compression method",a.mode=me;break}if(57344&a.flags){t.msg="unknown header flags set",a.mode=me;break}a.head&&(a.head.text=h>>8&1),512&a.flags&&4&a.wrap&&(A[0]=255&h,A[1]=h>>>8&255,a.check=L(a.check,A,2,0)),h=0,d=0,a.mode=16182;case 16182:for(;d<32;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}a.head&&(a.head.time=h),512&a.flags&&4&a.wrap&&(A[0]=255&h,A[1]=h>>>8&255,A[2]=h>>>16&255,A[3]=h>>>24&255,a.check=L(a.check,A,4,0)),h=0,d=0,a.mode=16183;case 16183:for(;d<16;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}a.head&&(a.head.xflags=255&h,a.head.os=h>>8),512&a.flags&&4&a.wrap&&(A[0]=255&h,A[1]=h>>>8&255,a.check=L(a.check,A,2,0)),h=0,d=0,a.mode=16184;case 16184:if(1024&a.flags){for(;d<16;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}a.length=h,a.head&&(a.head.extra_len=h),512&a.flags&&4&a.wrap&&(A[0]=255&h,A[1]=h>>>8&255,a.check=L(a.check,A,2,0)),h=0,d=0}else a.head&&(a.head.extra=null);a.mode=16185;case 16185:if(1024&a.flags&&(c=a.length,c>o&&(c=o),c&&(a.head&&(y=a.head.extra_len-a.length,a.head.extra||(a.head.extra=new Uint8Array(a.head.extra_len)),a.head.extra.set(i.subarray(s,s+c),y)),512&a.flags&&4&a.wrap&&(a.check=L(a.check,i,c,s)),o-=c,s+=c,a.length-=c),a.length))break t;a.length=0,a.mode=16186;case 16186:if(2048&a.flags){if(0===o)break t;c=0;do{y=i[s+c++],a.head&&y&&a.length<65536&&(a.head.name+=String.fromCharCode(y))}while(y&&c<o);if(512&a.flags&&4&a.wrap&&(a.check=L(a.check,i,c,s)),o-=c,s+=c,y)break t}else a.head&&(a.head.name=null);a.length=0,a.mode=16187;case 16187:if(4096&a.flags){if(0===o)break t;c=0;do{y=i[s+c++],a.head&&y&&a.length<65536&&(a.head.comment+=String.fromCharCode(y))}while(y&&c<o);if(512&a.flags&&4&a.wrap&&(a.check=L(a.check,i,c,s)),o-=c,s+=c,y)break t}else a.head&&(a.head.comment=null);a.mode=16188;case 16188:if(512&a.flags){for(;d<16;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}if(4&a.wrap&&h!==(65535&a.check)){t.msg="header crc mismatch",a.mode=me;break}h=0,d=0}a.head&&(a.head.hcrc=a.flags>>9&1,a.head.done=!0),t.adler=a.check=0,a.mode=16191;break;case 16189:for(;d<32;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}t.adler=a.check=be(h),h=0,d=0,a.mode=16190;case 16190:if(0===a.havedict)return t.next_out=r,t.avail_out=l,t.next_in=s,t.avail_in=o,a.hold=h,a.bits=d,de;t.adler=a.check=1,a.mode=16191;case 16191:if(e===re||e===oe)break t;case 16192:if(a.last){h>>>=7&d,d-=7&d,a.mode=16206;break}for(;d<3;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}switch(a.last=1&h,h>>>=1,d-=1,3&h){case 0:a.mode=16193;break;case 1:if(Re(a),a.mode=16199,e===oe){h>>>=2,d-=2;break t}break;case 2:a.mode=16196;break;case 3:t.msg="invalid block type",a.mode=me}h>>>=2,d-=2;break;case 16193:for(h>>>=7&d,d-=7&d;d<32;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}if((65535&h)!=(h>>>16^65535)){t.msg="invalid stored block lengths",a.mode=me;break}if(a.length=65535&h,h=0,d=0,a.mode=16194,e===oe)break t;case 16194:a.mode=16195;case 16195:if(c=a.length,c){if(c>o&&(c=o),c>l&&(c=l),0===c)break t;n.set(i.subarray(s,s+c),r),o-=c,s+=c,l-=c,r+=c,a.length-=c;break}a.mode=16191;break;case 16196:for(;d<14;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}if(a.nlen=257+(31&h),h>>>=5,d-=5,a.ndist=1+(31&h),h>>>=5,d-=5,a.ncode=4+(15&h),h>>>=4,d-=4,a.nlen>286||a.ndist>30){t.msg="too many length or distance symbols",a.mode=me;break}a.have=0,a.mode=16197;case 16197:for(;a.have<a.ncode;){for(;d<3;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}a.lens[Z[a.have++]]=7&h,h>>>=3,d-=3}for(;a.have<19;)a.lens[Z[a.have++]]=0;if(a.lencode=a.lendyn,a.lenbits=7,E={bits:a.lenbits},x=ne(0,a.lens,0,19,a.lencode,0,a.work,E),a.lenbits=E.bits,x){t.msg="invalid code lengths set",a.mode=me;break}a.have=0,a.mode=16198;case 16198:for(;a.have<a.nlen+a.ndist;){for(;z=a.lencode[h&(1<<a.lenbits)-1],m=z>>>24,b=z>>>16&255,g=65535&z,!(m<=d);){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}if(g<16)h>>>=m,d-=m,a.lens[a.have++]=g;else{if(16===g){for(R=m+2;d<R;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}if(h>>>=m,d-=m,0===a.have){t.msg="invalid bit length repeat",a.mode=me;break}y=a.lens[a.have-1],c=3+(3&h),h>>>=2,d-=2}else if(17===g){for(R=m+3;d<R;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}h>>>=m,d-=m,y=0,c=3+(7&h),h>>>=3,d-=3}else{for(R=m+7;d<R;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}h>>>=m,d-=m,y=0,c=11+(127&h),h>>>=7,d-=7}if(a.have+c>a.nlen+a.ndist){t.msg="invalid bit length repeat",a.mode=me;break}for(;c--;)a.lens[a.have++]=y}}if(a.mode===me)break;if(0===a.lens[256]){t.msg="invalid code -- missing end-of-block",a.mode=me;break}if(a.lenbits=9,E={bits:a.lenbits},x=ne(1,a.lens,0,a.nlen,a.lencode,0,a.work,E),a.lenbits=E.bits,x){t.msg="invalid literal/lengths set",a.mode=me;break}if(a.distbits=6,a.distcode=a.distdyn,E={bits:a.distbits},x=ne(2,a.lens,a.nlen,a.ndist,a.distcode,0,a.work,E),a.distbits=E.bits,x){t.msg="invalid distances set",a.mode=me;break}if(a.mode=16199,e===oe)break t;case 16199:a.mode=16200;case 16200:if(o>=6&&l>=258){t.next_out=r,t.avail_out=l,t.next_in=s,t.avail_in=o,a.hold=h,a.bits=d,$t(t,f),r=t.next_out,n=t.output,l=t.avail_out,s=t.next_in,i=t.input,o=t.avail_in,h=a.hold,d=a.bits,16191===a.mode&&(a.back=-1);break}for(a.back=0;z=a.lencode[h&(1<<a.lenbits)-1],m=z>>>24,b=z>>>16&255,g=65535&z,!(m<=d);){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}if(b&&0==(240&b)){for(p=m,k=b,v=g;z=a.lencode[v+((h&(1<<p+k)-1)>>p)],m=z>>>24,b=z>>>16&255,g=65535&z,!(p+m<=d);){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}h>>>=p,d-=p,a.back+=p}if(h>>>=m,d-=m,a.back+=m,a.length=g,0===b){a.mode=16205;break}if(32&b){a.back=-1,a.mode=16191;break}if(64&b){t.msg="invalid literal/length code",a.mode=me;break}a.extra=15&b,a.mode=16201;case 16201:if(a.extra){for(R=a.extra;d<R;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}a.length+=h&(1<<a.extra)-1,h>>>=a.extra,d-=a.extra,a.back+=a.extra}a.was=a.length,a.mode=16202;case 16202:for(;z=a.distcode[h&(1<<a.distbits)-1],m=z>>>24,b=z>>>16&255,g=65535&z,!(m<=d);){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}if(0==(240&b)){for(p=m,k=b,v=g;z=a.distcode[v+((h&(1<<p+k)-1)>>p)],m=z>>>24,b=z>>>16&255,g=65535&z,!(p+m<=d);){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}h>>>=p,d-=p,a.back+=p}if(h>>>=m,d-=m,a.back+=m,64&b){t.msg="invalid distance code",a.mode=me;break}a.offset=g,a.extra=15&b,a.mode=16203;case 16203:if(a.extra){for(R=a.extra;d<R;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}a.offset+=h&(1<<a.extra)-1,h>>>=a.extra,d-=a.extra,a.back+=a.extra}if(a.offset>a.dmax){t.msg="invalid distance too far back",a.mode=me;break}a.mode=16204;case 16204:if(0===l)break t;if(c=f-l,a.offset>c){if(c=a.offset-c,c>a.whave&&a.sane){t.msg="invalid distance too far back",a.mode=me;break}c>a.wnext?(c-=a.wnext,u=a.wsize-c):u=a.wnext-c,c>a.length&&(c=a.length),w=a.window}else w=n,u=r-a.offset,c=a.length;c>l&&(c=l),l-=c,a.length-=c;do{n[r++]=w[u++]}while(--c);0===a.length&&(a.mode=16200);break;case 16205:if(0===l)break t;n[r++]=a.length,l--,a.mode=16200;break;case 16206:if(a.wrap){for(;d<32;){if(0===o)break t;o--,h|=i[s++]<<d,d+=8}if(f-=l,t.total_out+=f,a.total+=f,4&a.wrap&&f&&(t.adler=a.check=a.flags?L(a.check,n,f,r-f):N(a.check,n,f,r-f)),f=l,4&a.wrap&&(a.flags?h:be(h))!==a.check){t.msg="incorrect data check",a.mode=me;break}h=0,d=0}a.mode=16207;case 16207:if(a.wrap&&a.flags){for(;d<32;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}if(4&a.wrap&&h!==(4294967295&a.total)){t.msg="incorrect length check",a.mode=me;break}h=0,d=0}a.mode=16208;case 16208:x=he;break t;case me:x=fe;break t;case 16210:return ce;default:return _e}return t.next_out=r,t.avail_out=l,t.next_in=s,t.avail_in=o,a.hold=h,a.bits=d,(a.wsize||f!==t.avail_out&&a.mode<me&&(a.mode<16206||e!==se))&&Ze(t,t.output,t.next_out,f-t.avail_out),_-=t.avail_in,f-=t.avail_out,t.total_in+=_,t.total_out+=f,a.total+=f,4&a.wrap&&f&&(t.adler=a.check=a.flags?L(a.check,n,f,t.next_out-f):N(a.check,n,f,t.next_out-f)),t.data_type=a.bits+(a.last?64:0)+(16191===a.mode?128:0)+(16199===a.mode||16194===a.mode?256:0),(0===_&&0===f||e===se)&&x===le&&(x=ue),x},inflateEnd:t=>{if(pe(t))return _e;let e=t.state;return e.window&&(e.window=null),t.state=null,le},inflateGetHeader:(t,e)=>{if(pe(t))return _e;const a=t.state;return 0==(2&a.wrap)?_e:(a.head=e,e.done=!1,le)},inflateSetDictionary:(t,e)=>{const a=e.length;let i,n,s;return pe(t)?_e:(i=t.state,0!==i.wrap&&16190!==i.mode?_e:16190===i.mode&&(n=1,n=N(n,e,a,0),n!==i.check)?fe:(s=Ze(t,e,a,a),s?(i.mode=16210,ce):(i.havedict=1,le)))},inflateInfo:"pako inflate (from Nodeca project)"};var Ue=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const De=Object.prototype.toString,{Z_NO_FLUSH:Oe,Z_FINISH:Te,Z_OK:Ne,Z_STREAM_END:Fe,Z_NEED_DICT:Le,Z_STREAM_ERROR:Ie,Z_DATA_ERROR:Be,Z_MEM_ERROR:Ce}=B;function He(t){this.options=Ot({chunkSize:65536,windowBits:15,to:""},t||{});const e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Ct,this.strm.avail_out=0;let a=Se.inflateInit2(this.strm,e.windowBits);if(a!==Ne)throw new Error(I[a]);if(this.header=new Ue,Se.inflateGetHeader(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=Lt(e.dictionary):"[object ArrayBuffer]"===De.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(a=Se.inflateSetDictionary(this.strm,e.dictionary),a!==Ne)))throw new Error(I[a])}He.prototype.push=function(t,e){const a=this.strm,i=this.options.chunkSize,n=this.options.dictionary;let s,r,o;if(this.ended)return!1;for(r=e===~~e?e:!0===e?Te:Oe,"[object ArrayBuffer]"===De.call(t)?a.input=new Uint8Array(t):a.input=t,a.next_in=0,a.avail_in=a.input.length;;){for(0===a.avail_out&&(a.output=new Uint8Array(i),a.next_out=0,a.avail_out=i),s=Se.inflate(a,r),s===Le&&n&&(s=Se.inflateSetDictionary(a,n),s===Ne?s=Se.inflate(a,r):s===Be&&(s=Le));a.avail_in>0&&s===Fe&&a.state.wrap>0&&0!==t[a.next_in];)Se.inflateReset(a),s=Se.inflate(a,r);switch(s){case Ie:case Be:case Le:case Ce:return this.onEnd(s),this.ended=!0,!1}if(o=a.avail_out,a.next_out&&(0===a.avail_out||s===Fe))if("string"===this.options.to){let t=Bt(a.output,a.next_out),e=a.next_out-t,n=It(a.output,t);a.next_out=e,a.avail_out=i-e,e&&a.output.set(a.output.subarray(t,t+e),0),this.onData(n)}else this.onData(a.output.length===a.next_out?a.output:a.output.subarray(0,a.next_out));if(s!==Ne||0!==o){if(s===Fe)return s=Se.inflateEnd(this.strm),this.onEnd(s),this.ended=!0,!0;if(0===a.avail_in)break}}return!0},He.prototype.onData=function(t){this.chunks.push(t)},He.prototype.onEnd=function(t){t===Ne&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Tt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};const{Deflate:Me,deflate:je,deflateRaw:Ke,gzip:Pe}=Vt;var Ye=Me,Ge=B;const Xe=new class{constructor(){this.added=0,this.init()}init(){this.added=0,this.deflate=new Ye,this.deflate.push("[",Ge.Z_NO_FLUSH)}addEvent(t){if(!t)throw new Error("Adding invalid event");const e=this.added>0?",":"";this.deflate.push(e+JSON.stringify(t),Ge.Z_SYNC_FLUSH),this.added++}finish(){if(this.deflate.push("]",Ge.Z_FINISH),this.deflate.err)throw this.deflate.err;const t=this.deflate.result;return this.init(),t}},Je={init:()=>(Xe.init(),""),addEvent:t=>Xe.addEvent(t),finish:()=>Xe.finish()};addEventListener("message",(function(t){const e=t.data.method,a=t.data.id,[i]=t.data.args?JSON.parse(t.data.args):[];if(e in Je&&"function"==typeof Je[e])try{const t=Je[e](i);postMessage({id:a,method:e,success:!0,response:t})}catch(t){postMessage({id:a,method:e,success:!1,response:t.message}),console.error(t)}})),postMessage({id:void 0,method:"init",success:!0,response:void 0});`;
3481
+
3374
3482
  /**
3375
- * An event handler to react to breadcrumbs.
3483
+ * Create an event buffer for replays.
3376
3484
  */
3377
- function breadcrumbHandler(type, handlerData) {
3378
- if (type === 'scope') {
3379
- return handleScope(handlerData );
3485
+ function createEventBuffer({ useCompression }) {
3486
+ // eslint-disable-next-line no-restricted-globals
3487
+ if (useCompression && window.Worker) {
3488
+ const workerBlob = new Blob([workerString]);
3489
+ const workerUrl = URL.createObjectURL(workerBlob);
3490
+
3491
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.log('[Replay] Using compression worker');
3492
+ const worker = new Worker(workerUrl);
3493
+ return new EventBufferProxy(worker);
3380
3494
  }
3381
3495
 
3382
- return handleDom(handlerData );
3496
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.log('[Replay] Using simple buffer');
3497
+ return new EventBufferArray();
3383
3498
  }
3384
3499
 
3385
3500
  /**
3386
- * Add an event to the event buffer
3501
+ * This proxy will try to use the compression worker, and fall back to use the simple buffer if an error occurs there.
3502
+ * This can happen e.g. if the worker cannot be loaded.
3503
+ * Exported only for testing.
3387
3504
  */
3388
- async function addEvent(
3389
- replay,
3390
- event,
3391
- isCheckout,
3392
- ) {
3393
- if (!replay.eventBuffer) {
3394
- // This implies that `_isEnabled` is false
3395
- return null;
3396
- }
3505
+ class EventBufferProxy {
3397
3506
 
3398
- if (replay.isPaused()) {
3399
- // Do not add to event buffer when recording is paused
3400
- return null;
3401
- }
3507
+ constructor(worker) {
3508
+ this._fallback = new EventBufferArray();
3509
+ this._compression = new EventBufferCompressionWorker(worker);
3510
+ this._used = this._fallback;
3402
3511
 
3403
- // TODO: sadness -- we will want to normalize timestamps to be in ms -
3404
- // requires coordination with frontend
3405
- const isMs = event.timestamp > 9999999999;
3406
- const timestampInMs = isMs ? event.timestamp : event.timestamp * 1000;
3512
+ void this._ensureWorkerIsLoaded();
3513
+ }
3407
3514
 
3408
- // Throw out events that happen more than 5 minutes ago. This can happen if
3409
- // page has been left open and idle for a long period of time and user
3410
- // comes back to trigger a new session. The performance entries rely on
3411
- // `performance.timeOrigin`, which is when the page first opened.
3412
- if (timestampInMs + SESSION_IDLE_DURATION < new Date().getTime()) {
3413
- return null;
3515
+ /** @inheritDoc */
3516
+ get pendingLength() {
3517
+ return this._used.pendingLength;
3414
3518
  }
3415
3519
 
3416
- // Only record earliest event if a new session was created, otherwise it
3417
- // shouldn't be relevant
3418
- const earliestEvent = replay.getContext().earliestEvent;
3419
- if (replay.session && replay.session.segmentId === 0 && (!earliestEvent || timestampInMs < earliestEvent)) {
3420
- replay.getContext().earliestEvent = timestampInMs;
3520
+ /** @inheritDoc */
3521
+ get pendingEvents() {
3522
+ return this._used.pendingEvents;
3421
3523
  }
3422
3524
 
3423
- return replay.eventBuffer.addEvent(event, isCheckout);
3424
- }
3525
+ /** @inheritDoc */
3526
+ destroy() {
3527
+ this._fallback.destroy();
3528
+ this._compression.destroy();
3529
+ }
3425
3530
 
3426
- /**
3427
- * Create a "span" for each performance entry. The parent transaction is `this.replayEvent`.
3428
- */
3429
- function createPerformanceSpans(
3430
- replay,
3431
- entries,
3432
- ) {
3433
- return entries.map(({ type, start, end, name, data }) =>
3434
- addEvent(replay, {
3435
- type: EventType.Custom,
3436
- timestamp: start,
3437
- data: {
3438
- tag: 'performanceSpan',
3439
- payload: {
3440
- op: type,
3441
- description: name,
3442
- startTimestamp: start,
3443
- endTimestamp: end,
3444
- data,
3445
- },
3446
- },
3447
- }),
3448
- );
3449
- }
3450
-
3451
- /**
3452
- * Check whether a given request URL should be filtered out.
3453
- */
3454
- function shouldFilterRequest(replay, url) {
3455
- // If we enabled the `traceInternals` experiment, we want to trace everything
3456
- if ((typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && replay.getOptions()._experiments.traceInternals) {
3457
- return false;
3531
+ /**
3532
+ * Add an event to the event buffer.
3533
+ *
3534
+ * Returns true if event was successfully added.
3535
+ */
3536
+ addEvent(event, isCheckout) {
3537
+ return this._used.addEvent(event, isCheckout);
3458
3538
  }
3459
3539
 
3460
- return !_isSentryRequest(url);
3461
- }
3462
-
3463
- /**
3464
- * Checks wether a given URL belongs to the configured Sentry DSN.
3465
- */
3466
- function _isSentryRequest(url) {
3467
- const client = core.getCurrentHub().getClient();
3468
- const dsn = client && client.getDsn();
3469
- return dsn ? url.includes(dsn.host) : false;
3470
- }
3471
-
3472
- /** only exported for tests */
3473
- function handleFetch(handlerData) {
3474
- if (!handlerData.endTimestamp) {
3475
- return null;
3540
+ /** @inheritDoc */
3541
+ finish() {
3542
+ return this._used.finish();
3476
3543
  }
3477
3544
 
3478
- const { startTimestamp, endTimestamp, fetchData, response } = handlerData;
3479
-
3480
- return {
3481
- type: 'resource.fetch',
3482
- start: startTimestamp / 1000,
3483
- end: endTimestamp / 1000,
3484
- name: fetchData.url,
3485
- data: {
3486
- method: fetchData.method,
3487
- statusCode: response.status,
3488
- },
3489
- };
3490
- }
3491
-
3492
- /**
3493
- * Returns a listener to be added to `addInstrumentationHandler('fetch', listener)`.
3494
- */
3495
- function handleFetchSpanListener(replay) {
3496
- return (handlerData) => {
3497
- if (!replay.isEnabled()) {
3498
- return;
3499
- }
3500
-
3501
- const result = handleFetch(handlerData);
3502
-
3503
- if (result === null) {
3545
+ /** Ensure the worker has loaded. */
3546
+ async _ensureWorkerIsLoaded() {
3547
+ try {
3548
+ await this._compression.ensureReady();
3549
+ } catch (error) {
3550
+ // If the worker fails to load, we fall back to the simple buffer.
3551
+ // Nothing more to do from our side here
3552
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.log('[Replay] Failed to load the compression worker, falling back to simple buffer');
3504
3553
  return;
3505
3554
  }
3506
3555
 
3507
- if (shouldFilterRequest(replay, result.name)) {
3508
- return;
3556
+ // Compression worker is ready, we can use it
3557
+ // Now we need to switch over the array buffer to the compression worker
3558
+ const addEventPromises = [];
3559
+ for (const event of this._fallback.pendingEvents) {
3560
+ addEventPromises.push(this._compression.addEvent(event));
3509
3561
  }
3510
3562
 
3511
- replay.addUpdate(() => {
3512
- createPerformanceSpans(replay, [result]);
3513
- // Returning true will cause `addUpdate` to not flush
3514
- // We do not want network requests to cause a flush. This will prevent
3515
- // recurring/polling requests from keeping the replay session alive.
3516
- return true;
3517
- });
3518
- };
3519
- }
3563
+ // We switch over to the compression buffer immediately - any further events will be added
3564
+ // after the previously buffered ones
3565
+ this._used = this._compression;
3520
3566
 
3521
- /**
3522
- * Returns true if we think the given event is an error originating inside of rrweb.
3523
- */
3524
- function isRrwebError(event) {
3525
- if (event.type || !event.exception || !event.exception.values || !event.exception.values.length) {
3526
- return false;
3567
+ // Wait for original events to be re-added before resolving
3568
+ await Promise.all(addEventPromises);
3527
3569
  }
3528
-
3529
- // Check if any exception originates from rrweb
3530
- return event.exception.values.some(exception => {
3531
- if (!exception.stacktrace || !exception.stacktrace.frames || !exception.stacktrace.frames.length) {
3532
- return false;
3533
- }
3534
-
3535
- return exception.stacktrace.frames.some(frame => frame.filename && frame.filename.includes('/rrweb/src/'));
3536
- });
3537
3570
  }
3538
3571
 
3539
- /**
3540
- * Returns a listener to be added to `addGlobalEventProcessor(listener)`.
3541
- */
3542
- function handleGlobalEventListener(replay) {
3543
- return (event) => {
3544
- // Do not apply replayId to the root event
3545
- if (event.type === REPLAY_EVENT_NAME) {
3546
- // Replays have separate set of breadcrumbs, do not include breadcrumbs
3547
- // from core SDK
3548
- delete event.breadcrumbs;
3549
- return event;
3550
- }
3572
+ class EventBufferArray {
3551
3573
 
3552
- // Unless `captureExceptions` is enabled, we want to ignore errors coming from rrweb
3553
- // As there can be a bunch of stuff going wrong in internals there, that we don't want to bubble up to users
3554
- if (isRrwebError(event) && !replay.getOptions()._experiments.captureExceptions) {
3555
- (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.log('[Replay] Ignoring error from rrweb internals', event);
3556
- return null;
3557
- }
3574
+ constructor() {
3575
+ this._events = [];
3576
+ }
3558
3577
 
3559
- // Only tag transactions with replayId if not waiting for an error
3560
- // @ts-ignore private
3561
- if (!event.type || replay.recordingMode === 'session') {
3562
- event.tags = { ...event.tags, replayId: replay.getSessionId() };
3563
- }
3578
+ get pendingLength() {
3579
+ return this._events.length;
3580
+ }
3564
3581
 
3565
- // Collect traceIds in _context regardless of `recordingMode` - if it's true,
3566
- // _context gets cleared on every checkout
3567
- if (event.type === 'transaction' && event.contexts && event.contexts.trace && event.contexts.trace.trace_id) {
3568
- replay.getContext().traceIds.add(event.contexts.trace.trace_id );
3569
- return event;
3570
- }
3582
+ /**
3583
+ * Returns the raw events that are buffered. In `EventBufferArray`, this is the
3584
+ * same as `this._events`.
3585
+ */
3586
+ get pendingEvents() {
3587
+ return this._events;
3588
+ }
3571
3589
 
3572
- // no event type means error
3573
- if (!event.type) {
3574
- replay.getContext().errorIds.add(event.event_id );
3575
- }
3590
+ destroy() {
3591
+ this._events = [];
3592
+ }
3576
3593
 
3577
- if ((typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && replay.getOptions()._experiments.traceInternals) {
3578
- const exc = getEventExceptionValues(event);
3579
- addInternalBreadcrumb({
3580
- message: `Tagging event (${event.event_id}) - ${event.message} - ${exc.type}: ${exc.value}`,
3581
- });
3594
+ async addEvent(event, isCheckout) {
3595
+ if (isCheckout) {
3596
+ this._events = [event];
3597
+ return;
3582
3598
  }
3583
3599
 
3584
- // Need to be very careful that this does not cause an infinite loop
3585
- if (
3586
- replay.recordingMode === 'error' &&
3587
- event.exception &&
3588
- event.message !== UNABLE_TO_SEND_REPLAY // ignore this error because otherwise we could loop indefinitely with trying to capture replay and failing
3589
- ) {
3590
- setTimeout(async () => {
3591
- // Allow flush to complete before resuming as a session recording, otherwise
3592
- // the checkout from `startRecording` may be included in the payload.
3593
- // Prefer to keep the error replay as a separate (and smaller) segment
3594
- // than the session replay.
3595
- await replay.flushImmediate();
3596
-
3597
- if (replay.stopRecording()) {
3598
- // Reset all "capture on error" configuration before
3599
- // starting a new recording
3600
- replay.recordingMode = 'session';
3601
- replay.startRecording();
3602
- }
3603
- });
3604
- }
3600
+ this._events.push(event);
3601
+ return;
3602
+ }
3605
3603
 
3606
- return event;
3607
- };
3604
+ finish() {
3605
+ return new Promise(resolve => {
3606
+ // Make a copy of the events array reference and immediately clear the
3607
+ // events member so that we do not lose new events while uploading
3608
+ // attachment.
3609
+ const eventsRet = this._events;
3610
+ this._events = [];
3611
+ resolve(JSON.stringify(eventsRet));
3612
+ });
3613
+ }
3608
3614
  }
3609
3615
 
3610
- function addInternalBreadcrumb(arg) {
3611
- const { category, level, message, ...rest } = arg;
3616
+ /**
3617
+ * Event buffer that uses a web worker to compress events.
3618
+ * Exported only for testing.
3619
+ */
3620
+ class EventBufferCompressionWorker {
3621
+ /**
3622
+ * Keeps track of the list of events since the last flush that have not been compressed.
3623
+ * For example, page is reloaded and a flush attempt is made, but
3624
+ * `finish()` (and thus the flush), does not complete.
3625
+ */
3626
+ __init() {this._pendingEvents = [];}
3612
3627
 
3613
- core.addBreadcrumb({
3614
- category: category || 'console',
3615
- level: level || 'debug',
3616
- message: `[debug]: ${message}`,
3617
- ...rest,
3618
- });
3619
- }
3628
+ __init2() {this._eventBufferItemLength = 0;}
3629
+ __init3() {this._id = 0;}
3620
3630
 
3621
- function getEventExceptionValues(event) {
3622
- return {
3623
- type: 'Unknown',
3624
- value: 'n/a',
3625
- ...(event.exception && event.exception.values && event.exception.values[0]),
3626
- };
3627
- }
3631
+ constructor(worker) {EventBufferCompressionWorker.prototype.__init.call(this);EventBufferCompressionWorker.prototype.__init2.call(this);EventBufferCompressionWorker.prototype.__init3.call(this);
3632
+ this._worker = worker;
3633
+ }
3628
3634
 
3629
- function handleHistory(handlerData) {
3630
- const { from, to } = handlerData;
3635
+ /**
3636
+ * The number of raw events that are buffered. This may not be the same as
3637
+ * the number of events that have been compresed in the worker because
3638
+ * `addEvent` is async.
3639
+ */
3640
+ get pendingLength() {
3641
+ return this._eventBufferItemLength;
3642
+ }
3631
3643
 
3632
- const now = new Date().getTime() / 1000;
3644
+ /**
3645
+ * Returns a list of the raw recording events that are being compressed.
3646
+ */
3647
+ get pendingEvents() {
3648
+ return this._pendingEvents;
3649
+ }
3633
3650
 
3634
- return {
3635
- type: 'navigation.push',
3636
- start: now,
3637
- end: now,
3638
- name: to,
3639
- data: {
3640
- previous: from,
3641
- },
3642
- };
3643
- }
3651
+ /**
3652
+ * Ensure the worker is ready (or not).
3653
+ * This will either resolve when the worker is ready, or reject if an error occured.
3654
+ */
3655
+ ensureReady() {
3656
+ return new Promise((resolve, reject) => {
3657
+ this._worker.addEventListener(
3658
+ 'message',
3659
+ ({ data }) => {
3660
+ if (data.success) {
3661
+ resolve();
3662
+ } else {
3663
+ reject();
3664
+ }
3665
+ },
3666
+ { once: true },
3667
+ );
3644
3668
 
3645
- /**
3646
- * Returns a listener to be added to `addInstrumentationHandler('history', listener)`.
3647
- */
3648
- function handleHistorySpanListener(replay) {
3649
- return (handlerData) => {
3650
- if (!replay.isEnabled()) {
3651
- return;
3669
+ this._worker.addEventListener(
3670
+ 'error',
3671
+ error => {
3672
+ reject(error);
3673
+ },
3674
+ { once: true },
3675
+ );
3676
+ });
3677
+ }
3678
+
3679
+ /**
3680
+ * Destroy the event buffer.
3681
+ */
3682
+ destroy() {
3683
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.log('[Replay] Destroying compression worker');
3684
+ this._worker.terminate();
3685
+ }
3686
+
3687
+ /**
3688
+ * Add an event to the event buffer.
3689
+ *
3690
+ * Returns true if event was successfuly received and processed by worker.
3691
+ */
3692
+ async addEvent(event, isCheckout) {
3693
+ if (isCheckout) {
3694
+ // This event is a checkout, make sure worker buffer is cleared before
3695
+ // proceeding.
3696
+ await this._postMessage({
3697
+ id: this._getAndIncrementId(),
3698
+ method: 'init',
3699
+ args: [],
3700
+ });
3652
3701
  }
3653
3702
 
3654
- const result = handleHistory(handlerData);
3655
-
3656
- if (result === null) {
3657
- return;
3703
+ // Don't store checkout events in `_pendingEvents` because they are too large
3704
+ if (!isCheckout) {
3705
+ this._pendingEvents.push(event);
3658
3706
  }
3659
3707
 
3660
- // Need to collect visited URLs
3661
- replay.getContext().urls.push(result.name);
3662
- replay.triggerUserActivity();
3708
+ return this._sendEventToWorker(event);
3709
+ }
3663
3710
 
3664
- replay.addUpdate(() => {
3665
- createPerformanceSpans(replay, [result]);
3666
- // Returning false to flush
3667
- return false;
3668
- });
3669
- };
3670
- }
3711
+ /**
3712
+ * Finish the event buffer and return the compressed data.
3713
+ */
3714
+ finish() {
3715
+ return this._finishRequest(this._getAndIncrementId());
3716
+ }
3671
3717
 
3672
- // From sentry-javascript
3673
- // e.g. https://github.com/getsentry/sentry-javascript/blob/c7fc025bf9fa8c073fdb56351808ce53909fbe45/packages/utils/src/instrument.ts#L180
3718
+ /**
3719
+ * Post message to worker and wait for response before resolving promise.
3720
+ */
3721
+ _postMessage({ id, method, args }) {
3722
+ return new Promise((resolve, reject) => {
3723
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
3724
+ const listener = ({ data }) => {
3725
+ if (data.method !== method) {
3726
+ return;
3727
+ }
3674
3728
 
3675
- function handleXhr(handlerData) {
3676
- if (handlerData.xhr.__sentry_own_request__) {
3677
- // Taken from sentry-javascript
3678
- // Only capture non-sentry requests
3679
- return null;
3680
- }
3729
+ // There can be multiple listeners for a single method, the id ensures
3730
+ // that the response matches the caller.
3731
+ if (data.id !== id) {
3732
+ return;
3733
+ }
3681
3734
 
3682
- if (handlerData.startTimestamp) {
3683
- // TODO: See if this is still needed
3684
- handlerData.xhr.__sentry_xhr__ = handlerData.xhr.__sentry_xhr__ || {};
3685
- handlerData.xhr.__sentry_xhr__.startTimestamp = handlerData.startTimestamp;
3686
- }
3735
+ // At this point, we'll always want to remove listener regardless of result status
3736
+ this._worker.removeEventListener('message', listener);
3687
3737
 
3688
- if (!handlerData.endTimestamp) {
3689
- return null;
3690
- }
3738
+ if (!data.success) {
3739
+ // TODO: Do some error handling, not sure what
3740
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.error('[Replay]', data.response);
3691
3741
 
3692
- const { method, url, status_code: statusCode } = handlerData.xhr.__sentry_xhr__ || {};
3742
+ reject(new Error('Error in compression worker'));
3743
+ return;
3744
+ }
3693
3745
 
3694
- if (url === undefined) {
3695
- return null;
3746
+ resolve(data.response);
3747
+ };
3748
+
3749
+ let stringifiedArgs;
3750
+ try {
3751
+ stringifiedArgs = JSON.stringify(args);
3752
+ } catch (err) {
3753
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.error('[Replay] Error when trying to stringify args', err);
3754
+ stringifiedArgs = '[]';
3755
+ }
3756
+
3757
+ // Note: we can't use `once` option because it's possible it needs to
3758
+ // listen to multiple messages
3759
+ this._worker.addEventListener('message', listener);
3760
+ this._worker.postMessage({ id, method, args: stringifiedArgs });
3761
+ });
3696
3762
  }
3697
3763
 
3698
- const timestamp = handlerData.xhr.__sentry_xhr__
3699
- ? handlerData.xhr.__sentry_xhr__.startTimestamp || 0
3700
- : handlerData.endTimestamp;
3764
+ /**
3765
+ * Send the event to the worker.
3766
+ */
3767
+ async _sendEventToWorker(event) {
3768
+ const promise = this._postMessage({
3769
+ id: this._getAndIncrementId(),
3770
+ method: 'addEvent',
3771
+ args: [event],
3772
+ });
3701
3773
 
3702
- return {
3703
- type: 'resource.xhr',
3704
- name: url,
3705
- start: timestamp / 1000,
3706
- end: handlerData.endTimestamp / 1000,
3707
- data: {
3708
- method,
3709
- statusCode,
3710
- },
3711
- };
3712
- }
3774
+ // XXX: See note in `get length()`
3775
+ this._eventBufferItemLength++;
3713
3776
 
3714
- /**
3715
- * Returns a listener to be added to `addInstrumentationHandler('xhr', listener)`.
3716
- */
3717
- function handleXhrSpanListener(replay) {
3718
- return (handlerData) => {
3719
- if (!replay.isEnabled()) {
3720
- return;
3721
- }
3777
+ return promise;
3778
+ }
3722
3779
 
3723
- const result = handleXhr(handlerData);
3780
+ /**
3781
+ * Finish the request and return the compressed data from the worker.
3782
+ */
3783
+ async _finishRequest(id) {
3784
+ const promise = this._postMessage({ id, method: 'finish', args: [] });
3724
3785
 
3725
- if (result === null) {
3726
- return;
3727
- }
3786
+ // XXX: See note in `get length()`
3787
+ this._eventBufferItemLength = 0;
3728
3788
 
3729
- if (shouldFilterRequest(replay, result.name)) {
3730
- return;
3731
- }
3789
+ await promise;
3732
3790
 
3733
- replay.addUpdate(() => {
3734
- createPerformanceSpans(replay, [result]);
3735
- // Returning true will cause `addUpdate` to not flush
3736
- // We do not want network requests to cause a flush. This will prevent
3737
- // recurring/polling requests from keeping the replay session alive.
3738
- return true;
3739
- });
3740
- };
3741
- }
3791
+ this._pendingEvents = [];
3742
3792
 
3743
- const NAVIGATION_ENTRY_KEYS = [
3744
- 'name',
3745
- 'type',
3746
- 'startTime',
3747
- 'transferSize',
3748
- 'duration',
3749
- ];
3793
+ return promise;
3794
+ }
3750
3795
 
3751
- function isNavigationEntryEqual(a) {
3752
- return function (b) {
3753
- return NAVIGATION_ENTRY_KEYS.every(key => a[key] === b[key]);
3754
- };
3796
+ /** Get the current ID and increment it for the next call. */
3797
+ _getAndIncrementId() {
3798
+ return this._id++;
3799
+ }
3755
3800
  }
3756
3801
 
3757
3802
  /**
3758
- * There are some difficulties diagnosing why there are duplicate navigation
3759
- * entries. We've witnessed several intermittent results:
3760
- * - duplicate entries have duration = 0
3761
- * - duplicate entries are the same object reference
3762
- * - none of the above
3763
- *
3764
- * Compare the values of several keys to determine if the entries are duplicates or not.
3803
+ * Given an initial timestamp and an expiry duration, checks to see if current
3804
+ * time should be considered as expired.
3765
3805
  */
3766
- // TODO (high-prio): Figure out wth is returned here
3767
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
3768
- function dedupePerformanceEntries(
3769
- currentList,
3770
- newList,
3806
+ function isExpired(
3807
+ initialTime,
3808
+ expiry,
3809
+ targetTime = +new Date(),
3771
3810
  ) {
3772
- // Partition `currentList` into 3 different lists based on entryType
3773
- const [existingNavigationEntries, existingLcpEntries, existingEntries] = currentList.reduce(
3774
- (acc, entry) => {
3775
- if (entry.entryType === 'navigation') {
3776
- acc[0].push(entry );
3777
- } else if (entry.entryType === 'largest-contentful-paint') {
3778
- acc[1].push(entry );
3779
- } else {
3780
- acc[2].push(entry);
3781
- }
3782
- return acc;
3783
- },
3784
- [[], [], []],
3785
- );
3811
+ // Always expired if < 0
3812
+ if (initialTime === null || expiry === undefined || expiry < 0) {
3813
+ return true;
3814
+ }
3786
3815
 
3787
- const newEntries = [];
3788
- const newNavigationEntries = [];
3789
- let newLcpEntry = existingLcpEntries.length
3790
- ? existingLcpEntries[existingLcpEntries.length - 1] // Take the last element as list is sorted
3791
- : undefined;
3816
+ // Never expires if == 0
3817
+ if (expiry === 0) {
3818
+ return false;
3819
+ }
3792
3820
 
3793
- newList.forEach(entry => {
3794
- if (entry.entryType === 'largest-contentful-paint') {
3795
- // We want the latest LCP event only
3796
- if (!newLcpEntry || newLcpEntry.startTime < entry.startTime) {
3797
- newLcpEntry = entry;
3798
- }
3799
- return;
3800
- }
3821
+ return initialTime + expiry <= targetTime;
3822
+ }
3801
3823
 
3802
- if (entry.entryType === 'navigation') {
3803
- const navigationEntry = entry ;
3824
+ /**
3825
+ * Checks to see if session is expired
3826
+ */
3827
+ function isSessionExpired(session, idleTimeout, targetTime = +new Date()) {
3828
+ return (
3829
+ // First, check that maximum session length has not been exceeded
3830
+ isExpired(session.started, MAX_SESSION_LIFE, targetTime) ||
3831
+ // check that the idle timeout has not been exceeded (i.e. user has
3832
+ // performed an action within the last `idleTimeout` ms)
3833
+ isExpired(session.lastActivity, idleTimeout, targetTime)
3834
+ );
3835
+ }
3804
3836
 
3805
- // Check if the navigation entry is contained in currentList or newList
3806
- if (
3807
- // Ignore any navigation entries with duration 0, as they are likely duplicates
3808
- entry.duration > 0 &&
3809
- // Ensure new entry does not already exist in existing entries
3810
- !existingNavigationEntries.find(isNavigationEntryEqual(navigationEntry)) &&
3811
- // Ensure new entry does not already exist in new list of navigation entries
3812
- !newNavigationEntries.find(isNavigationEntryEqual(navigationEntry))
3813
- ) {
3814
- newNavigationEntries.push(navigationEntry);
3815
- }
3837
+ /**
3838
+ * Save a session to session storage.
3839
+ */
3840
+ function saveSession(session) {
3841
+ const hasSessionStorage = 'sessionStorage' in WINDOW;
3842
+ if (!hasSessionStorage) {
3843
+ return;
3844
+ }
3816
3845
 
3817
- // Otherwise this navigation entry is considered a duplicate and is thrown away
3818
- return;
3819
- }
3846
+ try {
3847
+ WINDOW.sessionStorage.setItem(REPLAY_SESSION_KEY, JSON.stringify(session));
3848
+ } catch (e) {
3849
+ // Ignore potential SecurityError exceptions
3850
+ }
3851
+ }
3820
3852
 
3821
- newEntries.push(entry);
3822
- });
3853
+ /**
3854
+ * Given a sample rate, returns true if replay should be sampled.
3855
+ *
3856
+ * 1.0 = 100% sampling
3857
+ * 0.0 = 0% sampling
3858
+ */
3859
+ function isSampled(sampleRate) {
3860
+ if (sampleRate === undefined) {
3861
+ return false;
3862
+ }
3823
3863
 
3824
- // Re-combine and sort by startTime
3825
- return [
3826
- ...(newLcpEntry ? [newLcpEntry] : []),
3827
- ...existingNavigationEntries,
3828
- ...existingEntries,
3829
- ...newEntries,
3830
- ...newNavigationEntries,
3831
- ].sort((a, b) => a.startTime - b.startTime);
3864
+ // Math.random() returns a number in range of 0 to 1 (inclusive of 0, but not 1)
3865
+ return Math.random() < sampleRate;
3832
3866
  }
3833
3867
 
3834
3868
  /**
3835
- * Sets up a PerformanceObserver to listen to all performance entry types.
3869
+ * Get a session with defaults & applied sampling.
3836
3870
  */
3837
- function setupPerformanceObserver(replay) {
3838
- const performanceObserverHandler = (list) => {
3839
- // For whatever reason the observer was returning duplicate navigation
3840
- // entries (the other entry types were not duplicated).
3841
- const newPerformanceEntries = dedupePerformanceEntries(
3842
- replay.performanceEvents,
3843
- list.getEntries() ,
3844
- );
3845
- replay.performanceEvents = newPerformanceEntries;
3871
+ function makeSession(session) {
3872
+ const now = new Date().getTime();
3873
+ const id = session.id || utils.uuid4();
3874
+ // Note that this means we cannot set a started/lastActivity of `0`, but this should not be relevant outside of tests.
3875
+ const started = session.started || now;
3876
+ const lastActivity = session.lastActivity || now;
3877
+ const segmentId = session.segmentId || 0;
3878
+ const sampled = session.sampled;
3879
+
3880
+ return {
3881
+ id,
3882
+ started,
3883
+ lastActivity,
3884
+ segmentId,
3885
+ sampled,
3846
3886
  };
3887
+ }
3847
3888
 
3848
- const performanceObserver = new PerformanceObserver(performanceObserverHandler);
3889
+ /**
3890
+ * Get the sampled status for a session based on sample rates & current sampled status.
3891
+ */
3892
+ function getSessionSampleType(sessionSampleRate, errorSampleRate) {
3893
+ return isSampled(sessionSampleRate) ? 'session' : isSampled(errorSampleRate) ? 'error' : false;
3894
+ }
3849
3895
 
3850
- [
3851
- 'element',
3852
- 'event',
3853
- 'first-input',
3854
- 'largest-contentful-paint',
3855
- 'layout-shift',
3856
- 'longtask',
3857
- 'navigation',
3858
- 'paint',
3859
- 'resource',
3860
- ].forEach(type => {
3861
- try {
3862
- performanceObserver.observe({
3863
- type,
3864
- buffered: true,
3865
- });
3866
- } catch (e) {
3867
- // This can throw if an entry type is not supported in the browser.
3868
- // Ignore these errors.
3869
- }
3896
+ /**
3897
+ * Create a new session, which in its current implementation is a Sentry event
3898
+ * that all replays will be saved to as attachments. Currently, we only expect
3899
+ * one of these Sentry events per "replay session".
3900
+ */
3901
+ function createSession({ sessionSampleRate, errorSampleRate, stickySession = false }) {
3902
+ const sampled = getSessionSampleType(sessionSampleRate, errorSampleRate);
3903
+ const session = makeSession({
3904
+ sampled,
3870
3905
  });
3871
3906
 
3872
- return performanceObserver;
3873
- }
3907
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.log(`[Replay] Creating new session: ${session.id}`);
3874
3908
 
3875
- const workerString = `/*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) */
3876
- function t(t){let e=t.length;for(;--e>=0;)t[e]=0}const e=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),a=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),i=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),n=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),s=new Array(576);t(s);const r=new Array(60);t(r);const o=new Array(512);t(o);const l=new Array(256);t(l);const h=new Array(29);t(h);const d=new Array(30);function _(t,e,a,i,n){this.static_tree=t,this.extra_bits=e,this.extra_base=a,this.elems=i,this.max_length=n,this.has_stree=t&&t.length}let f,c,u;function w(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}t(d);const m=t=>t<256?o[t]:o[256+(t>>>7)],b=(t,e)=>{t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},g=(t,e,a)=>{t.bi_valid>16-a?(t.bi_buf|=e<<t.bi_valid&65535,b(t,t.bi_buf),t.bi_buf=e>>16-t.bi_valid,t.bi_valid+=a-16):(t.bi_buf|=e<<t.bi_valid&65535,t.bi_valid+=a)},p=(t,e,a)=>{g(t,a[2*e],a[2*e+1])},k=(t,e)=>{let a=0;do{a|=1&t,t>>>=1,a<<=1}while(--e>0);return a>>>1},v=(t,e,a)=>{const i=new Array(16);let n,s,r=0;for(n=1;n<=15;n++)r=r+a[n-1]<<1,i[n]=r;for(s=0;s<=e;s++){let e=t[2*s+1];0!==e&&(t[2*s]=k(i[e]++,e))}},y=t=>{let e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.sym_next=t.matches=0},x=t=>{t.bi_valid>8?b(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},z=(t,e,a,i)=>{const n=2*e,s=2*a;return t[n]<t[s]||t[n]===t[s]&&i[e]<=i[a]},A=(t,e,a)=>{const i=t.heap[a];let n=a<<1;for(;n<=t.heap_len&&(n<t.heap_len&&z(e,t.heap[n+1],t.heap[n],t.depth)&&n++,!z(e,i,t.heap[n],t.depth));)t.heap[a]=t.heap[n],a=n,n<<=1;t.heap[a]=i},E=(t,i,n)=>{let s,r,o,_,f=0;if(0!==t.sym_next)do{s=255&t.pending_buf[t.sym_buf+f++],s+=(255&t.pending_buf[t.sym_buf+f++])<<8,r=t.pending_buf[t.sym_buf+f++],0===s?p(t,r,i):(o=l[r],p(t,o+256+1,i),_=e[o],0!==_&&(r-=h[o],g(t,r,_)),s--,o=m(s),p(t,o,n),_=a[o],0!==_&&(s-=d[o],g(t,s,_)))}while(f<t.sym_next);p(t,256,i)},R=(t,e)=>{const a=e.dyn_tree,i=e.stat_desc.static_tree,n=e.stat_desc.has_stree,s=e.stat_desc.elems;let r,o,l,h=-1;for(t.heap_len=0,t.heap_max=573,r=0;r<s;r++)0!==a[2*r]?(t.heap[++t.heap_len]=h=r,t.depth[r]=0):a[2*r+1]=0;for(;t.heap_len<2;)l=t.heap[++t.heap_len]=h<2?++h:0,a[2*l]=1,t.depth[l]=0,t.opt_len--,n&&(t.static_len-=i[2*l+1]);for(e.max_code=h,r=t.heap_len>>1;r>=1;r--)A(t,a,r);l=s;do{r=t.heap[1],t.heap[1]=t.heap[t.heap_len--],A(t,a,1),o=t.heap[1],t.heap[--t.heap_max]=r,t.heap[--t.heap_max]=o,a[2*l]=a[2*r]+a[2*o],t.depth[l]=(t.depth[r]>=t.depth[o]?t.depth[r]:t.depth[o])+1,a[2*r+1]=a[2*o+1]=l,t.heap[1]=l++,A(t,a,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],((t,e)=>{const a=e.dyn_tree,i=e.max_code,n=e.stat_desc.static_tree,s=e.stat_desc.has_stree,r=e.stat_desc.extra_bits,o=e.stat_desc.extra_base,l=e.stat_desc.max_length;let h,d,_,f,c,u,w=0;for(f=0;f<=15;f++)t.bl_count[f]=0;for(a[2*t.heap[t.heap_max]+1]=0,h=t.heap_max+1;h<573;h++)d=t.heap[h],f=a[2*a[2*d+1]+1]+1,f>l&&(f=l,w++),a[2*d+1]=f,d>i||(t.bl_count[f]++,c=0,d>=o&&(c=r[d-o]),u=a[2*d],t.opt_len+=u*(f+c),s&&(t.static_len+=u*(n[2*d+1]+c)));if(0!==w){do{for(f=l-1;0===t.bl_count[f];)f--;t.bl_count[f]--,t.bl_count[f+1]+=2,t.bl_count[l]--,w-=2}while(w>0);for(f=l;0!==f;f--)for(d=t.bl_count[f];0!==d;)_=t.heap[--h],_>i||(a[2*_+1]!==f&&(t.opt_len+=(f-a[2*_+1])*a[2*_],a[2*_+1]=f),d--)}})(t,e),v(a,h,t.bl_count)},Z=(t,e,a)=>{let i,n,s=-1,r=e[1],o=0,l=7,h=4;for(0===r&&(l=138,h=3),e[2*(a+1)+1]=65535,i=0;i<=a;i++)n=r,r=e[2*(i+1)+1],++o<l&&n===r||(o<h?t.bl_tree[2*n]+=o:0!==n?(n!==s&&t.bl_tree[2*n]++,t.bl_tree[32]++):o<=10?t.bl_tree[34]++:t.bl_tree[36]++,o=0,s=n,0===r?(l=138,h=3):n===r?(l=6,h=3):(l=7,h=4))},S=(t,e,a)=>{let i,n,s=-1,r=e[1],o=0,l=7,h=4;for(0===r&&(l=138,h=3),i=0;i<=a;i++)if(n=r,r=e[2*(i+1)+1],!(++o<l&&n===r)){if(o<h)do{p(t,n,t.bl_tree)}while(0!=--o);else 0!==n?(n!==s&&(p(t,n,t.bl_tree),o--),p(t,16,t.bl_tree),g(t,o-3,2)):o<=10?(p(t,17,t.bl_tree),g(t,o-3,3)):(p(t,18,t.bl_tree),g(t,o-11,7));o=0,s=n,0===r?(l=138,h=3):n===r?(l=6,h=3):(l=7,h=4)}};let U=!1;const D=(t,e,a,i)=>{g(t,0+(i?1:0),3),x(t),b(t,a),b(t,~a),a&&t.pending_buf.set(t.window.subarray(e,e+a),t.pending),t.pending+=a};var O=(t,e,a,i)=>{let o,l,h=0;t.level>0?(2===t.strm.data_type&&(t.strm.data_type=(t=>{let e,a=4093624447;for(e=0;e<=31;e++,a>>>=1)if(1&a&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0})(t)),R(t,t.l_desc),R(t,t.d_desc),h=(t=>{let e;for(Z(t,t.dyn_ltree,t.l_desc.max_code),Z(t,t.dyn_dtree,t.d_desc.max_code),R(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*n[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e})(t),o=t.opt_len+3+7>>>3,l=t.static_len+3+7>>>3,l<=o&&(o=l)):o=l=a+5,a+4<=o&&-1!==e?D(t,e,a,i):4===t.strategy||l===o?(g(t,2+(i?1:0),3),E(t,s,r)):(g(t,4+(i?1:0),3),((t,e,a,i)=>{let s;for(g(t,e-257,5),g(t,a-1,5),g(t,i-4,4),s=0;s<i;s++)g(t,t.bl_tree[2*n[s]+1],3);S(t,t.dyn_ltree,e-1),S(t,t.dyn_dtree,a-1)})(t,t.l_desc.max_code+1,t.d_desc.max_code+1,h+1),E(t,t.dyn_ltree,t.dyn_dtree)),y(t),i&&x(t)},T={_tr_init:t=>{U||((()=>{let t,n,w,m,b;const g=new Array(16);for(w=0,m=0;m<28;m++)for(h[m]=w,t=0;t<1<<e[m];t++)l[w++]=m;for(l[w-1]=m,b=0,m=0;m<16;m++)for(d[m]=b,t=0;t<1<<a[m];t++)o[b++]=m;for(b>>=7;m<30;m++)for(d[m]=b<<7,t=0;t<1<<a[m]-7;t++)o[256+b++]=m;for(n=0;n<=15;n++)g[n]=0;for(t=0;t<=143;)s[2*t+1]=8,t++,g[8]++;for(;t<=255;)s[2*t+1]=9,t++,g[9]++;for(;t<=279;)s[2*t+1]=7,t++,g[7]++;for(;t<=287;)s[2*t+1]=8,t++,g[8]++;for(v(s,287,g),t=0;t<30;t++)r[2*t+1]=5,r[2*t]=k(t,5);f=new _(s,e,257,286,15),c=new _(r,a,0,30,15),u=new _(new Array(0),i,0,19,7)})(),U=!0),t.l_desc=new w(t.dyn_ltree,f),t.d_desc=new w(t.dyn_dtree,c),t.bl_desc=new w(t.bl_tree,u),t.bi_buf=0,t.bi_valid=0,y(t)},_tr_stored_block:D,_tr_flush_block:O,_tr_tally:(t,e,a)=>(t.pending_buf[t.sym_buf+t.sym_next++]=e,t.pending_buf[t.sym_buf+t.sym_next++]=e>>8,t.pending_buf[t.sym_buf+t.sym_next++]=a,0===e?t.dyn_ltree[2*a]++:(t.matches++,e--,t.dyn_ltree[2*(l[a]+256+1)]++,t.dyn_dtree[2*m(e)]++),t.sym_next===t.sym_end),_tr_align:t=>{g(t,2,3),p(t,256,s),(t=>{16===t.bi_valid?(b(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)})(t)}};var N=(t,e,a,i)=>{let n=65535&t|0,s=t>>>16&65535|0,r=0;for(;0!==a;){r=a>2e3?2e3:a,a-=r;do{n=n+e[i++]|0,s=s+n|0}while(--r);n%=65521,s%=65521}return n|s<<16|0};const F=new Uint32Array((()=>{let t,e=[];for(var a=0;a<256;a++){t=a;for(var i=0;i<8;i++)t=1&t?3988292384^t>>>1:t>>>1;e[a]=t}return e})());var L=(t,e,a,i)=>{const n=F,s=i+a;t^=-1;for(let a=i;a<s;a++)t=t>>>8^n[255&(t^e[a])];return-1^t},I={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},B={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:C,_tr_stored_block:H,_tr_flush_block:M,_tr_tally:j,_tr_align:K}=T,{Z_NO_FLUSH:P,Z_PARTIAL_FLUSH:Y,Z_FULL_FLUSH:G,Z_FINISH:X,Z_BLOCK:J,Z_OK:W,Z_STREAM_END:q,Z_STREAM_ERROR:Q,Z_DATA_ERROR:V,Z_BUF_ERROR:$,Z_DEFAULT_COMPRESSION:tt,Z_FILTERED:et,Z_HUFFMAN_ONLY:at,Z_RLE:it,Z_FIXED:nt,Z_DEFAULT_STRATEGY:st,Z_UNKNOWN:rt,Z_DEFLATED:ot}=B,lt=(t,e)=>(t.msg=I[e],e),ht=t=>2*t-(t>4?9:0),dt=t=>{let e=t.length;for(;--e>=0;)t[e]=0},_t=t=>{let e,a,i,n=t.w_size;e=t.hash_size,i=e;do{a=t.head[--i],t.head[i]=a>=n?a-n:0}while(--e);e=n,i=e;do{a=t.prev[--i],t.prev[i]=a>=n?a-n:0}while(--e)};let ft=(t,e,a)=>(e<<t.hash_shift^a)&t.hash_mask;const ct=t=>{const e=t.state;let a=e.pending;a>t.avail_out&&(a=t.avail_out),0!==a&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+a),t.next_out),t.next_out+=a,e.pending_out+=a,t.total_out+=a,t.avail_out-=a,e.pending-=a,0===e.pending&&(e.pending_out=0))},ut=(t,e)=>{M(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,ct(t.strm)},wt=(t,e)=>{t.pending_buf[t.pending++]=e},mt=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},bt=(t,e,a,i)=>{let n=t.avail_in;return n>i&&(n=i),0===n?0:(t.avail_in-=n,e.set(t.input.subarray(t.next_in,t.next_in+n),a),1===t.state.wrap?t.adler=N(t.adler,e,n,a):2===t.state.wrap&&(t.adler=L(t.adler,e,n,a)),t.next_in+=n,t.total_in+=n,n)},gt=(t,e)=>{let a,i,n=t.max_chain_length,s=t.strstart,r=t.prev_length,o=t.nice_match;const l=t.strstart>t.w_size-262?t.strstart-(t.w_size-262):0,h=t.window,d=t.w_mask,_=t.prev,f=t.strstart+258;let c=h[s+r-1],u=h[s+r];t.prev_length>=t.good_match&&(n>>=2),o>t.lookahead&&(o=t.lookahead);do{if(a=e,h[a+r]===u&&h[a+r-1]===c&&h[a]===h[s]&&h[++a]===h[s+1]){s+=2,a++;do{}while(h[++s]===h[++a]&&h[++s]===h[++a]&&h[++s]===h[++a]&&h[++s]===h[++a]&&h[++s]===h[++a]&&h[++s]===h[++a]&&h[++s]===h[++a]&&h[++s]===h[++a]&&s<f);if(i=258-(f-s),s=f-258,i>r){if(t.match_start=e,r=i,i>=o)break;c=h[s+r-1],u=h[s+r]}}}while((e=_[e&d])>l&&0!=--n);return r<=t.lookahead?r:t.lookahead},pt=t=>{const e=t.w_size;let a,i,n;do{if(i=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-262)&&(t.window.set(t.window.subarray(e,e+e-i),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,t.insert>t.strstart&&(t.insert=t.strstart),_t(t),i+=e),0===t.strm.avail_in)break;if(a=bt(t.strm,t.window,t.strstart+t.lookahead,i),t.lookahead+=a,t.lookahead+t.insert>=3)for(n=t.strstart-t.insert,t.ins_h=t.window[n],t.ins_h=ft(t,t.ins_h,t.window[n+1]);t.insert&&(t.ins_h=ft(t,t.ins_h,t.window[n+3-1]),t.prev[n&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=n,n++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead<262&&0!==t.strm.avail_in)},kt=(t,e)=>{let a,i,n,s=t.pending_buf_size-5>t.w_size?t.w_size:t.pending_buf_size-5,r=0,o=t.strm.avail_in;do{if(a=65535,n=t.bi_valid+42>>3,t.strm.avail_out<n)break;if(n=t.strm.avail_out-n,i=t.strstart-t.block_start,a>i+t.strm.avail_in&&(a=i+t.strm.avail_in),a>n&&(a=n),a<s&&(0===a&&e!==X||e===P||a!==i+t.strm.avail_in))break;r=e===X&&a===i+t.strm.avail_in?1:0,H(t,0,0,r),t.pending_buf[t.pending-4]=a,t.pending_buf[t.pending-3]=a>>8,t.pending_buf[t.pending-2]=~a,t.pending_buf[t.pending-1]=~a>>8,ct(t.strm),i&&(i>a&&(i=a),t.strm.output.set(t.window.subarray(t.block_start,t.block_start+i),t.strm.next_out),t.strm.next_out+=i,t.strm.avail_out-=i,t.strm.total_out+=i,t.block_start+=i,a-=i),a&&(bt(t.strm,t.strm.output,t.strm.next_out,a),t.strm.next_out+=a,t.strm.avail_out-=a,t.strm.total_out+=a)}while(0===r);return o-=t.strm.avail_in,o&&(o>=t.w_size?(t.matches=2,t.window.set(t.strm.input.subarray(t.strm.next_in-t.w_size,t.strm.next_in),0),t.strstart=t.w_size,t.insert=t.strstart):(t.window_size-t.strstart<=o&&(t.strstart-=t.w_size,t.window.set(t.window.subarray(t.w_size,t.w_size+t.strstart),0),t.matches<2&&t.matches++,t.insert>t.strstart&&(t.insert=t.strstart)),t.window.set(t.strm.input.subarray(t.strm.next_in-o,t.strm.next_in),t.strstart),t.strstart+=o,t.insert+=o>t.w_size-t.insert?t.w_size-t.insert:o),t.block_start=t.strstart),t.high_water<t.strstart&&(t.high_water=t.strstart),r?4:e!==P&&e!==X&&0===t.strm.avail_in&&t.strstart===t.block_start?2:(n=t.window_size-t.strstart,t.strm.avail_in>n&&t.block_start>=t.w_size&&(t.block_start-=t.w_size,t.strstart-=t.w_size,t.window.set(t.window.subarray(t.w_size,t.w_size+t.strstart),0),t.matches<2&&t.matches++,n+=t.w_size,t.insert>t.strstart&&(t.insert=t.strstart)),n>t.strm.avail_in&&(n=t.strm.avail_in),n&&(bt(t.strm,t.window,t.strstart,n),t.strstart+=n,t.insert+=n>t.w_size-t.insert?t.w_size-t.insert:n),t.high_water<t.strstart&&(t.high_water=t.strstart),n=t.bi_valid+42>>3,n=t.pending_buf_size-n>65535?65535:t.pending_buf_size-n,s=n>t.w_size?t.w_size:n,i=t.strstart-t.block_start,(i>=s||(i||e===X)&&e!==P&&0===t.strm.avail_in&&i<=n)&&(a=i>n?n:i,r=e===X&&0===t.strm.avail_in&&a===i?1:0,H(t,t.block_start,a,r),t.block_start+=a,ct(t.strm)),r?3:1)},vt=(t,e)=>{let a,i;for(;;){if(t.lookahead<262){if(pt(t),t.lookahead<262&&e===P)return 1;if(0===t.lookahead)break}if(a=0,t.lookahead>=3&&(t.ins_h=ft(t,t.ins_h,t.window[t.strstart+3-1]),a=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==a&&t.strstart-a<=t.w_size-262&&(t.match_length=gt(t,a)),t.match_length>=3)if(i=j(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=ft(t,t.ins_h,t.window[t.strstart+3-1]),a=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=ft(t,t.ins_h,t.window[t.strstart+1]);else i=j(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(i&&(ut(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===X?(ut(t,!0),0===t.strm.avail_out?3:4):t.sym_next&&(ut(t,!1),0===t.strm.avail_out)?1:2},yt=(t,e)=>{let a,i,n;for(;;){if(t.lookahead<262){if(pt(t),t.lookahead<262&&e===P)return 1;if(0===t.lookahead)break}if(a=0,t.lookahead>=3&&(t.ins_h=ft(t,t.ins_h,t.window[t.strstart+3-1]),a=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==a&&t.prev_length<t.max_lazy_match&&t.strstart-a<=t.w_size-262&&(t.match_length=gt(t,a),t.match_length<=5&&(t.strategy===et||3===t.match_length&&t.strstart-t.match_start>4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){n=t.strstart+t.lookahead-3,i=j(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=n&&(t.ins_h=ft(t,t.ins_h,t.window[t.strstart+3-1]),a=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,i&&(ut(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if(i=j(t,0,t.window[t.strstart-1]),i&&ut(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(i=j(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===X?(ut(t,!0),0===t.strm.avail_out?3:4):t.sym_next&&(ut(t,!1),0===t.strm.avail_out)?1:2};function xt(t,e,a,i,n){this.good_length=t,this.max_lazy=e,this.nice_length=a,this.max_chain=i,this.func=n}const zt=[new xt(0,0,0,0,kt),new xt(4,4,8,4,vt),new xt(4,5,16,8,vt),new xt(4,6,32,32,vt),new xt(4,4,16,16,yt),new xt(8,16,32,32,yt),new xt(8,16,128,128,yt),new xt(8,32,128,256,yt),new xt(32,128,258,1024,yt),new xt(32,258,258,4096,yt)];function At(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=ot,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),dt(this.dyn_ltree),dt(this.dyn_dtree),dt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),dt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),dt(this.depth),this.sym_buf=0,this.lit_bufsize=0,this.sym_next=0,this.sym_end=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const Et=t=>{if(!t)return 1;const e=t.state;return!e||e.strm!==t||42!==e.status&&57!==e.status&&69!==e.status&&73!==e.status&&91!==e.status&&103!==e.status&&113!==e.status&&666!==e.status?1:0},Rt=t=>{if(Et(t))return lt(t,Q);t.total_in=t.total_out=0,t.data_type=rt;const e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=2===e.wrap?57:e.wrap?42:113,t.adler=2===e.wrap?0:1,e.last_flush=-2,C(e),W},Zt=t=>{const e=Rt(t);var a;return e===W&&((a=t.state).window_size=2*a.w_size,dt(a.head),a.max_lazy_match=zt[a.level].max_lazy,a.good_match=zt[a.level].good_length,a.nice_match=zt[a.level].nice_length,a.max_chain_length=zt[a.level].max_chain,a.strstart=0,a.block_start=0,a.lookahead=0,a.insert=0,a.match_length=a.prev_length=2,a.match_available=0,a.ins_h=0),e},St=(t,e,a,i,n,s)=>{if(!t)return Q;let r=1;if(e===tt&&(e=6),i<0?(r=0,i=-i):i>15&&(r=2,i-=16),n<1||n>9||a!==ot||i<8||i>15||e<0||e>9||s<0||s>nt||8===i&&1!==r)return lt(t,Q);8===i&&(i=9);const o=new At;return t.state=o,o.strm=t,o.status=42,o.wrap=r,o.gzhead=null,o.w_bits=i,o.w_size=1<<o.w_bits,o.w_mask=o.w_size-1,o.hash_bits=n+7,o.hash_size=1<<o.hash_bits,o.hash_mask=o.hash_size-1,o.hash_shift=~~((o.hash_bits+3-1)/3),o.window=new Uint8Array(2*o.w_size),o.head=new Uint16Array(o.hash_size),o.prev=new Uint16Array(o.w_size),o.lit_bufsize=1<<n+6,o.pending_buf_size=4*o.lit_bufsize,o.pending_buf=new Uint8Array(o.pending_buf_size),o.sym_buf=o.lit_bufsize,o.sym_end=3*(o.lit_bufsize-1),o.level=e,o.strategy=s,o.method=a,Zt(t)};var Ut={deflateInit:(t,e)=>St(t,e,ot,15,8,st),deflateInit2:St,deflateReset:Zt,deflateResetKeep:Rt,deflateSetHeader:(t,e)=>Et(t)||2!==t.state.wrap?Q:(t.state.gzhead=e,W),deflate:(t,e)=>{if(Et(t)||e>J||e<0)return t?lt(t,Q):Q;const a=t.state;if(!t.output||0!==t.avail_in&&!t.input||666===a.status&&e!==X)return lt(t,0===t.avail_out?$:Q);const i=a.last_flush;if(a.last_flush=e,0!==a.pending){if(ct(t),0===t.avail_out)return a.last_flush=-1,W}else if(0===t.avail_in&&ht(e)<=ht(i)&&e!==X)return lt(t,$);if(666===a.status&&0!==t.avail_in)return lt(t,$);if(42===a.status&&0===a.wrap&&(a.status=113),42===a.status){let e=ot+(a.w_bits-8<<4)<<8,i=-1;if(i=a.strategy>=at||a.level<2?0:a.level<6?1:6===a.level?2:3,e|=i<<6,0!==a.strstart&&(e|=32),e+=31-e%31,mt(a,e),0!==a.strstart&&(mt(a,t.adler>>>16),mt(a,65535&t.adler)),t.adler=1,a.status=113,ct(t),0!==a.pending)return a.last_flush=-1,W}if(57===a.status)if(t.adler=0,wt(a,31),wt(a,139),wt(a,8),a.gzhead)wt(a,(a.gzhead.text?1:0)+(a.gzhead.hcrc?2:0)+(a.gzhead.extra?4:0)+(a.gzhead.name?8:0)+(a.gzhead.comment?16:0)),wt(a,255&a.gzhead.time),wt(a,a.gzhead.time>>8&255),wt(a,a.gzhead.time>>16&255),wt(a,a.gzhead.time>>24&255),wt(a,9===a.level?2:a.strategy>=at||a.level<2?4:0),wt(a,255&a.gzhead.os),a.gzhead.extra&&a.gzhead.extra.length&&(wt(a,255&a.gzhead.extra.length),wt(a,a.gzhead.extra.length>>8&255)),a.gzhead.hcrc&&(t.adler=L(t.adler,a.pending_buf,a.pending,0)),a.gzindex=0,a.status=69;else if(wt(a,0),wt(a,0),wt(a,0),wt(a,0),wt(a,0),wt(a,9===a.level?2:a.strategy>=at||a.level<2?4:0),wt(a,3),a.status=113,ct(t),0!==a.pending)return a.last_flush=-1,W;if(69===a.status){if(a.gzhead.extra){let e=a.pending,i=(65535&a.gzhead.extra.length)-a.gzindex;for(;a.pending+i>a.pending_buf_size;){let n=a.pending_buf_size-a.pending;if(a.pending_buf.set(a.gzhead.extra.subarray(a.gzindex,a.gzindex+n),a.pending),a.pending=a.pending_buf_size,a.gzhead.hcrc&&a.pending>e&&(t.adler=L(t.adler,a.pending_buf,a.pending-e,e)),a.gzindex+=n,ct(t),0!==a.pending)return a.last_flush=-1,W;e=0,i-=n}let n=new Uint8Array(a.gzhead.extra);a.pending_buf.set(n.subarray(a.gzindex,a.gzindex+i),a.pending),a.pending+=i,a.gzhead.hcrc&&a.pending>e&&(t.adler=L(t.adler,a.pending_buf,a.pending-e,e)),a.gzindex=0}a.status=73}if(73===a.status){if(a.gzhead.name){let e,i=a.pending;do{if(a.pending===a.pending_buf_size){if(a.gzhead.hcrc&&a.pending>i&&(t.adler=L(t.adler,a.pending_buf,a.pending-i,i)),ct(t),0!==a.pending)return a.last_flush=-1,W;i=0}e=a.gzindex<a.gzhead.name.length?255&a.gzhead.name.charCodeAt(a.gzindex++):0,wt(a,e)}while(0!==e);a.gzhead.hcrc&&a.pending>i&&(t.adler=L(t.adler,a.pending_buf,a.pending-i,i)),a.gzindex=0}a.status=91}if(91===a.status){if(a.gzhead.comment){let e,i=a.pending;do{if(a.pending===a.pending_buf_size){if(a.gzhead.hcrc&&a.pending>i&&(t.adler=L(t.adler,a.pending_buf,a.pending-i,i)),ct(t),0!==a.pending)return a.last_flush=-1,W;i=0}e=a.gzindex<a.gzhead.comment.length?255&a.gzhead.comment.charCodeAt(a.gzindex++):0,wt(a,e)}while(0!==e);a.gzhead.hcrc&&a.pending>i&&(t.adler=L(t.adler,a.pending_buf,a.pending-i,i))}a.status=103}if(103===a.status){if(a.gzhead.hcrc){if(a.pending+2>a.pending_buf_size&&(ct(t),0!==a.pending))return a.last_flush=-1,W;wt(a,255&t.adler),wt(a,t.adler>>8&255),t.adler=0}if(a.status=113,ct(t),0!==a.pending)return a.last_flush=-1,W}if(0!==t.avail_in||0!==a.lookahead||e!==P&&666!==a.status){let i=0===a.level?kt(a,e):a.strategy===at?((t,e)=>{let a;for(;;){if(0===t.lookahead&&(pt(t),0===t.lookahead)){if(e===P)return 1;break}if(t.match_length=0,a=j(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,a&&(ut(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===X?(ut(t,!0),0===t.strm.avail_out?3:4):t.sym_next&&(ut(t,!1),0===t.strm.avail_out)?1:2})(a,e):a.strategy===it?((t,e)=>{let a,i,n,s;const r=t.window;for(;;){if(t.lookahead<=258){if(pt(t),t.lookahead<=258&&e===P)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&(n=t.strstart-1,i=r[n],i===r[++n]&&i===r[++n]&&i===r[++n])){s=t.strstart+258;do{}while(i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&n<s);t.match_length=258-(s-n),t.match_length>t.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(a=j(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(a=j(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),a&&(ut(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===X?(ut(t,!0),0===t.strm.avail_out?3:4):t.sym_next&&(ut(t,!1),0===t.strm.avail_out)?1:2})(a,e):zt[a.level].func(a,e);if(3!==i&&4!==i||(a.status=666),1===i||3===i)return 0===t.avail_out&&(a.last_flush=-1),W;if(2===i&&(e===Y?K(a):e!==J&&(H(a,0,0,!1),e===G&&(dt(a.head),0===a.lookahead&&(a.strstart=0,a.block_start=0,a.insert=0))),ct(t),0===t.avail_out))return a.last_flush=-1,W}return e!==X?W:a.wrap<=0?q:(2===a.wrap?(wt(a,255&t.adler),wt(a,t.adler>>8&255),wt(a,t.adler>>16&255),wt(a,t.adler>>24&255),wt(a,255&t.total_in),wt(a,t.total_in>>8&255),wt(a,t.total_in>>16&255),wt(a,t.total_in>>24&255)):(mt(a,t.adler>>>16),mt(a,65535&t.adler)),ct(t),a.wrap>0&&(a.wrap=-a.wrap),0!==a.pending?W:q)},deflateEnd:t=>{if(Et(t))return Q;const e=t.state.status;return t.state=null,113===e?lt(t,V):W},deflateSetDictionary:(t,e)=>{let a=e.length;if(Et(t))return Q;const i=t.state,n=i.wrap;if(2===n||1===n&&42!==i.status||i.lookahead)return Q;if(1===n&&(t.adler=N(t.adler,e,a,0)),i.wrap=0,a>=i.w_size){0===n&&(dt(i.head),i.strstart=0,i.block_start=0,i.insert=0);let t=new Uint8Array(i.w_size);t.set(e.subarray(a-i.w_size,a),0),e=t,a=i.w_size}const s=t.avail_in,r=t.next_in,o=t.input;for(t.avail_in=a,t.next_in=0,t.input=e,pt(i);i.lookahead>=3;){let t=i.strstart,e=i.lookahead-2;do{i.ins_h=ft(i,i.ins_h,i.window[t+3-1]),i.prev[t&i.w_mask]=i.head[i.ins_h],i.head[i.ins_h]=t,t++}while(--e);i.strstart=t,i.lookahead=2,pt(i)}return i.strstart+=i.lookahead,i.block_start=i.strstart,i.insert=i.lookahead,i.lookahead=0,i.match_length=i.prev_length=2,i.match_available=0,t.next_in=r,t.input=o,t.avail_in=s,i.wrap=n,W},deflateInfo:"pako deflate (from Nodeca project)"};const Dt=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var Ot=function(t){const e=Array.prototype.slice.call(arguments,1);for(;e.length;){const a=e.shift();if(a){if("object"!=typeof a)throw new TypeError(a+"must be non-object");for(const e in a)Dt(a,e)&&(t[e]=a[e])}}return t},Tt=t=>{let e=0;for(let a=0,i=t.length;a<i;a++)e+=t[a].length;const a=new Uint8Array(e);for(let e=0,i=0,n=t.length;e<n;e++){let n=t[e];a.set(n,i),i+=n.length}return a};let Nt=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(t){Nt=!1}const Ft=new Uint8Array(256);for(let t=0;t<256;t++)Ft[t]=t>=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;Ft[254]=Ft[254]=1;var Lt=t=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);let e,a,i,n,s,r=t.length,o=0;for(n=0;n<r;n++)a=t.charCodeAt(n),55296==(64512&a)&&n+1<r&&(i=t.charCodeAt(n+1),56320==(64512&i)&&(a=65536+(a-55296<<10)+(i-56320),n++)),o+=a<128?1:a<2048?2:a<65536?3:4;for(e=new Uint8Array(o),s=0,n=0;s<o;n++)a=t.charCodeAt(n),55296==(64512&a)&&n+1<r&&(i=t.charCodeAt(n+1),56320==(64512&i)&&(a=65536+(a-55296<<10)+(i-56320),n++)),a<128?e[s++]=a:a<2048?(e[s++]=192|a>>>6,e[s++]=128|63&a):a<65536?(e[s++]=224|a>>>12,e[s++]=128|a>>>6&63,e[s++]=128|63&a):(e[s++]=240|a>>>18,e[s++]=128|a>>>12&63,e[s++]=128|a>>>6&63,e[s++]=128|63&a);return e},It=(t,e)=>{const a=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));let i,n;const s=new Array(2*a);for(n=0,i=0;i<a;){let e=t[i++];if(e<128){s[n++]=e;continue}let r=Ft[e];if(r>4)s[n++]=65533,i+=r-1;else{for(e&=2===r?31:3===r?15:7;r>1&&i<a;)e=e<<6|63&t[i++],r--;r>1?s[n++]=65533:e<65536?s[n++]=e:(e-=65536,s[n++]=55296|e>>10&1023,s[n++]=56320|1023&e)}}return((t,e)=>{if(e<65534&&t.subarray&&Nt)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let a="";for(let i=0;i<e;i++)a+=String.fromCharCode(t[i]);return a})(s,n)},Bt=(t,e)=>{(e=e||t.length)>t.length&&(e=t.length);let a=e-1;for(;a>=0&&128==(192&t[a]);)a--;return a<0||0===a?e:a+Ft[t[a]]>e?a:e};var Ct=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};const Ht=Object.prototype.toString,{Z_NO_FLUSH:Mt,Z_SYNC_FLUSH:jt,Z_FULL_FLUSH:Kt,Z_FINISH:Pt,Z_OK:Yt,Z_STREAM_END:Gt,Z_DEFAULT_COMPRESSION:Xt,Z_DEFAULT_STRATEGY:Jt,Z_DEFLATED:Wt}=B;function qt(t){this.options=Ot({level:Xt,method:Wt,chunkSize:16384,windowBits:15,memLevel:8,strategy:Jt},t||{});let e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Ct,this.strm.avail_out=0;let a=Ut.deflateInit2(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(a!==Yt)throw new Error(I[a]);if(e.header&&Ut.deflateSetHeader(this.strm,e.header),e.dictionary){let t;if(t="string"==typeof e.dictionary?Lt(e.dictionary):"[object ArrayBuffer]"===Ht.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,a=Ut.deflateSetDictionary(this.strm,t),a!==Yt)throw new Error(I[a]);this._dict_set=!0}}function Qt(t,e){const a=new qt(e);if(a.push(t,!0),a.err)throw a.msg||I[a.err];return a.result}qt.prototype.push=function(t,e){const a=this.strm,i=this.options.chunkSize;let n,s;if(this.ended)return!1;for(s=e===~~e?e:!0===e?Pt:Mt,"string"==typeof t?a.input=Lt(t):"[object ArrayBuffer]"===Ht.call(t)?a.input=new Uint8Array(t):a.input=t,a.next_in=0,a.avail_in=a.input.length;;)if(0===a.avail_out&&(a.output=new Uint8Array(i),a.next_out=0,a.avail_out=i),(s===jt||s===Kt)&&a.avail_out<=6)this.onData(a.output.subarray(0,a.next_out)),a.avail_out=0;else{if(n=Ut.deflate(a,s),n===Gt)return a.next_out>0&&this.onData(a.output.subarray(0,a.next_out)),n=Ut.deflateEnd(this.strm),this.onEnd(n),this.ended=!0,n===Yt;if(0!==a.avail_out){if(s>0&&a.next_out>0)this.onData(a.output.subarray(0,a.next_out)),a.avail_out=0;else if(0===a.avail_in)break}else this.onData(a.output)}return!0},qt.prototype.onData=function(t){this.chunks.push(t)},qt.prototype.onEnd=function(t){t===Yt&&(this.result=Tt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var Vt={Deflate:qt,deflate:Qt,deflateRaw:function(t,e){return(e=e||{}).raw=!0,Qt(t,e)},gzip:function(t,e){return(e=e||{}).gzip=!0,Qt(t,e)},constants:B};var $t=function(t,e){let a,i,n,s,r,o,l,h,d,_,f,c,u,w,m,b,g,p,k,v,y,x,z,A;const E=t.state;a=t.next_in,z=t.input,i=a+(t.avail_in-5),n=t.next_out,A=t.output,s=n-(e-t.avail_out),r=n+(t.avail_out-257),o=E.dmax,l=E.wsize,h=E.whave,d=E.wnext,_=E.window,f=E.hold,c=E.bits,u=E.lencode,w=E.distcode,m=(1<<E.lenbits)-1,b=(1<<E.distbits)-1;t:do{c<15&&(f+=z[a++]<<c,c+=8,f+=z[a++]<<c,c+=8),g=u[f&m];e:for(;;){if(p=g>>>24,f>>>=p,c-=p,p=g>>>16&255,0===p)A[n++]=65535&g;else{if(!(16&p)){if(0==(64&p)){g=u[(65535&g)+(f&(1<<p)-1)];continue e}if(32&p){E.mode=16191;break t}t.msg="invalid literal/length code",E.mode=16209;break t}k=65535&g,p&=15,p&&(c<p&&(f+=z[a++]<<c,c+=8),k+=f&(1<<p)-1,f>>>=p,c-=p),c<15&&(f+=z[a++]<<c,c+=8,f+=z[a++]<<c,c+=8),g=w[f&b];a:for(;;){if(p=g>>>24,f>>>=p,c-=p,p=g>>>16&255,!(16&p)){if(0==(64&p)){g=w[(65535&g)+(f&(1<<p)-1)];continue a}t.msg="invalid distance code",E.mode=16209;break t}if(v=65535&g,p&=15,c<p&&(f+=z[a++]<<c,c+=8,c<p&&(f+=z[a++]<<c,c+=8)),v+=f&(1<<p)-1,v>o){t.msg="invalid distance too far back",E.mode=16209;break t}if(f>>>=p,c-=p,p=n-s,v>p){if(p=v-p,p>h&&E.sane){t.msg="invalid distance too far back",E.mode=16209;break t}if(y=0,x=_,0===d){if(y+=l-p,p<k){k-=p;do{A[n++]=_[y++]}while(--p);y=n-v,x=A}}else if(d<p){if(y+=l+d-p,p-=d,p<k){k-=p;do{A[n++]=_[y++]}while(--p);if(y=0,d<k){p=d,k-=p;do{A[n++]=_[y++]}while(--p);y=n-v,x=A}}}else if(y+=d-p,p<k){k-=p;do{A[n++]=_[y++]}while(--p);y=n-v,x=A}for(;k>2;)A[n++]=x[y++],A[n++]=x[y++],A[n++]=x[y++],k-=3;k&&(A[n++]=x[y++],k>1&&(A[n++]=x[y++]))}else{y=n-v;do{A[n++]=A[y++],A[n++]=A[y++],A[n++]=A[y++],k-=3}while(k>2);k&&(A[n++]=A[y++],k>1&&(A[n++]=A[y++]))}break}}break}}while(a<i&&n<r);k=c>>3,a-=k,c-=k<<3,f&=(1<<c)-1,t.next_in=a,t.next_out=n,t.avail_in=a<i?i-a+5:5-(a-i),t.avail_out=n<r?r-n+257:257-(n-r),E.hold=f,E.bits=c};const te=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),ee=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),ae=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),ie=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]);var ne=(t,e,a,i,n,s,r,o)=>{const l=o.bits;let h,d,_,f,c,u,w=0,m=0,b=0,g=0,p=0,k=0,v=0,y=0,x=0,z=0,A=null;const E=new Uint16Array(16),R=new Uint16Array(16);let Z,S,U,D=null;for(w=0;w<=15;w++)E[w]=0;for(m=0;m<i;m++)E[e[a+m]]++;for(p=l,g=15;g>=1&&0===E[g];g--);if(p>g&&(p=g),0===g)return n[s++]=20971520,n[s++]=20971520,o.bits=1,0;for(b=1;b<g&&0===E[b];b++);for(p<b&&(p=b),y=1,w=1;w<=15;w++)if(y<<=1,y-=E[w],y<0)return-1;if(y>0&&(0===t||1!==g))return-1;for(R[1]=0,w=1;w<15;w++)R[w+1]=R[w]+E[w];for(m=0;m<i;m++)0!==e[a+m]&&(r[R[e[a+m]]++]=m);if(0===t?(A=D=r,u=20):1===t?(A=te,D=ee,u=257):(A=ae,D=ie,u=0),z=0,m=0,w=b,c=s,k=p,v=0,_=-1,x=1<<p,f=x-1,1===t&&x>852||2===t&&x>592)return 1;for(;;){Z=w-v,r[m]+1<u?(S=0,U=r[m]):r[m]>=u?(S=D[r[m]-u],U=A[r[m]-u]):(S=96,U=0),h=1<<w-v,d=1<<k,b=d;do{d-=h,n[c+(z>>v)+d]=Z<<24|S<<16|U|0}while(0!==d);for(h=1<<w-1;z&h;)h>>=1;if(0!==h?(z&=h-1,z+=h):z=0,m++,0==--E[w]){if(w===g)break;w=e[a+r[m]]}if(w>p&&(z&f)!==_){for(0===v&&(v=p),c+=b,k=w-v,y=1<<k;k+v<g&&(y-=E[k+v],!(y<=0));)k++,y<<=1;if(x+=1<<k,1===t&&x>852||2===t&&x>592)return 1;_=z&f,n[_]=p<<24|k<<16|c-s|0}}return 0!==z&&(n[c+z]=w-v<<24|64<<16|0),o.bits=p,0};const{Z_FINISH:se,Z_BLOCK:re,Z_TREES:oe,Z_OK:le,Z_STREAM_END:he,Z_NEED_DICT:de,Z_STREAM_ERROR:_e,Z_DATA_ERROR:fe,Z_MEM_ERROR:ce,Z_BUF_ERROR:ue,Z_DEFLATED:we}=B,me=16209,be=t=>(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24);function ge(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const pe=t=>{if(!t)return 1;const e=t.state;return!e||e.strm!==t||e.mode<16180||e.mode>16211?1:0},ke=t=>{if(pe(t))return _e;const e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=16180,e.last=0,e.havedict=0,e.flags=-1,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,le},ve=t=>{if(pe(t))return _e;const e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,ke(t)},ye=(t,e)=>{let a;if(pe(t))return _e;const i=t.state;return e<0?(a=0,e=-e):(a=5+(e>>4),e<48&&(e&=15)),e&&(e<8||e>15)?_e:(null!==i.window&&i.wbits!==e&&(i.window=null),i.wrap=a,i.wbits=e,ve(t))},xe=(t,e)=>{if(!t)return _e;const a=new ge;t.state=a,a.strm=t,a.window=null,a.mode=16180;const i=ye(t,e);return i!==le&&(t.state=null),i};let ze,Ae,Ee=!0;const Re=t=>{if(Ee){ze=new Int32Array(512),Ae=new Int32Array(32);let e=0;for(;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(ne(1,t.lens,0,288,ze,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;ne(2,t.lens,0,32,Ae,0,t.work,{bits:5}),Ee=!1}t.lencode=ze,t.lenbits=9,t.distcode=Ae,t.distbits=5},Ze=(t,e,a,i)=>{let n;const s=t.state;return null===s.window&&(s.wsize=1<<s.wbits,s.wnext=0,s.whave=0,s.window=new Uint8Array(s.wsize)),i>=s.wsize?(s.window.set(e.subarray(a-s.wsize,a),0),s.wnext=0,s.whave=s.wsize):(n=s.wsize-s.wnext,n>i&&(n=i),s.window.set(e.subarray(a-i,a-i+n),s.wnext),(i-=n)?(s.window.set(e.subarray(a-i,a),0),s.wnext=i,s.whave=s.wsize):(s.wnext+=n,s.wnext===s.wsize&&(s.wnext=0),s.whave<s.wsize&&(s.whave+=n))),0};var Se={inflateReset:ve,inflateReset2:ye,inflateResetKeep:ke,inflateInit:t=>xe(t,15),inflateInit2:xe,inflate:(t,e)=>{let a,i,n,s,r,o,l,h,d,_,f,c,u,w,m,b,g,p,k,v,y,x,z=0;const A=new Uint8Array(4);let E,R;const Z=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(pe(t)||!t.output||!t.input&&0!==t.avail_in)return _e;a=t.state,16191===a.mode&&(a.mode=16192),r=t.next_out,n=t.output,l=t.avail_out,s=t.next_in,i=t.input,o=t.avail_in,h=a.hold,d=a.bits,_=o,f=l,x=le;t:for(;;)switch(a.mode){case 16180:if(0===a.wrap){a.mode=16192;break}for(;d<16;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}if(2&a.wrap&&35615===h){0===a.wbits&&(a.wbits=15),a.check=0,A[0]=255&h,A[1]=h>>>8&255,a.check=L(a.check,A,2,0),h=0,d=0,a.mode=16181;break}if(a.head&&(a.head.done=!1),!(1&a.wrap)||(((255&h)<<8)+(h>>8))%31){t.msg="incorrect header check",a.mode=me;break}if((15&h)!==we){t.msg="unknown compression method",a.mode=me;break}if(h>>>=4,d-=4,y=8+(15&h),0===a.wbits&&(a.wbits=y),y>15||y>a.wbits){t.msg="invalid window size",a.mode=me;break}a.dmax=1<<a.wbits,a.flags=0,t.adler=a.check=1,a.mode=512&h?16189:16191,h=0,d=0;break;case 16181:for(;d<16;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}if(a.flags=h,(255&a.flags)!==we){t.msg="unknown compression method",a.mode=me;break}if(57344&a.flags){t.msg="unknown header flags set",a.mode=me;break}a.head&&(a.head.text=h>>8&1),512&a.flags&&4&a.wrap&&(A[0]=255&h,A[1]=h>>>8&255,a.check=L(a.check,A,2,0)),h=0,d=0,a.mode=16182;case 16182:for(;d<32;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}a.head&&(a.head.time=h),512&a.flags&&4&a.wrap&&(A[0]=255&h,A[1]=h>>>8&255,A[2]=h>>>16&255,A[3]=h>>>24&255,a.check=L(a.check,A,4,0)),h=0,d=0,a.mode=16183;case 16183:for(;d<16;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}a.head&&(a.head.xflags=255&h,a.head.os=h>>8),512&a.flags&&4&a.wrap&&(A[0]=255&h,A[1]=h>>>8&255,a.check=L(a.check,A,2,0)),h=0,d=0,a.mode=16184;case 16184:if(1024&a.flags){for(;d<16;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}a.length=h,a.head&&(a.head.extra_len=h),512&a.flags&&4&a.wrap&&(A[0]=255&h,A[1]=h>>>8&255,a.check=L(a.check,A,2,0)),h=0,d=0}else a.head&&(a.head.extra=null);a.mode=16185;case 16185:if(1024&a.flags&&(c=a.length,c>o&&(c=o),c&&(a.head&&(y=a.head.extra_len-a.length,a.head.extra||(a.head.extra=new Uint8Array(a.head.extra_len)),a.head.extra.set(i.subarray(s,s+c),y)),512&a.flags&&4&a.wrap&&(a.check=L(a.check,i,c,s)),o-=c,s+=c,a.length-=c),a.length))break t;a.length=0,a.mode=16186;case 16186:if(2048&a.flags){if(0===o)break t;c=0;do{y=i[s+c++],a.head&&y&&a.length<65536&&(a.head.name+=String.fromCharCode(y))}while(y&&c<o);if(512&a.flags&&4&a.wrap&&(a.check=L(a.check,i,c,s)),o-=c,s+=c,y)break t}else a.head&&(a.head.name=null);a.length=0,a.mode=16187;case 16187:if(4096&a.flags){if(0===o)break t;c=0;do{y=i[s+c++],a.head&&y&&a.length<65536&&(a.head.comment+=String.fromCharCode(y))}while(y&&c<o);if(512&a.flags&&4&a.wrap&&(a.check=L(a.check,i,c,s)),o-=c,s+=c,y)break t}else a.head&&(a.head.comment=null);a.mode=16188;case 16188:if(512&a.flags){for(;d<16;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}if(4&a.wrap&&h!==(65535&a.check)){t.msg="header crc mismatch",a.mode=me;break}h=0,d=0}a.head&&(a.head.hcrc=a.flags>>9&1,a.head.done=!0),t.adler=a.check=0,a.mode=16191;break;case 16189:for(;d<32;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}t.adler=a.check=be(h),h=0,d=0,a.mode=16190;case 16190:if(0===a.havedict)return t.next_out=r,t.avail_out=l,t.next_in=s,t.avail_in=o,a.hold=h,a.bits=d,de;t.adler=a.check=1,a.mode=16191;case 16191:if(e===re||e===oe)break t;case 16192:if(a.last){h>>>=7&d,d-=7&d,a.mode=16206;break}for(;d<3;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}switch(a.last=1&h,h>>>=1,d-=1,3&h){case 0:a.mode=16193;break;case 1:if(Re(a),a.mode=16199,e===oe){h>>>=2,d-=2;break t}break;case 2:a.mode=16196;break;case 3:t.msg="invalid block type",a.mode=me}h>>>=2,d-=2;break;case 16193:for(h>>>=7&d,d-=7&d;d<32;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}if((65535&h)!=(h>>>16^65535)){t.msg="invalid stored block lengths",a.mode=me;break}if(a.length=65535&h,h=0,d=0,a.mode=16194,e===oe)break t;case 16194:a.mode=16195;case 16195:if(c=a.length,c){if(c>o&&(c=o),c>l&&(c=l),0===c)break t;n.set(i.subarray(s,s+c),r),o-=c,s+=c,l-=c,r+=c,a.length-=c;break}a.mode=16191;break;case 16196:for(;d<14;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}if(a.nlen=257+(31&h),h>>>=5,d-=5,a.ndist=1+(31&h),h>>>=5,d-=5,a.ncode=4+(15&h),h>>>=4,d-=4,a.nlen>286||a.ndist>30){t.msg="too many length or distance symbols",a.mode=me;break}a.have=0,a.mode=16197;case 16197:for(;a.have<a.ncode;){for(;d<3;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}a.lens[Z[a.have++]]=7&h,h>>>=3,d-=3}for(;a.have<19;)a.lens[Z[a.have++]]=0;if(a.lencode=a.lendyn,a.lenbits=7,E={bits:a.lenbits},x=ne(0,a.lens,0,19,a.lencode,0,a.work,E),a.lenbits=E.bits,x){t.msg="invalid code lengths set",a.mode=me;break}a.have=0,a.mode=16198;case 16198:for(;a.have<a.nlen+a.ndist;){for(;z=a.lencode[h&(1<<a.lenbits)-1],m=z>>>24,b=z>>>16&255,g=65535&z,!(m<=d);){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}if(g<16)h>>>=m,d-=m,a.lens[a.have++]=g;else{if(16===g){for(R=m+2;d<R;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}if(h>>>=m,d-=m,0===a.have){t.msg="invalid bit length repeat",a.mode=me;break}y=a.lens[a.have-1],c=3+(3&h),h>>>=2,d-=2}else if(17===g){for(R=m+3;d<R;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}h>>>=m,d-=m,y=0,c=3+(7&h),h>>>=3,d-=3}else{for(R=m+7;d<R;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}h>>>=m,d-=m,y=0,c=11+(127&h),h>>>=7,d-=7}if(a.have+c>a.nlen+a.ndist){t.msg="invalid bit length repeat",a.mode=me;break}for(;c--;)a.lens[a.have++]=y}}if(a.mode===me)break;if(0===a.lens[256]){t.msg="invalid code -- missing end-of-block",a.mode=me;break}if(a.lenbits=9,E={bits:a.lenbits},x=ne(1,a.lens,0,a.nlen,a.lencode,0,a.work,E),a.lenbits=E.bits,x){t.msg="invalid literal/lengths set",a.mode=me;break}if(a.distbits=6,a.distcode=a.distdyn,E={bits:a.distbits},x=ne(2,a.lens,a.nlen,a.ndist,a.distcode,0,a.work,E),a.distbits=E.bits,x){t.msg="invalid distances set",a.mode=me;break}if(a.mode=16199,e===oe)break t;case 16199:a.mode=16200;case 16200:if(o>=6&&l>=258){t.next_out=r,t.avail_out=l,t.next_in=s,t.avail_in=o,a.hold=h,a.bits=d,$t(t,f),r=t.next_out,n=t.output,l=t.avail_out,s=t.next_in,i=t.input,o=t.avail_in,h=a.hold,d=a.bits,16191===a.mode&&(a.back=-1);break}for(a.back=0;z=a.lencode[h&(1<<a.lenbits)-1],m=z>>>24,b=z>>>16&255,g=65535&z,!(m<=d);){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}if(b&&0==(240&b)){for(p=m,k=b,v=g;z=a.lencode[v+((h&(1<<p+k)-1)>>p)],m=z>>>24,b=z>>>16&255,g=65535&z,!(p+m<=d);){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}h>>>=p,d-=p,a.back+=p}if(h>>>=m,d-=m,a.back+=m,a.length=g,0===b){a.mode=16205;break}if(32&b){a.back=-1,a.mode=16191;break}if(64&b){t.msg="invalid literal/length code",a.mode=me;break}a.extra=15&b,a.mode=16201;case 16201:if(a.extra){for(R=a.extra;d<R;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}a.length+=h&(1<<a.extra)-1,h>>>=a.extra,d-=a.extra,a.back+=a.extra}a.was=a.length,a.mode=16202;case 16202:for(;z=a.distcode[h&(1<<a.distbits)-1],m=z>>>24,b=z>>>16&255,g=65535&z,!(m<=d);){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}if(0==(240&b)){for(p=m,k=b,v=g;z=a.distcode[v+((h&(1<<p+k)-1)>>p)],m=z>>>24,b=z>>>16&255,g=65535&z,!(p+m<=d);){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}h>>>=p,d-=p,a.back+=p}if(h>>>=m,d-=m,a.back+=m,64&b){t.msg="invalid distance code",a.mode=me;break}a.offset=g,a.extra=15&b,a.mode=16203;case 16203:if(a.extra){for(R=a.extra;d<R;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}a.offset+=h&(1<<a.extra)-1,h>>>=a.extra,d-=a.extra,a.back+=a.extra}if(a.offset>a.dmax){t.msg="invalid distance too far back",a.mode=me;break}a.mode=16204;case 16204:if(0===l)break t;if(c=f-l,a.offset>c){if(c=a.offset-c,c>a.whave&&a.sane){t.msg="invalid distance too far back",a.mode=me;break}c>a.wnext?(c-=a.wnext,u=a.wsize-c):u=a.wnext-c,c>a.length&&(c=a.length),w=a.window}else w=n,u=r-a.offset,c=a.length;c>l&&(c=l),l-=c,a.length-=c;do{n[r++]=w[u++]}while(--c);0===a.length&&(a.mode=16200);break;case 16205:if(0===l)break t;n[r++]=a.length,l--,a.mode=16200;break;case 16206:if(a.wrap){for(;d<32;){if(0===o)break t;o--,h|=i[s++]<<d,d+=8}if(f-=l,t.total_out+=f,a.total+=f,4&a.wrap&&f&&(t.adler=a.check=a.flags?L(a.check,n,f,r-f):N(a.check,n,f,r-f)),f=l,4&a.wrap&&(a.flags?h:be(h))!==a.check){t.msg="incorrect data check",a.mode=me;break}h=0,d=0}a.mode=16207;case 16207:if(a.wrap&&a.flags){for(;d<32;){if(0===o)break t;o--,h+=i[s++]<<d,d+=8}if(4&a.wrap&&h!==(4294967295&a.total)){t.msg="incorrect length check",a.mode=me;break}h=0,d=0}a.mode=16208;case 16208:x=he;break t;case me:x=fe;break t;case 16210:return ce;default:return _e}return t.next_out=r,t.avail_out=l,t.next_in=s,t.avail_in=o,a.hold=h,a.bits=d,(a.wsize||f!==t.avail_out&&a.mode<me&&(a.mode<16206||e!==se))&&Ze(t,t.output,t.next_out,f-t.avail_out),_-=t.avail_in,f-=t.avail_out,t.total_in+=_,t.total_out+=f,a.total+=f,4&a.wrap&&f&&(t.adler=a.check=a.flags?L(a.check,n,f,t.next_out-f):N(a.check,n,f,t.next_out-f)),t.data_type=a.bits+(a.last?64:0)+(16191===a.mode?128:0)+(16199===a.mode||16194===a.mode?256:0),(0===_&&0===f||e===se)&&x===le&&(x=ue),x},inflateEnd:t=>{if(pe(t))return _e;let e=t.state;return e.window&&(e.window=null),t.state=null,le},inflateGetHeader:(t,e)=>{if(pe(t))return _e;const a=t.state;return 0==(2&a.wrap)?_e:(a.head=e,e.done=!1,le)},inflateSetDictionary:(t,e)=>{const a=e.length;let i,n,s;return pe(t)?_e:(i=t.state,0!==i.wrap&&16190!==i.mode?_e:16190===i.mode&&(n=1,n=N(n,e,a,0),n!==i.check)?fe:(s=Ze(t,e,a,a),s?(i.mode=16210,ce):(i.havedict=1,le)))},inflateInfo:"pako inflate (from Nodeca project)"};var Ue=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const De=Object.prototype.toString,{Z_NO_FLUSH:Oe,Z_FINISH:Te,Z_OK:Ne,Z_STREAM_END:Fe,Z_NEED_DICT:Le,Z_STREAM_ERROR:Ie,Z_DATA_ERROR:Be,Z_MEM_ERROR:Ce}=B;function He(t){this.options=Ot({chunkSize:65536,windowBits:15,to:""},t||{});const e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Ct,this.strm.avail_out=0;let a=Se.inflateInit2(this.strm,e.windowBits);if(a!==Ne)throw new Error(I[a]);if(this.header=new Ue,Se.inflateGetHeader(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=Lt(e.dictionary):"[object ArrayBuffer]"===De.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(a=Se.inflateSetDictionary(this.strm,e.dictionary),a!==Ne)))throw new Error(I[a])}He.prototype.push=function(t,e){const a=this.strm,i=this.options.chunkSize,n=this.options.dictionary;let s,r,o;if(this.ended)return!1;for(r=e===~~e?e:!0===e?Te:Oe,"[object ArrayBuffer]"===De.call(t)?a.input=new Uint8Array(t):a.input=t,a.next_in=0,a.avail_in=a.input.length;;){for(0===a.avail_out&&(a.output=new Uint8Array(i),a.next_out=0,a.avail_out=i),s=Se.inflate(a,r),s===Le&&n&&(s=Se.inflateSetDictionary(a,n),s===Ne?s=Se.inflate(a,r):s===Be&&(s=Le));a.avail_in>0&&s===Fe&&a.state.wrap>0&&0!==t[a.next_in];)Se.inflateReset(a),s=Se.inflate(a,r);switch(s){case Ie:case Be:case Le:case Ce:return this.onEnd(s),this.ended=!0,!1}if(o=a.avail_out,a.next_out&&(0===a.avail_out||s===Fe))if("string"===this.options.to){let t=Bt(a.output,a.next_out),e=a.next_out-t,n=It(a.output,t);a.next_out=e,a.avail_out=i-e,e&&a.output.set(a.output.subarray(t,t+e),0),this.onData(n)}else this.onData(a.output.length===a.next_out?a.output:a.output.subarray(0,a.next_out));if(s!==Ne||0!==o){if(s===Fe)return s=Se.inflateEnd(this.strm),this.onEnd(s),this.ended=!0,!0;if(0===a.avail_in)break}}return!0},He.prototype.onData=function(t){this.chunks.push(t)},He.prototype.onEnd=function(t){t===Ne&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Tt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};const{Deflate:Me,deflate:je,deflateRaw:Ke,gzip:Pe}=Vt;var Ye=Me,Ge=B;const Xe=new class{constructor(){this.added=0,this.init()}init(){this.added=0,this.deflate=new Ye,this.deflate.push("[",Ge.Z_NO_FLUSH)}addEvent(t){if(!t)throw new Error("Adding invalid event");const e=this.added>0?",":"";this.deflate.push(e+JSON.stringify(t),Ge.Z_SYNC_FLUSH),this.added++}finish(){if(this.deflate.push("]",Ge.Z_FINISH),this.deflate.err)throw this.deflate.err;const t=this.deflate.result;return this.init(),t}},Je={init:()=>(Xe.init(),""),addEvent:t=>Xe.addEvent(t),finish:()=>Xe.finish()};addEventListener("message",(function(t){const e=t.data.method,a=t.data.id,[i]=t.data.args?JSON.parse(t.data.args):[];if(e in Je&&"function"==typeof Je[e])try{const t=Je[e](i);postMessage({id:a,method:e,success:!0,response:t})}catch(t){postMessage({id:a,method:e,success:!1,response:t.message}),console.error(t)}})),postMessage({id:void 0,method:"init",success:!0,response:void 0});`;
3909
+ if (stickySession) {
3910
+ saveSession(session);
3911
+ }
3912
+
3913
+ return session;
3914
+ }
3877
3915
 
3878
3916
  /**
3879
- * Create an event buffer for replays.
3917
+ * Fetches a session from storage
3880
3918
  */
3881
- function createEventBuffer({ useCompression }) {
3882
- // eslint-disable-next-line no-restricted-globals
3883
- if (useCompression && window.Worker) {
3884
- const workerBlob = new Blob([workerString]);
3885
- const workerUrl = URL.createObjectURL(workerBlob);
3919
+ function fetchSession() {
3920
+ const hasSessionStorage = 'sessionStorage' in WINDOW;
3886
3921
 
3887
- (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.log('[Replay] Using compression worker');
3888
- const worker = new Worker(workerUrl);
3889
- return new EventBufferProxy(worker);
3922
+ if (!hasSessionStorage) {
3923
+ return null;
3890
3924
  }
3891
3925
 
3892
- (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.log('[Replay] Using simple buffer');
3893
- return new EventBufferArray();
3926
+ try {
3927
+ // This can throw if cookies are disabled
3928
+ const sessionStringFromStorage = WINDOW.sessionStorage.getItem(REPLAY_SESSION_KEY);
3929
+
3930
+ if (!sessionStringFromStorage) {
3931
+ return null;
3932
+ }
3933
+
3934
+ const sessionObj = JSON.parse(sessionStringFromStorage) ;
3935
+
3936
+ return makeSession(sessionObj);
3937
+ } catch (e) {
3938
+ return null;
3939
+ }
3894
3940
  }
3895
3941
 
3896
3942
  /**
3897
- * This proxy will try to use the compression worker, and fall back to use the simple buffer if an error occurs there.
3898
- * This can happen e.g. if the worker cannot be loaded.
3899
- * Exported only for testing.
3943
+ * Get or create a session
3900
3944
  */
3901
- class EventBufferProxy {
3902
-
3903
- constructor(worker) {
3904
- this._fallback = new EventBufferArray();
3905
- this._compression = new EventBufferCompressionWorker(worker);
3906
- this._used = this._fallback;
3945
+ function getSession({
3946
+ expiry,
3947
+ currentSession,
3948
+ stickySession,
3949
+ sessionSampleRate,
3950
+ errorSampleRate,
3951
+ }) {
3952
+ // If session exists and is passed, use it instead of always hitting session storage
3953
+ const session = currentSession || (stickySession && fetchSession());
3907
3954
 
3908
- void this._ensureWorkerIsLoaded();
3909
- }
3955
+ if (session) {
3956
+ // If there is a session, check if it is valid (e.g. "last activity" time
3957
+ // should be within the "session idle time", and "session started" time is
3958
+ // within "max session time").
3959
+ const isExpired = isSessionExpired(session, expiry);
3910
3960
 
3911
- /** @inheritDoc */
3912
- get pendingLength() {
3913
- return this._used.pendingLength;
3961
+ if (!isExpired) {
3962
+ return { type: 'saved', session };
3963
+ } else {
3964
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.log('[Replay] Session has expired');
3965
+ }
3966
+ // Otherwise continue to create a new session
3914
3967
  }
3915
3968
 
3916
- /** @inheritDoc */
3917
- get pendingEvents() {
3918
- return this._used.pendingEvents;
3919
- }
3969
+ const newSession = createSession({
3970
+ stickySession,
3971
+ sessionSampleRate,
3972
+ errorSampleRate,
3973
+ });
3920
3974
 
3921
- /** @inheritDoc */
3922
- destroy() {
3923
- this._fallback.destroy();
3924
- this._compression.destroy();
3925
- }
3975
+ return { type: 'new', session: newSession };
3976
+ }
3926
3977
 
3927
- /**
3928
- * Add an event to the event buffer.
3929
- *
3930
- * Returns true if event was successfully added.
3931
- */
3932
- addEvent(event, isCheckout) {
3933
- return this._used.addEvent(event, isCheckout);
3978
+ /**
3979
+ * Add an event to the event buffer
3980
+ */
3981
+ async function addEvent(
3982
+ replay,
3983
+ event,
3984
+ isCheckout,
3985
+ ) {
3986
+ if (!replay.eventBuffer) {
3987
+ // This implies that `_isEnabled` is false
3988
+ return null;
3934
3989
  }
3935
3990
 
3936
- /** @inheritDoc */
3937
- finish() {
3938
- return this._used.finish();
3991
+ if (replay.isPaused()) {
3992
+ // Do not add to event buffer when recording is paused
3993
+ return null;
3939
3994
  }
3940
3995
 
3941
- /** Ensure the worker has loaded. */
3942
- async _ensureWorkerIsLoaded() {
3943
- try {
3944
- await this._compression.ensureReady();
3945
- } catch (error) {
3946
- // If the worker fails to load, we fall back to the simple buffer.
3947
- // Nothing more to do from our side here
3948
- (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.log('[Replay] Failed to load the compression worker, falling back to simple buffer');
3949
- return;
3950
- }
3951
-
3952
- // Compression worker is ready, we can use it
3953
- // Now we need to switch over the array buffer to the compression worker
3954
- const addEventPromises = [];
3955
- for (const event of this._fallback.pendingEvents) {
3956
- addEventPromises.push(this._compression.addEvent(event));
3957
- }
3996
+ // TODO: sadness -- we will want to normalize timestamps to be in ms -
3997
+ // requires coordination with frontend
3998
+ const isMs = event.timestamp > 9999999999;
3999
+ const timestampInMs = isMs ? event.timestamp : event.timestamp * 1000;
3958
4000
 
3959
- // We switch over to the compression buffer immediately - any further events will be added
3960
- // after the previously buffered ones
3961
- this._used = this._compression;
4001
+ // Throw out events that happen more than 5 minutes ago. This can happen if
4002
+ // page has been left open and idle for a long period of time and user
4003
+ // comes back to trigger a new session. The performance entries rely on
4004
+ // `performance.timeOrigin`, which is when the page first opened.
4005
+ if (timestampInMs + SESSION_IDLE_DURATION < new Date().getTime()) {
4006
+ return null;
4007
+ }
3962
4008
 
3963
- // Wait for original events to be re-added before resolving
3964
- await Promise.all(addEventPromises);
4009
+ // Only record earliest event if a new session was created, otherwise it
4010
+ // shouldn't be relevant
4011
+ const earliestEvent = replay.getContext().earliestEvent;
4012
+ if (replay.session && replay.session.segmentId === 0 && (!earliestEvent || timestampInMs < earliestEvent)) {
4013
+ replay.getContext().earliestEvent = timestampInMs;
3965
4014
  }
4015
+
4016
+ return replay.eventBuffer.addEvent(event, isCheckout);
3966
4017
  }
3967
4018
 
3968
- class EventBufferArray {
4019
+ /**
4020
+ * Create a breadcrumb for a replay.
4021
+ */
4022
+ function createBreadcrumb(
4023
+ breadcrumb,
4024
+ ) {
4025
+ return {
4026
+ timestamp: new Date().getTime() / 1000,
4027
+ type: 'default',
4028
+ ...breadcrumb,
4029
+ };
4030
+ }
3969
4031
 
3970
- constructor() {
3971
- this._events = [];
4032
+ /**
4033
+ * Add a breadcrumb event to replay.
4034
+ */
4035
+ function addBreadcrumbEvent(replay, breadcrumb) {
4036
+ if (breadcrumb.category === 'sentry.transaction') {
4037
+ return;
3972
4038
  }
3973
4039
 
3974
- get pendingLength() {
3975
- return this._events.length;
4040
+ if (breadcrumb.category === 'ui.click') {
4041
+ replay.triggerUserActivity();
4042
+ } else {
4043
+ replay.checkAndHandleExpiredSession();
3976
4044
  }
3977
4045
 
3978
- /**
3979
- * Returns the raw events that are buffered. In `EventBufferArray`, this is the
3980
- * same as `this._events`.
3981
- */
3982
- get pendingEvents() {
3983
- return this._events;
3984
- }
4046
+ replay.addUpdate(() => {
4047
+ void addEvent(replay, {
4048
+ type: EventType.Custom,
4049
+ // TODO: We were converting from ms to seconds for breadcrumbs, spans,
4050
+ // but maybe we should just keep them as milliseconds
4051
+ timestamp: (breadcrumb.timestamp || 0) * 1000,
4052
+ data: {
4053
+ tag: 'breadcrumb',
4054
+ payload: breadcrumb,
4055
+ },
4056
+ });
3985
4057
 
3986
- destroy() {
3987
- this._events = [];
3988
- }
4058
+ // Do not flush after console log messages
4059
+ return breadcrumb.category === 'console';
4060
+ });
4061
+ }
3989
4062
 
3990
- async addEvent(event, isCheckout) {
3991
- if (isCheckout) {
3992
- this._events = [event];
4063
+ const handleDomListener =
4064
+ (replay) =>
4065
+ (handlerData) => {
4066
+ if (!replay.isEnabled()) {
3993
4067
  return;
3994
4068
  }
3995
4069
 
3996
- this._events.push(event);
3997
- return;
3998
- }
4070
+ const result = handleDom(handlerData);
3999
4071
 
4000
- finish() {
4001
- return new Promise(resolve => {
4002
- // Make a copy of the events array reference and immediately clear the
4003
- // events member so that we do not lose new events while uploading
4004
- // attachment.
4005
- const eventsRet = this._events;
4006
- this._events = [];
4007
- resolve(JSON.stringify(eventsRet));
4008
- });
4009
- }
4010
- }
4072
+ if (!result) {
4073
+ return;
4074
+ }
4075
+
4076
+ addBreadcrumbEvent(replay, result);
4077
+ };
4011
4078
 
4012
4079
  /**
4013
- * Event buffer that uses a web worker to compress events.
4014
- * Exported only for testing.
4080
+ * An event handler to react to DOM events.
4015
4081
  */
4016
- class EventBufferCompressionWorker {
4017
- /**
4018
- * Keeps track of the list of events since the last flush that have not been compressed.
4019
- * For example, page is reloaded and a flush attempt is made, but
4020
- * `finish()` (and thus the flush), does not complete.
4021
- */
4022
- __init() {this._pendingEvents = [];}
4023
-
4024
- __init2() {this._eventBufferItemLength = 0;}
4025
- __init3() {this._id = 0;}
4082
+ function handleDom(handlerData) {
4083
+ // Taken from https://github.com/getsentry/sentry-javascript/blob/master/packages/browser/src/integrations/breadcrumbs.ts#L112
4084
+ let target;
4085
+ let targetNode;
4026
4086
 
4027
- constructor(worker) {EventBufferCompressionWorker.prototype.__init.call(this);EventBufferCompressionWorker.prototype.__init2.call(this);EventBufferCompressionWorker.prototype.__init3.call(this);
4028
- this._worker = worker;
4087
+ // Accessing event.target can throw (see getsentry/raven-js#838, #768)
4088
+ try {
4089
+ targetNode = getTargetNode(handlerData);
4090
+ target = utils.htmlTreeAsString(targetNode);
4091
+ } catch (e) {
4092
+ target = '<unknown>';
4029
4093
  }
4030
4094
 
4031
- /**
4032
- * The number of raw events that are buffered. This may not be the same as
4033
- * the number of events that have been compresed in the worker because
4034
- * `addEvent` is async.
4035
- */
4036
- get pendingLength() {
4037
- return this._eventBufferItemLength;
4095
+ if (target.length === 0) {
4096
+ return null;
4038
4097
  }
4039
4098
 
4040
- /**
4041
- * Returns a list of the raw recording events that are being compressed.
4042
- */
4043
- get pendingEvents() {
4044
- return this._pendingEvents;
4099
+ return createBreadcrumb({
4100
+ category: `ui.${handlerData.name}`,
4101
+ message: target,
4102
+ data: {
4103
+ // Not sure why this errors, Node should be correct (Argument of type 'Node' is not assignable to parameter of type 'INode')
4104
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4105
+ ...(targetNode ? { nodeId: record.mirror.getId(targetNode ) } : {}),
4106
+ },
4107
+ });
4108
+ }
4109
+
4110
+ function getTargetNode(handlerData) {
4111
+ if (isEventWithTarget(handlerData.event)) {
4112
+ return handlerData.event.target;
4045
4113
  }
4046
4114
 
4047
- /**
4048
- * Ensure the worker is ready (or not).
4049
- * This will either resolve when the worker is ready, or reject if an error occured.
4050
- */
4051
- ensureReady() {
4052
- return new Promise((resolve, reject) => {
4053
- this._worker.addEventListener(
4054
- 'message',
4055
- ({ data }) => {
4056
- if (data.success) {
4057
- resolve();
4058
- } else {
4059
- reject();
4060
- }
4061
- },
4062
- { once: true },
4063
- );
4115
+ return handlerData.event;
4116
+ }
4064
4117
 
4065
- this._worker.addEventListener(
4066
- 'error',
4067
- error => {
4068
- reject(error);
4118
+ function isEventWithTarget(event) {
4119
+ return !!(event ).target;
4120
+ }
4121
+
4122
+ /**
4123
+ * Create a "span" for each performance entry. The parent transaction is `this.replayEvent`.
4124
+ */
4125
+ function createPerformanceSpans(
4126
+ replay,
4127
+ entries,
4128
+ ) {
4129
+ return entries.map(({ type, start, end, name, data }) =>
4130
+ addEvent(replay, {
4131
+ type: EventType.Custom,
4132
+ timestamp: start,
4133
+ data: {
4134
+ tag: 'performanceSpan',
4135
+ payload: {
4136
+ op: type,
4137
+ description: name,
4138
+ startTimestamp: start,
4139
+ endTimestamp: end,
4140
+ data,
4069
4141
  },
4070
- { once: true },
4071
- );
4072
- });
4142
+ },
4143
+ }),
4144
+ );
4145
+ }
4146
+
4147
+ /**
4148
+ * Check whether a given request URL should be filtered out.
4149
+ */
4150
+ function shouldFilterRequest(replay, url) {
4151
+ // If we enabled the `traceInternals` experiment, we want to trace everything
4152
+ if ((typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && replay.getOptions()._experiments.traceInternals) {
4153
+ return false;
4073
4154
  }
4074
4155
 
4075
- /**
4076
- * Destroy the event buffer.
4077
- */
4078
- destroy() {
4079
- (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.log('[Replay] Destroying compression worker');
4080
- this._worker.terminate();
4156
+ return !_isSentryRequest(url);
4157
+ }
4158
+
4159
+ /**
4160
+ * Checks wether a given URL belongs to the configured Sentry DSN.
4161
+ */
4162
+ function _isSentryRequest(url) {
4163
+ const client = core.getCurrentHub().getClient();
4164
+ const dsn = client && client.getDsn();
4165
+ return dsn ? url.includes(dsn.host) : false;
4166
+ }
4167
+
4168
+ /** only exported for tests */
4169
+ function handleFetch(handlerData) {
4170
+ if (!handlerData.endTimestamp) {
4171
+ return null;
4081
4172
  }
4082
4173
 
4083
- /**
4084
- * Add an event to the event buffer.
4085
- *
4086
- * Returns true if event was successfuly received and processed by worker.
4087
- */
4088
- async addEvent(event, isCheckout) {
4089
- if (isCheckout) {
4090
- // This event is a checkout, make sure worker buffer is cleared before
4091
- // proceeding.
4092
- await this._postMessage({
4093
- id: this._getAndIncrementId(),
4094
- method: 'init',
4095
- args: [],
4096
- });
4097
- }
4174
+ const { startTimestamp, endTimestamp, fetchData, response } = handlerData;
4098
4175
 
4099
- // Don't store checkout events in `_pendingEvents` because they are too large
4100
- if (!isCheckout) {
4101
- this._pendingEvents.push(event);
4176
+ return {
4177
+ type: 'resource.fetch',
4178
+ start: startTimestamp / 1000,
4179
+ end: endTimestamp / 1000,
4180
+ name: fetchData.url,
4181
+ data: {
4182
+ method: fetchData.method,
4183
+ statusCode: response.status,
4184
+ },
4185
+ };
4186
+ }
4187
+
4188
+ /**
4189
+ * Returns a listener to be added to `addInstrumentationHandler('fetch', listener)`.
4190
+ */
4191
+ function handleFetchSpanListener(replay) {
4192
+ return (handlerData) => {
4193
+ if (!replay.isEnabled()) {
4194
+ return;
4102
4195
  }
4103
4196
 
4104
- return this._sendEventToWorker(event);
4105
- }
4197
+ const result = handleFetch(handlerData);
4106
4198
 
4107
- /**
4108
- * Finish the event buffer and return the compressed data.
4109
- */
4110
- finish() {
4111
- return this._finishRequest(this._getAndIncrementId());
4112
- }
4199
+ if (result === null) {
4200
+ return;
4201
+ }
4113
4202
 
4114
- /**
4115
- * Post message to worker and wait for response before resolving promise.
4116
- */
4117
- _postMessage({ id, method, args }) {
4118
- return new Promise((resolve, reject) => {
4119
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
4120
- const listener = ({ data }) => {
4121
- if (data.method !== method) {
4122
- return;
4123
- }
4203
+ if (shouldFilterRequest(replay, result.name)) {
4204
+ return;
4205
+ }
4124
4206
 
4125
- // There can be multiple listeners for a single method, the id ensures
4126
- // that the response matches the caller.
4127
- if (data.id !== id) {
4128
- return;
4129
- }
4207
+ replay.addUpdate(() => {
4208
+ createPerformanceSpans(replay, [result]);
4209
+ // Returning true will cause `addUpdate` to not flush
4210
+ // We do not want network requests to cause a flush. This will prevent
4211
+ // recurring/polling requests from keeping the replay session alive.
4212
+ return true;
4213
+ });
4214
+ };
4215
+ }
4130
4216
 
4131
- // At this point, we'll always want to remove listener regardless of result status
4132
- this._worker.removeEventListener('message', listener);
4217
+ /**
4218
+ * Returns true if we think the given event is an error originating inside of rrweb.
4219
+ */
4220
+ function isRrwebError(event) {
4221
+ if (event.type || !event.exception || !event.exception.values || !event.exception.values.length) {
4222
+ return false;
4223
+ }
4133
4224
 
4134
- if (!data.success) {
4135
- // TODO: Do some error handling, not sure what
4136
- (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.error('[Replay]', data.response);
4225
+ // Check if any exception originates from rrweb
4226
+ return event.exception.values.some(exception => {
4227
+ if (!exception.stacktrace || !exception.stacktrace.frames || !exception.stacktrace.frames.length) {
4228
+ return false;
4229
+ }
4137
4230
 
4138
- reject(new Error('Error in compression worker'));
4139
- return;
4140
- }
4231
+ return exception.stacktrace.frames.some(frame => frame.filename && frame.filename.includes('/rrweb/src/'));
4232
+ });
4233
+ }
4141
4234
 
4142
- resolve(data.response);
4143
- };
4235
+ /**
4236
+ * Returns a listener to be added to `addGlobalEventProcessor(listener)`.
4237
+ */
4238
+ function handleGlobalEventListener(replay) {
4239
+ return (event) => {
4240
+ // Do not apply replayId to the root event
4241
+ if (event.type === REPLAY_EVENT_NAME) {
4242
+ // Replays have separate set of breadcrumbs, do not include breadcrumbs
4243
+ // from core SDK
4244
+ delete event.breadcrumbs;
4245
+ return event;
4246
+ }
4144
4247
 
4145
- let stringifiedArgs;
4146
- try {
4147
- stringifiedArgs = JSON.stringify(args);
4148
- } catch (err) {
4149
- (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.error('[Replay] Error when trying to stringify args', err);
4150
- stringifiedArgs = '[]';
4151
- }
4248
+ // Unless `captureExceptions` is enabled, we want to ignore errors coming from rrweb
4249
+ // As there can be a bunch of stuff going wrong in internals there, that we don't want to bubble up to users
4250
+ if (isRrwebError(event) && !replay.getOptions()._experiments.captureExceptions) {
4251
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.log('[Replay] Ignoring error from rrweb internals', event);
4252
+ return null;
4253
+ }
4152
4254
 
4153
- // Note: we can't use `once` option because it's possible it needs to
4154
- // listen to multiple messages
4155
- this._worker.addEventListener('message', listener);
4156
- this._worker.postMessage({ id, method, args: stringifiedArgs });
4157
- });
4158
- }
4255
+ // Only tag transactions with replayId if not waiting for an error
4256
+ // @ts-ignore private
4257
+ if (!event.type || replay.recordingMode === 'session') {
4258
+ event.tags = { ...event.tags, replayId: replay.getSessionId() };
4259
+ }
4159
4260
 
4160
- /**
4161
- * Send the event to the worker.
4162
- */
4163
- async _sendEventToWorker(event) {
4164
- const promise = this._postMessage({
4165
- id: this._getAndIncrementId(),
4166
- method: 'addEvent',
4167
- args: [event],
4168
- });
4261
+ // Collect traceIds in _context regardless of `recordingMode` - if it's true,
4262
+ // _context gets cleared on every checkout
4263
+ if (event.type === 'transaction' && event.contexts && event.contexts.trace && event.contexts.trace.trace_id) {
4264
+ replay.getContext().traceIds.add(event.contexts.trace.trace_id );
4265
+ return event;
4266
+ }
4169
4267
 
4170
- // XXX: See note in `get length()`
4171
- this._eventBufferItemLength++;
4268
+ // no event type means error
4269
+ if (!event.type) {
4270
+ replay.getContext().errorIds.add(event.event_id );
4271
+ }
4172
4272
 
4173
- return promise;
4174
- }
4273
+ if ((typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && replay.getOptions()._experiments.traceInternals) {
4274
+ const exc = getEventExceptionValues(event);
4275
+ addInternalBreadcrumb({
4276
+ message: `Tagging event (${event.event_id}) - ${event.message} - ${exc.type}: ${exc.value}`,
4277
+ });
4278
+ }
4175
4279
 
4176
- /**
4177
- * Finish the request and return the compressed data from the worker.
4178
- */
4179
- async _finishRequest(id) {
4180
- const promise = this._postMessage({ id, method: 'finish', args: [] });
4280
+ // Need to be very careful that this does not cause an infinite loop
4281
+ if (
4282
+ replay.recordingMode === 'error' &&
4283
+ event.exception &&
4284
+ event.message !== UNABLE_TO_SEND_REPLAY // ignore this error because otherwise we could loop indefinitely with trying to capture replay and failing
4285
+ ) {
4286
+ setTimeout(async () => {
4287
+ // Allow flush to complete before resuming as a session recording, otherwise
4288
+ // the checkout from `startRecording` may be included in the payload.
4289
+ // Prefer to keep the error replay as a separate (and smaller) segment
4290
+ // than the session replay.
4291
+ await replay.flushImmediate();
4181
4292
 
4182
- // XXX: See note in `get length()`
4183
- this._eventBufferItemLength = 0;
4293
+ if (replay.stopRecording()) {
4294
+ // Reset all "capture on error" configuration before
4295
+ // starting a new recording
4296
+ replay.recordingMode = 'session';
4297
+ replay.startRecording();
4298
+ }
4299
+ });
4300
+ }
4184
4301
 
4185
- await promise;
4302
+ return event;
4303
+ };
4304
+ }
4186
4305
 
4187
- this._pendingEvents = [];
4306
+ function addInternalBreadcrumb(arg) {
4307
+ const { category, level, message, ...rest } = arg;
4188
4308
 
4189
- return promise;
4190
- }
4309
+ core.addBreadcrumb({
4310
+ category: category || 'console',
4311
+ level: level || 'debug',
4312
+ message: `[debug]: ${message}`,
4313
+ ...rest,
4314
+ });
4315
+ }
4191
4316
 
4192
- /** Get the current ID and increment it for the next call. */
4193
- _getAndIncrementId() {
4194
- return this._id++;
4195
- }
4317
+ function getEventExceptionValues(event) {
4318
+ return {
4319
+ type: 'Unknown',
4320
+ value: 'n/a',
4321
+ ...(event.exception && event.exception.values && event.exception.values[0]),
4322
+ };
4196
4323
  }
4197
4324
 
4198
- /**
4199
- * Given an initial timestamp and an expiry duration, checks to see if current
4200
- * time should be considered as expired.
4201
- */
4202
- function isExpired(
4203
- initialTime,
4204
- expiry,
4205
- targetTime = +new Date(),
4206
- ) {
4207
- // Always expired if < 0
4208
- if (initialTime === null || expiry === undefined || expiry < 0) {
4209
- return true;
4210
- }
4325
+ function handleHistory(handlerData) {
4326
+ const { from, to } = handlerData;
4211
4327
 
4212
- // Never expires if == 0
4213
- if (expiry === 0) {
4214
- return false;
4215
- }
4328
+ const now = new Date().getTime() / 1000;
4216
4329
 
4217
- return initialTime + expiry <= targetTime;
4330
+ return {
4331
+ type: 'navigation.push',
4332
+ start: now,
4333
+ end: now,
4334
+ name: to,
4335
+ data: {
4336
+ previous: from,
4337
+ },
4338
+ };
4218
4339
  }
4219
4340
 
4220
4341
  /**
4221
- * Checks to see if session is expired
4342
+ * Returns a listener to be added to `addInstrumentationHandler('history', listener)`.
4222
4343
  */
4223
- function isSessionExpired(session, idleTimeout, targetTime = +new Date()) {
4224
- return (
4225
- // First, check that maximum session length has not been exceeded
4226
- isExpired(session.started, MAX_SESSION_LIFE, targetTime) ||
4227
- // check that the idle timeout has not been exceeded (i.e. user has
4228
- // performed an action within the last `idleTimeout` ms)
4229
- isExpired(session.lastActivity, idleTimeout, targetTime)
4230
- );
4231
- }
4344
+ function handleHistorySpanListener(replay) {
4345
+ return (handlerData) => {
4346
+ if (!replay.isEnabled()) {
4347
+ return;
4348
+ }
4232
4349
 
4233
- /**
4234
- * Save a session to session storage.
4235
- */
4236
- function saveSession(session) {
4237
- const hasSessionStorage = 'sessionStorage' in WINDOW;
4238
- if (!hasSessionStorage) {
4239
- return;
4240
- }
4350
+ const result = handleHistory(handlerData);
4241
4351
 
4242
- try {
4243
- WINDOW.sessionStorage.setItem(REPLAY_SESSION_KEY, JSON.stringify(session));
4244
- } catch (e) {
4245
- // Ignore potential SecurityError exceptions
4246
- }
4247
- }
4352
+ if (result === null) {
4353
+ return;
4354
+ }
4248
4355
 
4249
- /**
4250
- * Given a sample rate, returns true if replay should be sampled.
4251
- *
4252
- * 1.0 = 100% sampling
4253
- * 0.0 = 0% sampling
4254
- */
4255
- function isSampled(sampleRate) {
4256
- if (sampleRate === undefined) {
4257
- return false;
4258
- }
4356
+ // Need to collect visited URLs
4357
+ replay.getContext().urls.push(result.name);
4358
+ replay.triggerUserActivity();
4259
4359
 
4260
- // Math.random() returns a number in range of 0 to 1 (inclusive of 0, but not 1)
4261
- return Math.random() < sampleRate;
4360
+ replay.addUpdate(() => {
4361
+ createPerformanceSpans(replay, [result]);
4362
+ // Returning false to flush
4363
+ return false;
4364
+ });
4365
+ };
4262
4366
  }
4263
4367
 
4264
- /**
4265
- * Get a session with defaults & applied sampling.
4266
- */
4267
- function makeSession(session) {
4268
- const now = new Date().getTime();
4269
- const id = session.id || utils.uuid4();
4270
- // Note that this means we cannot set a started/lastActivity of `0`, but this should not be relevant outside of tests.
4271
- const started = session.started || now;
4272
- const lastActivity = session.lastActivity || now;
4273
- const segmentId = session.segmentId || 0;
4274
- const sampled = session.sampled;
4368
+ let _LAST_BREADCRUMB = null;
4275
4369
 
4276
- return {
4277
- id,
4278
- started,
4279
- lastActivity,
4280
- segmentId,
4281
- sampled,
4370
+ const handleScopeListener =
4371
+ (replay) =>
4372
+ (scope) => {
4373
+ if (!replay.isEnabled()) {
4374
+ return;
4375
+ }
4376
+
4377
+ const result = handleScope(scope);
4378
+
4379
+ if (!result) {
4380
+ return;
4381
+ }
4382
+
4383
+ addBreadcrumbEvent(replay, result);
4282
4384
  };
4283
- }
4284
4385
 
4285
4386
  /**
4286
- * Get the sampled status for a session based on sample rates & current sampled status.
4387
+ * An event handler to handle scope changes.
4287
4388
  */
4288
- function getSessionSampleType(sessionSampleRate, errorSampleRate) {
4289
- return isSampled(sessionSampleRate) ? 'session' : isSampled(errorSampleRate) ? 'error' : false;
4290
- }
4389
+ function handleScope(scope) {
4390
+ const newBreadcrumb = scope.getLastBreadcrumb();
4291
4391
 
4292
- /**
4293
- * Create a new session, which in its current implementation is a Sentry event
4294
- * that all replays will be saved to as attachments. Currently, we only expect
4295
- * one of these Sentry events per "replay session".
4296
- */
4297
- function createSession({ sessionSampleRate, errorSampleRate, stickySession = false }) {
4298
- const sampled = getSessionSampleType(sessionSampleRate, errorSampleRate);
4299
- const session = makeSession({
4300
- sampled,
4301
- });
4392
+ // Listener can be called when breadcrumbs have not changed, so we store the
4393
+ // reference to the last crumb and only return a crumb if it has changed
4394
+ if (_LAST_BREADCRUMB === newBreadcrumb || !newBreadcrumb) {
4395
+ return null;
4396
+ }
4302
4397
 
4303
- (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.log(`[Replay] Creating new session: ${session.id}`);
4398
+ _LAST_BREADCRUMB = newBreadcrumb;
4304
4399
 
4305
- if (stickySession) {
4306
- saveSession(session);
4400
+ if (
4401
+ newBreadcrumb.category &&
4402
+ (['fetch', 'xhr', 'sentry.event', 'sentry.transaction'].includes(newBreadcrumb.category) ||
4403
+ newBreadcrumb.category.startsWith('ui.'))
4404
+ ) {
4405
+ return null;
4307
4406
  }
4308
4407
 
4309
- return session;
4408
+ return createBreadcrumb(newBreadcrumb);
4310
4409
  }
4311
4410
 
4312
- /**
4313
- * Fetches a session from storage
4314
- */
4315
- function fetchSession() {
4316
- const hasSessionStorage = 'sessionStorage' in WINDOW;
4411
+ // From sentry-javascript
4412
+ // e.g. https://github.com/getsentry/sentry-javascript/blob/c7fc025bf9fa8c073fdb56351808ce53909fbe45/packages/utils/src/instrument.ts#L180
4317
4413
 
4318
- if (!hasSessionStorage) {
4414
+ function handleXhr(handlerData) {
4415
+ if (handlerData.xhr.__sentry_own_request__) {
4416
+ // Taken from sentry-javascript
4417
+ // Only capture non-sentry requests
4319
4418
  return null;
4320
4419
  }
4321
4420
 
4322
- try {
4323
- // This can throw if cookies are disabled
4324
- const sessionStringFromStorage = WINDOW.sessionStorage.getItem(REPLAY_SESSION_KEY);
4421
+ if (handlerData.startTimestamp) {
4422
+ // TODO: See if this is still needed
4423
+ handlerData.xhr.__sentry_xhr__ = handlerData.xhr.__sentry_xhr__ || {};
4424
+ handlerData.xhr.__sentry_xhr__.startTimestamp = handlerData.startTimestamp;
4425
+ }
4325
4426
 
4326
- if (!sessionStringFromStorage) {
4327
- return null;
4328
- }
4427
+ if (!handlerData.endTimestamp) {
4428
+ return null;
4429
+ }
4329
4430
 
4330
- const sessionObj = JSON.parse(sessionStringFromStorage) ;
4431
+ const { method, url, status_code: statusCode } = handlerData.xhr.__sentry_xhr__ || {};
4331
4432
 
4332
- return makeSession(sessionObj);
4333
- } catch (e) {
4433
+ if (url === undefined) {
4334
4434
  return null;
4335
4435
  }
4436
+
4437
+ const timestamp = handlerData.xhr.__sentry_xhr__
4438
+ ? handlerData.xhr.__sentry_xhr__.startTimestamp || 0
4439
+ : handlerData.endTimestamp;
4440
+
4441
+ return {
4442
+ type: 'resource.xhr',
4443
+ name: url,
4444
+ start: timestamp / 1000,
4445
+ end: handlerData.endTimestamp / 1000,
4446
+ data: {
4447
+ method,
4448
+ statusCode,
4449
+ },
4450
+ };
4336
4451
  }
4337
4452
 
4338
4453
  /**
4339
- * Get or create a session
4454
+ * Returns a listener to be added to `addInstrumentationHandler('xhr', listener)`.
4340
4455
  */
4341
- function getSession({
4342
- expiry,
4343
- currentSession,
4344
- stickySession,
4345
- sessionSampleRate,
4346
- errorSampleRate,
4347
- }) {
4348
- // If session exists and is passed, use it instead of always hitting session storage
4349
- const session = currentSession || (stickySession && fetchSession());
4456
+ function handleXhrSpanListener(replay) {
4457
+ return (handlerData) => {
4458
+ if (!replay.isEnabled()) {
4459
+ return;
4460
+ }
4350
4461
 
4351
- if (session) {
4352
- // If there is a session, check if it is valid (e.g. "last activity" time
4353
- // should be within the "session idle time", and "session started" time is
4354
- // within "max session time").
4355
- const isExpired = isSessionExpired(session, expiry);
4462
+ const result = handleXhr(handlerData);
4356
4463
 
4357
- if (!isExpired) {
4358
- return { type: 'saved', session };
4359
- } else {
4360
- (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.log('[Replay] Session has expired');
4464
+ if (result === null) {
4465
+ return;
4361
4466
  }
4362
- // Otherwise continue to create a new session
4363
- }
4364
4467
 
4365
- const newSession = createSession({
4366
- stickySession,
4367
- sessionSampleRate,
4368
- errorSampleRate,
4369
- });
4468
+ if (shouldFilterRequest(replay, result.name)) {
4469
+ return;
4470
+ }
4370
4471
 
4371
- return { type: 'new', session: newSession };
4472
+ replay.addUpdate(() => {
4473
+ createPerformanceSpans(replay, [result]);
4474
+ // Returning true will cause `addUpdate` to not flush
4475
+ // We do not want network requests to cause a flush. This will prevent
4476
+ // recurring/polling requests from keeping the replay session alive.
4477
+ return true;
4478
+ });
4479
+ };
4480
+ }
4481
+
4482
+ /**
4483
+ * Add global listeners that cannot be removed.
4484
+ */
4485
+ function addGlobalListeners(replay) {
4486
+ // Listeners from core SDK //
4487
+ const scope = core.getCurrentHub().getScope();
4488
+ if (scope) {
4489
+ scope.addScopeListener(handleScopeListener(replay));
4490
+ }
4491
+ utils.addInstrumentationHandler('dom', handleDomListener(replay));
4492
+ utils.addInstrumentationHandler('fetch', handleFetchSpanListener(replay));
4493
+ utils.addInstrumentationHandler('xhr', handleXhrSpanListener(replay));
4494
+ utils.addInstrumentationHandler('history', handleHistorySpanListener(replay));
4495
+
4496
+ // Tag all (non replay) events that get sent to Sentry with the current
4497
+ // replay ID so that we can reference them later in the UI
4498
+ core.addGlobalEventProcessor(handleGlobalEventListener(replay));
4372
4499
  }
4373
4500
 
4374
4501
  /**
@@ -4995,7 +5122,7 @@ class ReplayContainer {
4995
5122
  recordingOptions,
4996
5123
  }
4997
5124
 
4998
- ) {ReplayContainer.prototype.__init.call(this);ReplayContainer.prototype.__init2.call(this);ReplayContainer.prototype.__init3.call(this);ReplayContainer.prototype.__init4.call(this);ReplayContainer.prototype.__init5.call(this);ReplayContainer.prototype.__init6.call(this);ReplayContainer.prototype.__init7.call(this);ReplayContainer.prototype.__init8.call(this);ReplayContainer.prototype.__init9.call(this);ReplayContainer.prototype.__init10.call(this);ReplayContainer.prototype.__init11.call(this);ReplayContainer.prototype.__init12.call(this);ReplayContainer.prototype.__init13.call(this);ReplayContainer.prototype.__init14.call(this);ReplayContainer.prototype.__init15.call(this);ReplayContainer.prototype.__init16.call(this);ReplayContainer.prototype.__init17.call(this);
5125
+ ) {ReplayContainer.prototype.__init.call(this);ReplayContainer.prototype.__init2.call(this);ReplayContainer.prototype.__init3.call(this);ReplayContainer.prototype.__init4.call(this);ReplayContainer.prototype.__init5.call(this);ReplayContainer.prototype.__init6.call(this);ReplayContainer.prototype.__init7.call(this);ReplayContainer.prototype.__init8.call(this);ReplayContainer.prototype.__init9.call(this);ReplayContainer.prototype.__init10.call(this);ReplayContainer.prototype.__init11.call(this);ReplayContainer.prototype.__init12.call(this);ReplayContainer.prototype.__init13.call(this);ReplayContainer.prototype.__init14.call(this);ReplayContainer.prototype.__init15.call(this);ReplayContainer.prototype.__init16.call(this);
4999
5126
  this._recordingOptions = recordingOptions;
5000
5127
  this._options = options;
5001
5128
 
@@ -5093,12 +5220,18 @@ class ReplayContainer {
5093
5220
  * Returns true if it was stopped, else false.
5094
5221
  */
5095
5222
  stopRecording() {
5096
- if (this._stopRecording) {
5097
- this._stopRecording();
5098
- return true;
5099
- }
5223
+ try {
5224
+ if (this._stopRecording) {
5225
+ this._stopRecording();
5226
+ this._stopRecording = undefined;
5227
+ return true;
5228
+ }
5100
5229
 
5101
- return false;
5230
+ return false;
5231
+ } catch (err) {
5232
+ this._handleException(err);
5233
+ return false;
5234
+ }
5102
5235
  }
5103
5236
 
5104
5237
  /**
@@ -5110,7 +5243,7 @@ class ReplayContainer {
5110
5243
  (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.log('[Replay] Stopping Replays');
5111
5244
  this._isEnabled = false;
5112
5245
  this._removeListeners();
5113
- this._stopRecording && this._stopRecording();
5246
+ this.stopRecording();
5114
5247
  this.eventBuffer && this.eventBuffer.destroy();
5115
5248
  this.eventBuffer = null;
5116
5249
  this._debouncedFlush.cancel();
@@ -5126,14 +5259,7 @@ class ReplayContainer {
5126
5259
  */
5127
5260
  pause() {
5128
5261
  this._isPaused = true;
5129
- try {
5130
- if (this._stopRecording) {
5131
- this._stopRecording();
5132
- this._stopRecording = undefined;
5133
- }
5134
- } catch (err) {
5135
- this._handleException(err);
5136
- }
5262
+ this.stopRecording();
5137
5263
  }
5138
5264
 
5139
5265
  /**
@@ -5197,7 +5323,7 @@ class ReplayContainer {
5197
5323
  }
5198
5324
 
5199
5325
  // Otherwise... recording was never suspended, continue as normalish
5200
- this._checkAndHandleExpiredSession();
5326
+ this.checkAndHandleExpiredSession();
5201
5327
 
5202
5328
  this._updateSessionActivity();
5203
5329
  }
@@ -5219,6 +5345,44 @@ class ReplayContainer {
5219
5345
  return this.session && this.session.id;
5220
5346
  }
5221
5347
 
5348
+ /**
5349
+ * Checks if recording should be stopped due to user inactivity. Otherwise
5350
+ * check if session is expired and create a new session if so. Triggers a new
5351
+ * full snapshot on new session.
5352
+ *
5353
+ * Returns true if session is not expired, false otherwise.
5354
+ * @hidden
5355
+ */
5356
+ checkAndHandleExpiredSession({ expiry = SESSION_IDLE_DURATION } = {}) {
5357
+ const oldSessionId = this.getSessionId();
5358
+
5359
+ // Prevent starting a new session if the last user activity is older than
5360
+ // MAX_SESSION_LIFE. Otherwise non-user activity can trigger a new
5361
+ // session+recording. This creates noisy replays that do not have much
5362
+ // content in them.
5363
+ if (this._lastActivity && isExpired(this._lastActivity, MAX_SESSION_LIFE)) {
5364
+ // Pause recording
5365
+ this.pause();
5366
+ return;
5367
+ }
5368
+
5369
+ // --- There is recent user activity --- //
5370
+ // This will create a new session if expired, based on expiry length
5371
+ this._loadSession({ expiry });
5372
+
5373
+ // Session was expired if session ids do not match
5374
+ const expired = oldSessionId !== this.getSessionId();
5375
+
5376
+ if (!expired) {
5377
+ return true;
5378
+ }
5379
+
5380
+ // Session is expired, trigger a full snapshot (which will create a new session)
5381
+ this._triggerFullSnapshot();
5382
+
5383
+ return false;
5384
+ }
5385
+
5222
5386
  /** A wrapper to conditionally capture exceptions. */
5223
5387
  _handleException(error) {
5224
5388
  (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.error('[Replay]', error);
@@ -5288,19 +5452,7 @@ class ReplayContainer {
5288
5452
 
5289
5453
  // There is no way to remove these listeners, so ensure they are only added once
5290
5454
  if (!this._hasInitializedCoreListeners) {
5291
- // Listeners from core SDK //
5292
- const scope = core.getCurrentHub().getScope();
5293
- if (scope) {
5294
- scope.addScopeListener(this._handleCoreBreadcrumbListener('scope'));
5295
- }
5296
- utils.addInstrumentationHandler('dom', this._handleCoreBreadcrumbListener('dom'));
5297
- utils.addInstrumentationHandler('fetch', handleFetchSpanListener(this));
5298
- utils.addInstrumentationHandler('xhr', handleXhrSpanListener(this));
5299
- utils.addInstrumentationHandler('history', handleHistorySpanListener(this));
5300
-
5301
- // Tag all (non replay) events that get sent to Sentry with the current
5302
- // replay ID so that we can reference them later in the UI
5303
- core.addGlobalEventProcessor(handleGlobalEventListener(this));
5455
+ addGlobalListeners(this);
5304
5456
 
5305
5457
  this._hasInitializedCoreListeners = true;
5306
5458
  }
@@ -5347,7 +5499,7 @@ class ReplayContainer {
5347
5499
  isCheckout,
5348
5500
  ) => {
5349
5501
  // If this is false, it means session is expired, create and a new session and wait for checkout
5350
- if (!this._checkAndHandleExpiredSession()) {
5502
+ if (!this.checkAndHandleExpiredSession()) {
5351
5503
  (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.error('[Replay] Received replay event after session expired.');
5352
5504
 
5353
5505
  return;
@@ -5442,51 +5594,6 @@ class ReplayContainer {
5442
5594
  this._doChangeToForegroundTasks(breadcrumb);
5443
5595
  };}
5444
5596
 
5445
- /**
5446
- * Handler for Sentry Core SDK events.
5447
- *
5448
- * These events will create breadcrumb-like objects in the recording.
5449
- */
5450
- __init16() {this._handleCoreBreadcrumbListener =
5451
- (type) =>
5452
- (handlerData) => {
5453
- if (!this._isEnabled) {
5454
- return;
5455
- }
5456
-
5457
- const result = breadcrumbHandler(type, handlerData);
5458
-
5459
- if (result === null) {
5460
- return;
5461
- }
5462
-
5463
- if (result.category === 'sentry.transaction') {
5464
- return;
5465
- }
5466
-
5467
- if (result.category === 'ui.click') {
5468
- this.triggerUserActivity();
5469
- } else {
5470
- this._checkAndHandleExpiredSession();
5471
- }
5472
-
5473
- this.addUpdate(() => {
5474
- void addEvent(this, {
5475
- type: EventType.Custom,
5476
- // TODO: We were converting from ms to seconds for breadcrumbs, spans,
5477
- // but maybe we should just keep them as milliseconds
5478
- timestamp: (result.timestamp || 0) * 1000,
5479
- data: {
5480
- tag: 'breadcrumb',
5481
- payload: result,
5482
- },
5483
- });
5484
-
5485
- // Do not flush after console log messages
5486
- return result.category === 'console';
5487
- });
5488
- };}
5489
-
5490
5597
  /**
5491
5598
  * Tasks to run when we consider a page to be hidden (via blurring and/or visibility)
5492
5599
  */
@@ -5515,7 +5622,7 @@ class ReplayContainer {
5515
5622
  return;
5516
5623
  }
5517
5624
 
5518
- const isSessionActive = this._checkAndHandleExpiredSession({
5625
+ const isSessionActive = this.checkAndHandleExpiredSession({
5519
5626
  expiry: VISIBILITY_CHANGE_TIMEOUT,
5520
5627
  });
5521
5628
 
@@ -5537,8 +5644,12 @@ class ReplayContainer {
5537
5644
  * create a new Replay event.
5538
5645
  */
5539
5646
  _triggerFullSnapshot() {
5540
- (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.log('[Replay] Taking full rrweb snapshot');
5541
- record.takeFullSnapshot(true);
5647
+ try {
5648
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.log('[Replay] Taking full rrweb snapshot');
5649
+ record.takeFullSnapshot(true);
5650
+ } catch (err) {
5651
+ this._handleException(err);
5652
+ }
5542
5653
  }
5543
5654
 
5544
5655
  /**
@@ -5586,43 +5697,6 @@ class ReplayContainer {
5586
5697
  return Promise.all(createPerformanceSpans(this, createPerformanceEntries(entries)));
5587
5698
  }
5588
5699
 
5589
- /**
5590
- * Checks if recording should be stopped due to user inactivity. Otherwise
5591
- * check if session is expired and create a new session if so. Triggers a new
5592
- * full snapshot on new session.
5593
- *
5594
- * Returns true if session is not expired, false otherwise.
5595
- */
5596
- _checkAndHandleExpiredSession({ expiry = SESSION_IDLE_DURATION } = {}) {
5597
- const oldSessionId = this.getSessionId();
5598
-
5599
- // Prevent starting a new session if the last user activity is older than
5600
- // MAX_SESSION_LIFE. Otherwise non-user activity can trigger a new
5601
- // session+recording. This creates noisy replays that do not have much
5602
- // content in them.
5603
- if (this._lastActivity && isExpired(this._lastActivity, MAX_SESSION_LIFE)) {
5604
- // Pause recording
5605
- this.pause();
5606
- return;
5607
- }
5608
-
5609
- // --- There is recent user activity --- //
5610
- // This will create a new session if expired, based on expiry length
5611
- this._loadSession({ expiry });
5612
-
5613
- // Session was expired if session ids do not match
5614
- const expired = oldSessionId !== this.getSessionId();
5615
-
5616
- if (!expired) {
5617
- return true;
5618
- }
5619
-
5620
- // Session is expired, trigger a full snapshot (which will create a new session)
5621
- this._triggerFullSnapshot();
5622
-
5623
- return false;
5624
- }
5625
-
5626
5700
  /**
5627
5701
  * Only flush if `this.recordingMode === 'session'`
5628
5702
  */
@@ -5735,13 +5809,13 @@ class ReplayContainer {
5735
5809
  * Flush recording data to Sentry. Creates a lock so that only a single flush
5736
5810
  * can be active at a time. Do not call this directly.
5737
5811
  */
5738
- __init17() {this._flush = async () => {
5812
+ __init16() {this._flush = async () => {
5739
5813
  if (!this._isEnabled) {
5740
5814
  // This can happen if e.g. the replay was stopped because of exceeding the retry limit
5741
5815
  return;
5742
5816
  }
5743
5817
 
5744
- if (!this._checkAndHandleExpiredSession()) {
5818
+ if (!this.checkAndHandleExpiredSession()) {
5745
5819
  (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.error('[Replay] Attempting to finish replay event after session expired.');
5746
5820
  return;
5747
5821
  }
@@ -5878,8 +5952,8 @@ class Replay {
5878
5952
  flushMinDelay,
5879
5953
  flushMaxDelay,
5880
5954
  stickySession,
5881
- sessionSampleRate: DEFAULT_SESSION_SAMPLE_RATE,
5882
- errorSampleRate: DEFAULT_ERROR_SAMPLE_RATE,
5955
+ sessionSampleRate: 0,
5956
+ errorSampleRate: 0,
5883
5957
  useCompression,
5884
5958
  maskAllText: typeof maskAllText === 'boolean' ? maskAllText : !maskTextSelector,
5885
5959
  blockAllMedia,