clarity-js 0.8.5 → 0.8.6

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/build/clarity.js CHANGED
@@ -12,39 +12,34 @@ var dom = /*#__PURE__*/Object.freeze({
12
12
  get iframe () { return iframe; },
13
13
  get iframeContent () { return iframeContent; },
14
14
  get lookup () { return lookup; },
15
- get parse () { return parse$1; },
15
+ get parse () { return parse; },
16
16
  get removeIFrame () { return removeIFrame; },
17
17
  get sameorigin () { return sameorigin; },
18
- get start () { return start$i; },
19
- get stop () { return stop$g; },
20
- get update () { return update$1; },
18
+ get start () { return start$j; },
19
+ get stop () { return stop$h; },
20
+ get update () { return update; },
21
21
  get updates () { return updates$2; }
22
22
  });
23
23
  var upload$1 = /*#__PURE__*/Object.freeze({
24
24
  __proto__: null,
25
25
  get queue () { return queue; },
26
- get start () { return start$f; },
27
- get stop () { return stop$d; },
26
+ get start () { return start$g; },
27
+ get stop () { return stop$e; },
28
28
  get track () { return track$1; }
29
29
  });
30
- var extract = /*#__PURE__*/Object.freeze({
30
+ var upgrade$1 = /*#__PURE__*/Object.freeze({
31
31
  __proto__: null,
32
- get clone () { return clone; },
33
- get compute () { return compute$4; },
34
32
  get data () { return data$5; },
35
- get keys () { return keys; },
36
- get reset () { return reset$4; },
37
- get start () { return start$c; },
33
+ get start () { return start$b; },
38
34
  get stop () { return stop$b; },
39
- get trigger () { return trigger$1; },
40
- get update () { return update; }
35
+ get upgrade () { return upgrade; }
41
36
  });
42
37
  var limit = /*#__PURE__*/Object.freeze({
43
38
  __proto__: null,
44
39
  get check () { return check$2; },
45
40
  get compute () { return compute$3; },
46
41
  get data () { return data$4; },
47
- get start () { return start$b; },
42
+ get start () { return start$a; },
48
43
  get stop () { return stop$a; },
49
44
  get trigger () { return trigger; }
50
45
  });
@@ -54,7 +49,7 @@ var dimension = /*#__PURE__*/Object.freeze({
54
49
  get data () { return data$3; },
55
50
  get log () { return log; },
56
51
  get reset () { return reset$3; },
57
- get start () { return start$a; },
52
+ get start () { return start$9; },
58
53
  get stop () { return stop$9; },
59
54
  get updates () { return updates; }
60
55
  });
@@ -70,14 +65,14 @@ var metadata$1 = /*#__PURE__*/Object.freeze({
70
65
  get metadata () { return metadata; },
71
66
  get save () { return save; },
72
67
  get shortid () { return shortid; },
73
- get start () { return start$9; },
68
+ get start () { return start$8; },
74
69
  get stop () { return stop$8; }
75
70
  });
76
71
  var envelope$1 = /*#__PURE__*/Object.freeze({
77
72
  __proto__: null,
78
73
  get data () { return data$1; },
79
74
  get envelope () { return envelope; },
80
- get start () { return start$8; },
75
+ get start () { return start$7; },
81
76
  get stop () { return stop$7; }
82
77
  });
83
78
  var clarity = /*#__PURE__*/Object.freeze({
@@ -139,6 +134,7 @@ var config$2 = {
139
134
  projectId: null,
140
135
  delay: 1 * 1000 /* Time.Second */,
141
136
  lean: false,
137
+ lite: false,
142
138
  track: true,
143
139
  content: true,
144
140
  drop: [],
@@ -189,7 +185,7 @@ function stop$F() {
189
185
  startTime = 0;
190
186
  }
191
187
 
192
- var version$1 = "0.8.5";
188
+ var version$1 = "0.8.6";
193
189
 
194
190
  // tslint:disable: no-bitwise
195
191
  function hash (input, precision) {
@@ -715,44 +711,6 @@ var summary = /*#__PURE__*/Object.freeze({
715
711
  track: track$7
716
712
  });
717
713
 
718
- var data$f = null;
719
- function start$D() {
720
- if (!config$2.lean && config$2.upgrade) {
721
- config$2.upgrade("Config" /* Constant.Config */);
722
- }
723
- data$f = null;
724
- }
725
- // Following call will upgrade the session from lean mode into the full mode retroactively from the start of the page.
726
- // As part of the lean mode, we do not send back any layout information - including discovery of DOM and mutations.
727
- // However, if there's a need for full fidelity playback, calling this function will disable lean mode
728
- // and send all backed up layout events to the server.
729
- function upgrade(key) {
730
- // Upgrade only if Clarity was successfully activated on the page
731
- if (active() && config$2.lean) {
732
- config$2.lean = false;
733
- data$f = { key: key };
734
- // Update metadata to track we have upgraded this session
735
- callback();
736
- save();
737
- // Callback upgrade handler, if configured
738
- if (config$2.upgrade) {
739
- config$2.upgrade(key);
740
- }
741
- encode$1(3 /* Event.Upgrade */);
742
- }
743
- }
744
- function stop$A() {
745
- data$f = null;
746
- }
747
-
748
- var upgrade$1 = /*#__PURE__*/Object.freeze({
749
- __proto__: null,
750
- get data () { return data$f; },
751
- start: start$D,
752
- stop: stop$A,
753
- upgrade: upgrade
754
- });
755
-
756
714
  /******************************************************************************
757
715
  Copyright (c) Microsoft Corporation.
758
716
 
@@ -808,8 +766,66 @@ function __generator(thisArg, body) {
808
766
  }
809
767
  }
810
768
 
811
- var data$e = null;
812
- function start$C() {
769
+ var supported$1 = "CompressionStream" /* Constant.CompressionStream */ in window;
770
+ function compress (input) {
771
+ return __awaiter(this, void 0, void 0, function () {
772
+ var stream, _a;
773
+ return __generator(this, function (_c) {
774
+ switch (_c.label) {
775
+ case 0:
776
+ _c.trys.push([0, 3, , 4]);
777
+ if (!supported$1) return [3 /*break*/, 2];
778
+ stream = new ReadableStream({ start: function (controller) {
779
+ return __awaiter(this, void 0, void 0, function () {
780
+ return __generator(this, function (_a) {
781
+ controller.enqueue(input);
782
+ controller.close();
783
+ return [2 /*return*/];
784
+ });
785
+ });
786
+ } }).pipeThrough(new TextEncoderStream()).pipeThrough(new window["CompressionStream" /* Constant.CompressionStream */]("gzip"));
787
+ _a = Uint8Array.bind;
788
+ return [4 /*yield*/, read(stream)];
789
+ case 1: return [2 /*return*/, new (_a.apply(Uint8Array, [void 0, _c.sent()]))()];
790
+ case 2: return [3 /*break*/, 4];
791
+ case 3:
792
+ _c.sent();
793
+ return [3 /*break*/, 4];
794
+ case 4: return [2 /*return*/, null];
795
+ }
796
+ });
797
+ });
798
+ }
799
+ function read(stream) {
800
+ return __awaiter(this, void 0, void 0, function () {
801
+ var reader, chunks, done, value;
802
+ var _a;
803
+ return __generator(this, function (_b) {
804
+ switch (_b.label) {
805
+ case 0:
806
+ reader = stream.getReader();
807
+ chunks = [];
808
+ done = false;
809
+ value = [];
810
+ _b.label = 1;
811
+ case 1:
812
+ if (!!done) return [3 /*break*/, 3];
813
+ return [4 /*yield*/, reader.read()];
814
+ case 2:
815
+ (_a = _b.sent(), done = _a.done, value = _a.value);
816
+ if (done) {
817
+ return [2 /*return*/, chunks];
818
+ }
819
+ chunks.push.apply(chunks, value);
820
+ return [3 /*break*/, 1];
821
+ case 3: return [2 /*return*/, chunks];
822
+ }
823
+ });
824
+ });
825
+ }
826
+
827
+ var data$f = null;
828
+ function start$D() {
813
829
  reset$o();
814
830
  }
815
831
  function set(variable, value) {
@@ -856,22 +872,22 @@ function log$2(variable, value) {
856
872
  value &&
857
873
  typeof variable === "string" /* Constant.String */ &&
858
874
  variable.length < 255) {
859
- var validValues = variable in data$e ? data$e[variable] : [];
875
+ var validValues = variable in data$f ? data$f[variable] : [];
860
876
  for (var i = 0; i < value.length; i++) {
861
877
  if (typeof value[i] === "string" /* Constant.String */ && value[i].length < 255) {
862
878
  validValues.push(value[i]);
863
879
  }
864
880
  }
865
- data$e[variable] = validValues;
881
+ data$f[variable] = validValues;
866
882
  }
867
883
  }
868
884
  function compute$b() {
869
885
  encode$1(34 /* Event.Variable */);
870
886
  }
871
887
  function reset$o() {
872
- data$e = {};
888
+ data$f = {};
873
889
  }
874
- function stop$z() {
890
+ function stop$A() {
875
891
  reset$o();
876
892
  }
877
893
  function redact(input) {
@@ -907,72 +923,215 @@ function detect(input) {
907
923
  var variable = /*#__PURE__*/Object.freeze({
908
924
  __proto__: null,
909
925
  compute: compute$b,
910
- get data () { return data$e; },
926
+ get data () { return data$f; },
911
927
  identify: identify,
912
928
  reset: reset$o,
913
929
  set: set,
914
- start: start$C,
915
- stop: stop$z
930
+ start: start$D,
931
+ stop: stop$A
916
932
  });
917
933
 
918
- var supported$1 = "CompressionStream" /* Constant.CompressionStream */ in window;
919
- function compress (input) {
920
- return __awaiter(this, void 0, void 0, function () {
921
- var stream, _a;
922
- return __generator(this, function (_c) {
923
- switch (_c.label) {
924
- case 0:
925
- _c.trys.push([0, 3, , 4]);
926
- if (!supported$1) return [3 /*break*/, 2];
927
- stream = new ReadableStream({ start: function (controller) {
928
- return __awaiter(this, void 0, void 0, function () {
929
- return __generator(this, function (_a) {
930
- controller.enqueue(input);
931
- controller.close();
932
- return [2 /*return*/];
933
- });
934
- });
935
- } }).pipeThrough(new TextEncoderStream()).pipeThrough(new window["CompressionStream" /* Constant.CompressionStream */]("gzip"));
936
- _a = Uint8Array.bind;
937
- return [4 /*yield*/, read(stream)];
938
- case 1: return [2 /*return*/, new (_a.apply(Uint8Array, [void 0, _c.sent()]))()];
939
- case 2: return [3 /*break*/, 4];
940
- case 3:
941
- _c.sent();
942
- return [3 /*break*/, 4];
943
- case 4: return [2 /*return*/, null];
934
+ var data$e = {};
935
+ var keys = new Set();
936
+ var variables = {};
937
+ var selectors = {};
938
+ var hashes = {};
939
+ var validation = {};
940
+ function start$C() {
941
+ reset$n();
942
+ }
943
+ // Input string is of the following form:
944
+ // EXTRACT 101|element { "1": ".class1", "2": "~window.a.b", "3": "!abc"}
945
+ // if element is present on the page it will set up event 101 to grab the contents of the class1 selector into component 1,
946
+ // the javascript evaluated contents of window.a.b into component 2,
947
+ // and the contents of Clarity's hash abc into component 3
948
+ function trigger$2(input) {
949
+ try {
950
+ var parts = input && input.length > 0 ? input.split(/ (.*)/) : ["" /* Constant.Empty */];
951
+ var keyparts = parts[0].split(/\|(.*)/);
952
+ var key = parseInt(keyparts[0]);
953
+ var element = keyparts.length > 1 ? keyparts[1] : "" /* Constant.Empty */;
954
+ var values = parts.length > 1 ? JSON.parse(parts[1]) : {};
955
+ variables[key] = {};
956
+ selectors[key] = {};
957
+ hashes[key] = {};
958
+ validation[key] = element;
959
+ for (var v in values) {
960
+ // values is a set of strings for proper JSON parsing, but it's more efficient
961
+ // to interact with them as numbers
962
+ var id = parseInt(v);
963
+ var value = values[v];
964
+ var source = 2 /* ExtractSource.Text */;
965
+ if (value.startsWith("~" /* Constant.Tilde */)) {
966
+ source = 0 /* ExtractSource.Javascript */;
944
967
  }
945
- });
946
- });
968
+ else if (value.startsWith("!" /* Constant.Bang */)) {
969
+ source = 4 /* ExtractSource.Hash */;
970
+ }
971
+ switch (source) {
972
+ case 0 /* ExtractSource.Javascript */:
973
+ var variable = value.slice(1);
974
+ variables[key][id] = parse$1(variable);
975
+ break;
976
+ case 2 /* ExtractSource.Text */:
977
+ selectors[key][id] = value;
978
+ break;
979
+ case 4 /* ExtractSource.Hash */:
980
+ var hash_1 = value.slice(1);
981
+ hashes[key][id] = hash_1;
982
+ break;
983
+ }
984
+ }
985
+ }
986
+ catch (e) {
987
+ log$1(8 /* Code.Config */, 1 /* Severity.Warning */, e ? e.name : null);
988
+ }
947
989
  }
948
- function read(stream) {
949
- return __awaiter(this, void 0, void 0, function () {
950
- var reader, chunks, done, value;
951
- var _a;
952
- return __generator(this, function (_b) {
953
- switch (_b.label) {
954
- case 0:
955
- reader = stream.getReader();
956
- chunks = [];
957
- done = false;
958
- value = [];
959
- _b.label = 1;
960
- case 1:
961
- if (!!done) return [3 /*break*/, 3];
962
- return [4 /*yield*/, reader.read()];
963
- case 2:
964
- (_a = _b.sent(), done = _a.done, value = _a.value);
965
- if (done) {
966
- return [2 /*return*/, chunks];
990
+ function clone$1(v) {
991
+ return JSON.parse(JSON.stringify(v));
992
+ }
993
+ function compute$a() {
994
+ try {
995
+ for (var v in variables) {
996
+ var key = parseInt(v);
997
+ if (validation[key] == "" /* Constant.Empty */ || document.querySelector(validation[key])) {
998
+ var variableData = variables[key];
999
+ for (var v_1 in variableData) {
1000
+ var variableKey = parseInt(v_1);
1001
+ var value = str$1(evaluate(clone$1(variableData[variableKey])));
1002
+ if (value) {
1003
+ update$1(key, variableKey, value);
967
1004
  }
968
- chunks.push.apply(chunks, value);
969
- return [3 /*break*/, 1];
970
- case 3: return [2 /*return*/, chunks];
1005
+ }
1006
+ var selectorData = selectors[key];
1007
+ for (var s in selectorData) {
1008
+ var shouldMask = false;
1009
+ var selectorKey = parseInt(s);
1010
+ var selector = selectorData[selectorKey];
1011
+ if (selector.startsWith("@" /* Constant.At */)) {
1012
+ shouldMask = true;
1013
+ selector = selector.slice(1);
1014
+ }
1015
+ var nodes = document.querySelectorAll(selector);
1016
+ if (nodes) {
1017
+ var text = Array.from(nodes).map(function (e) { return e.textContent; }).join("<SEP>" /* Constant.Seperator */);
1018
+ update$1(key, selectorKey, (shouldMask ? hash(text).trim() : text).slice(0, 10000 /* Setting.ExtractLimit */));
1019
+ }
1020
+ }
1021
+ var hashData = hashes[key];
1022
+ for (var h in hashData) {
1023
+ var hashKey = parseInt(h);
1024
+ var content = hashText(hashData[hashKey]).trim().slice(0, 10000 /* Setting.ExtractLimit */);
1025
+ update$1(key, hashKey, content);
1026
+ }
971
1027
  }
1028
+ }
1029
+ if (keys.size > 0) {
1030
+ encode$1(40 /* Event.Extract */);
1031
+ }
1032
+ }
1033
+ catch (e) {
1034
+ log$1(5 /* Code.Selector */, 1 /* Severity.Warning */, e ? e.name : null);
1035
+ }
1036
+ }
1037
+ function reset$n() {
1038
+ keys.clear();
1039
+ }
1040
+ function update$1(key, subkey, value) {
1041
+ var update = false;
1042
+ if (!(key in data$e)) {
1043
+ data$e[key] = {};
1044
+ update = true;
1045
+ }
1046
+ if (!isEmpty(hashes[key])
1047
+ && (!(subkey in data$e[key]) || data$e[key][subkey] != value)) {
1048
+ update = true;
1049
+ }
1050
+ data$e[key][subkey] = value;
1051
+ if (update) {
1052
+ keys.add(key);
1053
+ }
1054
+ return;
1055
+ }
1056
+ function stop$z() {
1057
+ reset$n();
1058
+ }
1059
+ function parse$1(variable) {
1060
+ var syntax = [];
1061
+ var parts = variable.split("." /* Constant.Dot */);
1062
+ while (parts.length > 0) {
1063
+ var part = parts.shift();
1064
+ var arrayStart = part.indexOf("[" /* Constant.ArrayStart */);
1065
+ var conditionStart = part.indexOf("{" /* Constant.ConditionStart */);
1066
+ var conditionEnd = part.indexOf("}" /* Constant.ConditionEnd */);
1067
+ syntax.push({
1068
+ name: arrayStart > 0 ? part.slice(0, arrayStart) : (conditionStart > 0 ? part.slice(0, conditionStart) : part),
1069
+ type: arrayStart > 0 ? 1 /* Type.Array */ : (conditionStart > 0 ? 2 /* Type.Object */ : 3 /* Type.Simple */),
1070
+ condition: conditionStart > 0 ? part.slice(conditionStart + 1, conditionEnd) : null
972
1071
  });
973
- });
1072
+ }
1073
+ return syntax;
1074
+ }
1075
+ // The function below takes in a variable name in following format: "a.b.c" and safely evaluates its value in javascript context
1076
+ // For instance, for a.b.c, it will first check window["a"]. If it exists, it will recursively look at: window["a"]["b"] and finally,
1077
+ // return the value for window["a"]["b"]["c"].
1078
+ function evaluate(variable, base) {
1079
+ if (base === void 0) { base = window; }
1080
+ if (variable.length == 0) {
1081
+ return base;
1082
+ }
1083
+ var part = variable.shift();
1084
+ var output;
1085
+ if (base && base[part.name]) {
1086
+ var obj = base[part.name];
1087
+ if (part.type !== 1 /* Type.Array */ && match(obj, part.condition)) {
1088
+ output = evaluate(variable, obj);
1089
+ }
1090
+ else if (Array.isArray(obj)) {
1091
+ var filtered = [];
1092
+ for (var _i = 0, obj_1 = obj; _i < obj_1.length; _i++) {
1093
+ var value = obj_1[_i];
1094
+ if (match(value, part.condition)) {
1095
+ var op = evaluate(variable, value);
1096
+ if (op) {
1097
+ filtered.push(op);
1098
+ }
1099
+ }
1100
+ }
1101
+ output = filtered;
1102
+ }
1103
+ return output;
1104
+ }
1105
+ return null;
1106
+ }
1107
+ function str$1(input) {
1108
+ // Automatically trim string to max of Setting.ExtractLimit to avoid fetching long strings
1109
+ return input ? JSON.stringify(input).slice(0, 10000 /* Setting.ExtractLimit */) : input;
1110
+ }
1111
+ function match(base, condition) {
1112
+ if (condition) {
1113
+ var prop = condition.split(":");
1114
+ return prop.length > 1 ? base[prop[0]] == prop[1] : base[prop[0]];
1115
+ }
1116
+ return true;
1117
+ }
1118
+ function isEmpty(obj) {
1119
+ return Object.keys(obj).length == 0;
974
1120
  }
975
1121
 
1122
+ var extract = /*#__PURE__*/Object.freeze({
1123
+ __proto__: null,
1124
+ clone: clone$1,
1125
+ compute: compute$a,
1126
+ data: data$e,
1127
+ keys: keys,
1128
+ reset: reset$n,
1129
+ start: start$C,
1130
+ stop: stop$z,
1131
+ trigger: trigger$2,
1132
+ update: update$1
1133
+ });
1134
+
976
1135
  var signalCallback = null;
977
1136
  function signal(cb) {
978
1137
  signalCallback = cb;
@@ -1012,244 +1171,46 @@ function stop$y() {
1012
1171
  // The ordering below should respect inter-module dependency.
1013
1172
  // E.g. if upgrade depends on upload, then upgrade needs to end before upload.
1014
1173
  // Similarly, if upload depends on metadata, upload needs to end before metadata.
1015
- modules$1.slice().reverse().forEach(function (x) { return measure(x.stop)(); });
1016
- stop$D();
1017
- }
1018
- function compute$a() {
1019
- compute$b();
1020
- compute$e();
1021
- compute$2();
1022
- compute$d();
1023
- compute$c();
1024
- compute$3();
1025
- compute$4();
1026
- }
1027
-
1028
- var history$5 = [];
1029
- var data$d;
1030
- function start$A() {
1031
- history$5 = [];
1032
- max(26 /* Metric.Automation */, navigator.webdriver ? 1 /* BooleanFlag.True */ : 0 /* BooleanFlag.False */);
1033
- try {
1034
- // some sites (unintentionally) overwrite the window.self property, so we also check for the main window object
1035
- max(31 /* Metric.Iframed */, window.top == window.self || window.top == window ? 1 /* IframeStatus.TopFrame */ : 2 /* IframeStatus.Iframe */);
1036
- }
1037
- catch (ex) {
1038
- max(31 /* Metric.Iframed */, 0 /* IframeStatus.Unknown */);
1039
- }
1040
- }
1041
- function check$4(id, target, input) {
1042
- // Compute hash for fraud detection, if enabled. Hash is computed only if input meets the minimum length criteria
1043
- if (config$2.fraud && id !== null && input && input.length >= 5 /* Setting.WordLength */) {
1044
- data$d = { id: id, target: target, checksum: hash(input, 28 /* Setting.ChecksumPrecision */) };
1045
- // Only encode this event if we haven't already reported this hash
1046
- if (history$5.indexOf(data$d.checksum) < 0) {
1047
- history$5.push(data$d.checksum);
1048
- encode$2(41 /* Event.Fraud */);
1049
- }
1050
- }
1051
- }
1052
-
1053
- // Track the start time to be able to compute duration at the end of the task
1054
- var idleTimeout = 5000;
1055
- var tracker = {};
1056
- var queuedTasks = [];
1057
- var activeTask = null;
1058
- var pauseTask = null;
1059
- var resumeResolve = null;
1060
- function pause$1() {
1061
- if (pauseTask === null) {
1062
- pauseTask = new Promise(function (resolve) {
1063
- resumeResolve = resolve;
1064
- });
1065
- }
1066
- }
1067
- function resume$1() {
1068
- if (pauseTask) {
1069
- resumeResolve();
1070
- pauseTask = null;
1071
- if (activeTask === null) {
1072
- run();
1073
- }
1074
- }
1075
- }
1076
- function reset$n() {
1077
- tracker = {};
1078
- queuedTasks = [];
1079
- activeTask = null;
1080
- pauseTask = null;
1081
- }
1082
- function schedule$1(task, priority) {
1083
- if (priority === void 0) { priority = 0 /* Priority.Normal */; }
1084
- return __awaiter(this, void 0, void 0, function () {
1085
- var _i, queuedTasks_1, q, promise;
1086
- return __generator(this, function (_a) {
1087
- // If this task is already scheduled, skip it
1088
- for (_i = 0, queuedTasks_1 = queuedTasks; _i < queuedTasks_1.length; _i++) {
1089
- q = queuedTasks_1[_i];
1090
- if (q.task === task) {
1091
- return [2 /*return*/];
1092
- }
1093
- }
1094
- promise = new Promise(function (resolve) {
1095
- var insert = priority === 1 /* Priority.High */ ? "unshift" : "push";
1096
- // Queue this task for asynchronous execution later
1097
- // We also store a unique page identifier (id) along with the task to ensure
1098
- // ensure that we do not accidentally execute this task in context of a different page
1099
- queuedTasks[insert]({ task: task, resolve: resolve, id: id() });
1100
- });
1101
- // If there is no active task running, and Clarity is not in pause state,
1102
- // invoke the first task in the queue synchronously. This ensures that we don't yield the thread during unload event
1103
- if (activeTask === null && pauseTask === null) {
1104
- run();
1105
- }
1106
- return [2 /*return*/, promise];
1107
- });
1108
- });
1109
- }
1110
- function run() {
1111
- var entry = queuedTasks.shift();
1112
- if (entry) {
1113
- activeTask = entry;
1114
- entry.task().then(function () {
1115
- // Bail out if the context in which this task was operating is different from the current page
1116
- // An example scenario where task could span across pages is Single Page Applications (SPA)
1117
- // A task that started on page #1, but completes on page #2
1118
- if (entry.id !== id()) {
1119
- return;
1120
- }
1121
- entry.resolve();
1122
- activeTask = null; // Reset active task back to null now that the promise is resolved
1123
- run();
1124
- }).catch(function (error) {
1125
- // If one of the scheduled tasks failed, log, recover and continue processing rest of the tasks
1126
- if (entry.id !== id()) {
1127
- return;
1128
- }
1129
- if (error) {
1130
- log$1(0 /* Code.RunTask */, 1 /* Severity.Warning */, error.name, error.message, error.stack);
1131
- }
1132
- activeTask = null;
1133
- run();
1134
- });
1135
- }
1136
- }
1137
- function state$a(timer) {
1138
- var id = key(timer);
1139
- if (id in tracker) {
1140
- var elapsed = performance.now() - tracker[id].start;
1141
- return (elapsed > tracker[id].yield) ? 0 /* Task.Wait */ : 1 /* Task.Run */;
1142
- }
1143
- // If this task is no longer being tracked, send stop message to the caller
1144
- return 2 /* Task.Stop */;
1145
- }
1146
- function start$z(timer) {
1147
- tracker[key(timer)] = { start: performance.now(), calls: 0, yield: 30 /* Setting.LongTask */ };
1148
- }
1149
- function restart$2(timer) {
1150
- var id = key(timer);
1151
- if (tracker && tracker[id]) {
1152
- var c = tracker[id].calls;
1153
- var y = tracker[id].yield;
1154
- start$z(timer);
1155
- tracker[id].calls = c + 1;
1156
- tracker[id].yield = y;
1157
- }
1158
- }
1159
- function stop$x(timer) {
1160
- var end = performance.now();
1161
- var id = key(timer);
1162
- var duration = end - tracker[id].start;
1163
- sum(timer.cost, duration);
1164
- count$1(5 /* Metric.InvokeCount */);
1165
- // For the first execution, which is synchronous, time is automatically counted towards TotalDuration.
1166
- // However, for subsequent asynchronous runs, we need to manually update TotalDuration metric.
1167
- if (tracker[id].calls > 0) {
1168
- sum(4 /* Metric.TotalCost */, duration);
1169
- }
1170
- }
1171
- function suspend$1(timer) {
1172
- var _a;
1173
- return __awaiter(this, void 0, void 0, function () {
1174
- var id, _b;
1175
- return __generator(this, function (_c) {
1176
- switch (_c.label) {
1177
- case 0:
1178
- id = key(timer);
1179
- if (!(id in tracker)) return [3 /*break*/, 2];
1180
- stop$x(timer);
1181
- // some customer polyfills for requestIdleCallback return null
1182
- _b = tracker[id];
1183
- return [4 /*yield*/, wait()];
1184
- case 1:
1185
- // some customer polyfills for requestIdleCallback return null
1186
- _b.yield = ((_a = (_c.sent())) === null || _a === void 0 ? void 0 : _a.timeRemaining()) || 30 /* Setting.LongTask */;
1187
- restart$2(timer);
1188
- _c.label = 2;
1189
- case 2:
1190
- // After we are done with suspending task, ensure that we are still operating in the right context
1191
- // If the task is still being tracked, continue running the task, otherwise ask caller to stop execution
1192
- return [2 /*return*/, id in tracker ? 1 /* Task.Run */ : 2 /* Task.Stop */];
1193
- }
1194
- });
1195
- });
1196
- }
1197
- function key(timer) {
1198
- return "".concat(timer.id, ".").concat(timer.cost);
1174
+ modules$1.slice().reverse().forEach(function (x) { return measure(x.stop)(); });
1175
+ stop$D();
1199
1176
  }
1200
- function wait() {
1201
- return __awaiter(this, void 0, void 0, function () {
1202
- return __generator(this, function (_a) {
1203
- switch (_a.label) {
1204
- case 0:
1205
- if (!pauseTask) return [3 /*break*/, 2];
1206
- return [4 /*yield*/, pauseTask];
1207
- case 1:
1208
- _a.sent();
1209
- _a.label = 2;
1210
- case 2: return [2 /*return*/, new Promise(function (resolve) {
1211
- requestIdleCallback(resolve, { timeout: idleTimeout });
1212
- })];
1213
- }
1214
- });
1215
- });
1177
+ function compute$9() {
1178
+ compute$b();
1179
+ compute$e();
1180
+ compute$2();
1181
+ compute$d();
1182
+ compute$c();
1183
+ compute$3();
1184
+ compute$a();
1185
+ }
1186
+
1187
+ var history$5 = [];
1188
+ var data$d;
1189
+ function start$A() {
1190
+ history$5 = [];
1191
+ max(26 /* Metric.Automation */, navigator.webdriver ? 1 /* BooleanFlag.True */ : 0 /* BooleanFlag.False */);
1192
+ try {
1193
+ // some sites (unintentionally) overwrite the window.self property, so we also check for the main window object
1194
+ max(31 /* Metric.Iframed */, window.top == window.self || window.top == window ? 1 /* IframeStatus.TopFrame */ : 2 /* IframeStatus.Iframe */);
1195
+ }
1196
+ catch (ex) {
1197
+ max(31 /* Metric.Iframed */, 0 /* IframeStatus.Unknown */);
1198
+ }
1216
1199
  }
1217
- // Use native implementation of requestIdleCallback if it exists.
1218
- // Otherwise, fall back to a custom implementation using requestAnimationFrame & MessageChannel.
1219
- // While it's not possible to build a perfect polyfill given the nature of this API, the following code attempts to get close.
1220
- // Background context: requestAnimationFrame invokes the js code right before: style, layout and paint computation within the frame.
1221
- // This means, that any code that runs as part of requestAnimationFrame will by default be blocking in nature. Not what we want.
1222
- // For non-blocking behavior, We need to know when browser has finished painting. This can be accomplished in two different ways (hacks):
1223
- // (1) Use MessageChannel to pass the message, and browser will receive the message right after paint event has occured.
1224
- // (2) Use setTimeout call within requestAnimationFrame. This also works, but there's a risk that browser may throttle setTimeout calls.
1225
- // Given this information, we are currently using (1) from above. More information on (2) as well as some additional context is below:
1226
- // https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Performance_best_practices_for_Firefox_fe_engineers
1227
- function requestIdleCallbackPolyfill(callback, options) {
1228
- var startTime = performance.now();
1229
- var channel = new MessageChannel();
1230
- var incoming = channel.port1;
1231
- var outgoing = channel.port2;
1232
- incoming.onmessage = function (event) {
1233
- var currentTime = performance.now();
1234
- var elapsed = currentTime - startTime;
1235
- var duration = currentTime - event.data;
1236
- if (duration > 30 /* Setting.LongTask */ && elapsed < options.timeout) {
1237
- requestAnimationFrame(function () { outgoing.postMessage(currentTime); });
1238
- }
1239
- else {
1240
- var didTimeout_1 = elapsed > options.timeout;
1241
- callback({
1242
- didTimeout: didTimeout_1,
1243
- timeRemaining: function () { return didTimeout_1 ? 30 /* Setting.LongTask */ : Math.max(0, 30 /* Setting.LongTask */ - duration); }
1244
- });
1200
+ function check$4(id, target, input) {
1201
+ // Compute hash for fraud detection, if enabled. Hash is computed only if input meets the minimum length criteria
1202
+ if (config$2.fraud && id !== null && input && input.length >= 5 /* Setting.WordLength */) {
1203
+ data$d = { id: id, target: target, checksum: hash(input, 28 /* Setting.ChecksumPrecision */) };
1204
+ // Only encode this event if we haven't already reported this hash
1205
+ if (history$5.indexOf(data$d.checksum) < 0) {
1206
+ history$5.push(data$d.checksum);
1207
+ encode$2(41 /* Event.Fraud */);
1245
1208
  }
1246
- };
1247
- requestAnimationFrame(function () { outgoing.postMessage(performance.now()); });
1248
- }
1249
- var requestIdleCallback = window["requestIdleCallback"] || requestIdleCallbackPolyfill;
1209
+ }
1210
+ }
1250
1211
 
1251
- var state$9 = [];
1252
- function start$y() {
1212
+ var state$a = [];
1213
+ function start$z() {
1253
1214
  reset$m();
1254
1215
  }
1255
1216
  function observe$c(root) {
@@ -1261,14 +1222,14 @@ function recompute$8(evt) {
1261
1222
  if (element) {
1262
1223
  var value = element.value;
1263
1224
  var checksum = value && value.length >= 5 /* Setting.WordLength */ && config$2.fraud && "password,secret,pass,social,ssn,code,hidden" /* Mask.Exclude */.indexOf(element.type) === -1 ? hash(value, 28 /* Setting.ChecksumPrecision */) : "" /* Constant.Empty */;
1264
- state$9.push({ time: time(evt), event: 42 /* Event.Change */, data: { target: target(evt), type: element.type, value: value, checksum: checksum } });
1265
- schedule$1(encode$3.bind(this, 42 /* Event.Change */));
1225
+ state$a.push({ time: time(evt), event: 42 /* Event.Change */, data: { target: target(evt), type: element.type, value: value, checksum: checksum } });
1226
+ schedule(encode$3.bind(this, 42 /* Event.Change */));
1266
1227
  }
1267
1228
  }
1268
1229
  function reset$m() {
1269
- state$9 = [];
1230
+ state$a = [];
1270
1231
  }
1271
- function stop$w() {
1232
+ function stop$x() {
1272
1233
  reset$m();
1273
1234
  }
1274
1235
 
@@ -1289,8 +1250,8 @@ function offset(element) {
1289
1250
  }
1290
1251
 
1291
1252
  var UserInputTags = ["input", "textarea", "radio", "button", "canvas", "select"];
1292
- var state$8 = [];
1293
- function start$x() {
1253
+ var state$9 = [];
1254
+ function start$y() {
1294
1255
  reset$l();
1295
1256
  }
1296
1257
  function observe$b(root) {
@@ -1326,7 +1287,7 @@ function handler$3(event, root, evt) {
1326
1287
  // Check for null values before processing this event
1327
1288
  if (x !== null && y !== null) {
1328
1289
  var textInfo = text(t);
1329
- state$8.push({
1290
+ state$9.push({
1330
1291
  time: time(evt),
1331
1292
  event: event,
1332
1293
  data: {
@@ -1345,7 +1306,7 @@ function handler$3(event, root, evt) {
1345
1306
  isFullText: textInfo.isFullText,
1346
1307
  }
1347
1308
  });
1348
- schedule$1(encode$3.bind(this, event));
1309
+ schedule(encode$3.bind(this, event));
1349
1310
  }
1350
1311
  }
1351
1312
  function link(node) {
@@ -1418,14 +1379,14 @@ function context(a) {
1418
1379
  return 0 /* BrowsingContext.Self */;
1419
1380
  }
1420
1381
  function reset$l() {
1421
- state$8 = [];
1382
+ state$9 = [];
1422
1383
  }
1423
- function stop$v() {
1384
+ function stop$w() {
1424
1385
  reset$l();
1425
1386
  }
1426
1387
 
1427
- var state$7 = [];
1428
- function start$w() {
1388
+ var state$8 = [];
1389
+ function start$x() {
1429
1390
  reset$k();
1430
1391
  }
1431
1392
  function observe$a(root) {
@@ -1435,19 +1396,19 @@ function observe$a(root) {
1435
1396
  }
1436
1397
  function recompute$7(action, evt) {
1437
1398
  recompute$7.dn = 7 /* FunctionNames.ClipboardRecompute */;
1438
- state$7.push({ time: time(evt), event: 38 /* Event.Clipboard */, data: { target: target(evt), action: action } });
1439
- schedule$1(encode$3.bind(this, 38 /* Event.Clipboard */));
1399
+ state$8.push({ time: time(evt), event: 38 /* Event.Clipboard */, data: { target: target(evt), action: action } });
1400
+ schedule(encode$3.bind(this, 38 /* Event.Clipboard */));
1440
1401
  }
1441
1402
  function reset$k() {
1442
- state$7 = [];
1403
+ state$8 = [];
1443
1404
  }
1444
- function stop$u() {
1405
+ function stop$v() {
1445
1406
  reset$k();
1446
1407
  }
1447
1408
 
1448
1409
  var timeout$6 = null;
1449
- var state$6 = [];
1450
- function start$v() {
1410
+ var state$7 = [];
1411
+ function start$w() {
1451
1412
  reset$j();
1452
1413
  }
1453
1414
  function observe$9(root) {
@@ -1468,31 +1429,31 @@ function recompute$6(evt) {
1468
1429
  }
1469
1430
  var data = { target: input, value: v, type: t };
1470
1431
  // If last entry in the queue is for the same target node as the current one, remove it so we can later swap it with current data.
1471
- if (state$6.length > 0 && (state$6[state$6.length - 1].data.target === data.target)) {
1472
- state$6.pop();
1432
+ if (state$7.length > 0 && (state$7[state$7.length - 1].data.target === data.target)) {
1433
+ state$7.pop();
1473
1434
  }
1474
- state$6.push({ time: time(evt), event: 27 /* Event.Input */, data: data });
1435
+ state$7.push({ time: time(evt), event: 27 /* Event.Input */, data: data });
1475
1436
  clearTimeout(timeout$6);
1476
1437
  timeout$6 = setTimeout(process$7, 1000 /* Setting.InputLookAhead */, 27 /* Event.Input */);
1477
1438
  }
1478
1439
  }
1479
1440
  function process$7(event) {
1480
- schedule$1(encode$3.bind(this, event));
1441
+ schedule(encode$3.bind(this, event));
1481
1442
  }
1482
1443
  function reset$j() {
1483
- state$6 = [];
1444
+ state$7 = [];
1484
1445
  }
1485
- function stop$t() {
1446
+ function stop$u() {
1486
1447
  clearTimeout(timeout$6);
1487
1448
  reset$j();
1488
1449
  }
1489
1450
 
1490
- var state$5 = [];
1451
+ var state$6 = [];
1491
1452
  var timeout$5 = null;
1492
1453
  var hasPrimaryTouch = false;
1493
1454
  var primaryTouchId = 0;
1494
1455
  var activeTouchPointIds = new Set();
1495
- function start$u() {
1456
+ function start$v() {
1496
1457
  reset$i();
1497
1458
  }
1498
1459
  function observe$8(root) {
@@ -1572,26 +1533,26 @@ function handler$2(current) {
1572
1533
  case 12 /* Event.MouseMove */:
1573
1534
  case 15 /* Event.MouseWheel */:
1574
1535
  case 19 /* Event.TouchMove */:
1575
- var length_1 = state$5.length;
1576
- var last = length_1 > 1 ? state$5[length_1 - 2] : null;
1536
+ var length_1 = state$6.length;
1537
+ var last = length_1 > 1 ? state$6[length_1 - 2] : null;
1577
1538
  if (last && similar$1(last, current)) {
1578
- state$5.pop();
1539
+ state$6.pop();
1579
1540
  }
1580
- state$5.push(current);
1541
+ state$6.push(current);
1581
1542
  clearTimeout(timeout$5);
1582
1543
  timeout$5 = setTimeout(process$6, 500 /* Setting.LookAhead */, current.event);
1583
1544
  break;
1584
1545
  default:
1585
- state$5.push(current);
1546
+ state$6.push(current);
1586
1547
  process$6(current.event);
1587
1548
  break;
1588
1549
  }
1589
1550
  }
1590
1551
  function process$6(event) {
1591
- schedule$1(encode$3.bind(this, event));
1552
+ schedule(encode$3.bind(this, event));
1592
1553
  }
1593
1554
  function reset$i() {
1594
- state$5 = [];
1555
+ state$6 = [];
1595
1556
  }
1596
1557
  function similar$1(last, current) {
1597
1558
  var dx = last.data.x - current.data.x;
@@ -1601,18 +1562,18 @@ function similar$1(last, current) {
1601
1562
  var match = current.data.target === last.data.target;
1602
1563
  return current.event === last.event && match && distance < 20 /* Setting.Distance */ && gap < 25 /* Setting.Interval */;
1603
1564
  }
1604
- function stop$s() {
1565
+ function stop$t() {
1605
1566
  clearTimeout(timeout$5);
1606
1567
  // Send out any pending pointer events in the pipeline
1607
- if (state$5.length > 0) {
1608
- process$6(state$5[state$5.length - 1].event);
1568
+ if (state$6.length > 0) {
1569
+ process$6(state$6[state$6.length - 1].event);
1609
1570
  }
1610
1571
  }
1611
1572
 
1612
1573
  var data$c;
1613
1574
  var timeout$4 = null;
1614
1575
  var initialStateLogged = false;
1615
- function start$t() {
1576
+ function start$u() {
1616
1577
  initialStateLogged = false;
1617
1578
  bind(window, "resize", recompute$5);
1618
1579
  recompute$5();
@@ -1636,22 +1597,22 @@ function recompute$5() {
1636
1597
  }
1637
1598
  }
1638
1599
  function process$5(event) {
1639
- schedule$1(encode$3.bind(this, event));
1600
+ schedule(encode$3.bind(this, event));
1640
1601
  }
1641
1602
  function reset$h() {
1642
1603
  data$c = null;
1643
1604
  clearTimeout(timeout$4);
1644
1605
  }
1645
- function stop$r() {
1606
+ function stop$s() {
1646
1607
  reset$h();
1647
1608
  }
1648
1609
 
1649
- var state$4 = [];
1610
+ var state$5 = [];
1650
1611
  var initialTop = null;
1651
1612
  var initialBottom = null;
1652
1613
  var timeout$3 = null;
1653
- function start$s() {
1654
- state$4 = [];
1614
+ function start$t() {
1615
+ state$5 = [];
1655
1616
  recompute$4();
1656
1617
  }
1657
1618
  function observe$7(root) {
@@ -1691,12 +1652,12 @@ function recompute$4(event) {
1691
1652
  initialBottom = bottom;
1692
1653
  return;
1693
1654
  }
1694
- var length = state$4.length;
1695
- var last = length > 1 ? state$4[length - 2] : null;
1655
+ var length = state$5.length;
1656
+ var last = length > 1 ? state$5[length - 2] : null;
1696
1657
  if (last && similar(last, current)) {
1697
- state$4.pop();
1658
+ state$5.pop();
1698
1659
  }
1699
- state$4.push(current);
1660
+ state$5.push(current);
1700
1661
  clearTimeout(timeout$3);
1701
1662
  timeout$3 = setTimeout(process$4, 500 /* Setting.LookAhead */, 10 /* Event.Scroll */);
1702
1663
  }
@@ -1718,21 +1679,21 @@ function getPositionNode(x, y) {
1718
1679
  return node;
1719
1680
  }
1720
1681
  function reset$g() {
1721
- state$4 = [];
1682
+ state$5 = [];
1722
1683
  initialTop = null;
1723
1684
  initialBottom = null;
1724
1685
  }
1725
1686
  function process$4(event) {
1726
- schedule$1(encode$3.bind(this, event));
1687
+ schedule(encode$3.bind(this, event));
1727
1688
  }
1728
1689
  function similar(last, current) {
1729
1690
  var dx = last.data.x - current.data.x;
1730
1691
  var dy = last.data.y - current.data.y;
1731
1692
  return (dx * dx + dy * dy < 20 /* Setting.Distance */ * 20 /* Setting.Distance */) && (current.time - last.time < 25 /* Setting.Interval */);
1732
1693
  }
1733
- function compute$9() {
1694
+ function compute$8() {
1734
1695
  var _a, _b;
1735
- compute$9.dn = 14 /* FunctionNames.ScrollCompute */;
1696
+ compute$8.dn = 14 /* FunctionNames.ScrollCompute */;
1736
1697
  if (initialTop) {
1737
1698
  var top_1 = metadata$2(initialTop, null);
1738
1699
  log(31 /* Dimension.InitialScrollTop */, (_a = top_1 === null || top_1 === void 0 ? void 0 : top_1.hash) === null || _a === void 0 ? void 0 : _a.join("." /* Constant.Dot */));
@@ -1742,9 +1703,9 @@ function compute$9() {
1742
1703
  log(32 /* Dimension.InitialScrollBottom */, (_b = bottom === null || bottom === void 0 ? void 0 : bottom.hash) === null || _b === void 0 ? void 0 : _b.join("." /* Constant.Dot */));
1743
1704
  }
1744
1705
  }
1745
- function stop$q() {
1706
+ function stop$r() {
1746
1707
  clearTimeout(timeout$3);
1747
- state$4 = [];
1708
+ state$5 = [];
1748
1709
  initialTop = null;
1749
1710
  initialBottom = null;
1750
1711
  }
@@ -1752,7 +1713,7 @@ function stop$q() {
1752
1713
  var data$b = null;
1753
1714
  var previous = null;
1754
1715
  var timeout$2 = null;
1755
- function start$r() {
1716
+ function start$s() {
1756
1717
  reset$f();
1757
1718
  }
1758
1719
  function observe$6(root) {
@@ -1791,19 +1752,19 @@ function recompute$3(root) {
1791
1752
  timeout$2 = setTimeout(process$3, 500 /* Setting.LookAhead */, 21 /* Event.Selection */);
1792
1753
  }
1793
1754
  function process$3(event) {
1794
- schedule$1(encode$3.bind(this, event));
1755
+ schedule(encode$3.bind(this, event));
1795
1756
  }
1796
1757
  function reset$f() {
1797
1758
  previous = null;
1798
1759
  data$b = { start: 0, startOffset: 0, end: 0, endOffset: 0 };
1799
1760
  }
1800
- function stop$p() {
1761
+ function stop$q() {
1801
1762
  reset$f();
1802
1763
  clearTimeout(timeout$2);
1803
1764
  }
1804
1765
 
1805
- var state$3 = [];
1806
- function start$q() {
1766
+ var state$4 = [];
1767
+ function start$r() {
1807
1768
  reset$e();
1808
1769
  }
1809
1770
  function observe$5(root) {
@@ -1811,18 +1772,18 @@ function observe$5(root) {
1811
1772
  }
1812
1773
  function recompute$2(evt) {
1813
1774
  recompute$2.dn = 16 /* FunctionNames.SubmitRecompute */;
1814
- state$3.push({ time: time(evt), event: 39 /* Event.Submit */, data: { target: target(evt) } });
1815
- schedule$1(encode$3.bind(this, 39 /* Event.Submit */));
1775
+ state$4.push({ time: time(evt), event: 39 /* Event.Submit */, data: { target: target(evt) } });
1776
+ schedule(encode$3.bind(this, 39 /* Event.Submit */));
1816
1777
  }
1817
1778
  function reset$e() {
1818
- state$3 = [];
1779
+ state$4 = [];
1819
1780
  }
1820
- function stop$o() {
1781
+ function stop$p() {
1821
1782
  reset$e();
1822
1783
  }
1823
1784
 
1824
1785
  var data$a;
1825
- function start$p() {
1786
+ function start$q() {
1826
1787
  bind(window, "pagehide", recompute$1);
1827
1788
  }
1828
1789
  function recompute$1(evt) {
@@ -1834,12 +1795,12 @@ function recompute$1(evt) {
1834
1795
  function reset$d() {
1835
1796
  data$a = null;
1836
1797
  }
1837
- function stop$n() {
1798
+ function stop$o() {
1838
1799
  reset$d();
1839
1800
  }
1840
1801
 
1841
1802
  var data$9;
1842
- function start$o() {
1803
+ function start$p() {
1843
1804
  bind(document, "visibilitychange", recompute);
1844
1805
  recompute();
1845
1806
  }
@@ -1852,38 +1813,38 @@ function recompute(evt) {
1852
1813
  function reset$c() {
1853
1814
  data$9 = null;
1854
1815
  }
1855
- function stop$m() {
1816
+ function stop$n() {
1856
1817
  reset$c();
1857
1818
  }
1858
1819
 
1859
- function start$n() {
1860
- start$n.dn = 8 /* FunctionNames.InteractionStart */;
1861
- start$g();
1820
+ function start$o() {
1821
+ start$o.dn = 8 /* FunctionNames.InteractionStart */;
1822
+ start$h();
1823
+ start$y();
1862
1824
  start$x();
1825
+ start$v();
1863
1826
  start$w();
1864
1827
  start$u();
1865
- start$v();
1828
+ start$p();
1866
1829
  start$t();
1867
- start$o();
1868
1830
  start$s();
1831
+ start$z();
1869
1832
  start$r();
1870
- start$y();
1871
1833
  start$q();
1872
- start$p();
1873
1834
  }
1874
- function stop$l() {
1875
- stop$e();
1835
+ function stop$m() {
1836
+ stop$f();
1837
+ stop$w();
1876
1838
  stop$v();
1839
+ stop$t();
1877
1840
  stop$u();
1878
1841
  stop$s();
1879
- stop$t();
1842
+ stop$n();
1880
1843
  stop$r();
1881
- stop$m();
1882
1844
  stop$q();
1845
+ stop$x();
1883
1846
  stop$p();
1884
- stop$w();
1885
1847
  stop$o();
1886
- stop$n();
1887
1848
  }
1888
1849
  function observe$4(root) {
1889
1850
  observe$7(root);
@@ -1903,8 +1864,8 @@ function observe$4(root) {
1903
1864
  var interaction = /*#__PURE__*/Object.freeze({
1904
1865
  __proto__: null,
1905
1866
  observe: observe$4,
1906
- start: start$n,
1907
- stop: stop$l
1867
+ start: start$o,
1868
+ stop: stop$m
1908
1869
  });
1909
1870
 
1910
1871
  // Following code takes an array of tokens and transforms it to optimize for repeating tokens and make it efficient to send over the wire
@@ -1952,17 +1913,19 @@ function tokenize (tokens) {
1952
1913
 
1953
1914
  var sheetUpdateState = [];
1954
1915
  var sheetAdoptionState = [];
1955
- var replace = null;
1956
- var replaceSync = null;
1957
1916
  var styleSheetId = 'claritySheetId';
1958
1917
  var styleSheetMap = {};
1959
1918
  var styleTimeMap = {};
1960
1919
  var documentNodes = [];
1961
1920
  var createdSheetIds = [];
1962
- function start$m() {
1963
- if (window['CSSStyleSheet'] && CSSStyleSheet.prototype) {
1964
- if (replace === null) {
1965
- replace = CSSStyleSheet.prototype.replace;
1921
+ function proxyStyleRules$1(win) {
1922
+ if ((config$2.lean && config$2.lite) || win === null || win === undefined) {
1923
+ return;
1924
+ }
1925
+ win.clarityOverrides = win.clarityOverrides || {};
1926
+ if (win['CSSStyleSheet'] && win.CSSStyleSheet.prototype) {
1927
+ if (win.clarityOverrides.replace === undefined) {
1928
+ win.clarityOverrides.replace = CSSStyleSheet.prototype.replace;
1966
1929
  CSSStyleSheet.prototype.replace = function () {
1967
1930
  if (active()) {
1968
1931
  max(36 /* Metric.ConstructedStyles */, 1);
@@ -1973,11 +1936,11 @@ function start$m() {
1973
1936
  trackStyleChange(time(), this[styleSheetId], 1 /* StyleSheetOperation.Replace */, arguments[0]);
1974
1937
  }
1975
1938
  }
1976
- return replace.apply(this, arguments);
1939
+ return win.clarityOverrides.replace.apply(this, arguments);
1977
1940
  };
1978
1941
  }
1979
- if (replaceSync === null) {
1980
- replaceSync = CSSStyleSheet.prototype.replaceSync;
1942
+ if (win.clarityOverrides.replaceSync === undefined) {
1943
+ win.clarityOverrides.replaceSync = CSSStyleSheet.prototype.replaceSync;
1981
1944
  CSSStyleSheet.prototype.replaceSync = function () {
1982
1945
  if (active()) {
1983
1946
  max(36 /* Metric.ConstructedStyles */, 1);
@@ -1988,14 +1951,23 @@ function start$m() {
1988
1951
  trackStyleChange(time(), this[styleSheetId], 2 /* StyleSheetOperation.ReplaceSync */, arguments[0]);
1989
1952
  }
1990
1953
  }
1991
- return replaceSync.apply(this, arguments);
1954
+ return win.clarityOverrides.replaceSync.apply(this, arguments);
1992
1955
  };
1993
1956
  }
1994
1957
  }
1995
1958
  }
1959
+ function start$n() {
1960
+ proxyStyleRules$1(window);
1961
+ }
1996
1962
  function checkDocumentStyles(documentNode, timestamp) {
1963
+ if (config$2.lean && config$2.lite) {
1964
+ return;
1965
+ }
1997
1966
  if (documentNodes.indexOf(documentNode) === -1) {
1998
1967
  documentNodes.push(documentNode);
1968
+ if (documentNode.defaultView) {
1969
+ proxyStyleRules$1(documentNode.defaultView);
1970
+ }
1999
1971
  }
2000
1972
  timestamp = timestamp || time();
2001
1973
  if (!(documentNode === null || documentNode === void 0 ? void 0 : documentNode.adoptedStyleSheets)) {
@@ -2029,7 +2001,7 @@ function checkDocumentStyles(documentNode, timestamp) {
2029
2001
  styleTimeMap[documentId] = timestamp;
2030
2002
  }
2031
2003
  }
2032
- function compute$8() {
2004
+ function compute$7() {
2033
2005
  for (var _i = 0, documentNodes_1 = documentNodes; _i < documentNodes_1.length; _i++) {
2034
2006
  var documentNode = documentNodes_1[_i];
2035
2007
  var docId = documentNode == document ? -1 : getId(documentNode);
@@ -2041,7 +2013,7 @@ function reset$b() {
2041
2013
  sheetAdoptionState = [];
2042
2014
  sheetUpdateState = [];
2043
2015
  }
2044
- function stop$k() {
2016
+ function stop$l() {
2045
2017
  styleSheetMap = {};
2046
2018
  styleTimeMap = {};
2047
2019
  documentNodes = [];
@@ -2079,7 +2051,7 @@ function arraysEqual(a, b) {
2079
2051
  return a.every(function (value, index) { return value === b[index]; });
2080
2052
  }
2081
2053
 
2082
- var state$2 = [];
2054
+ var state$3 = [];
2083
2055
  var elementAnimate = null;
2084
2056
  var animationPlay = null;
2085
2057
  var animationPause = null;
@@ -2089,7 +2061,7 @@ var animationFinish = null;
2089
2061
  var animationId = 'clarityAnimationId';
2090
2062
  var operationCount = 'clarityOperationCount';
2091
2063
  var maxOperations = 20;
2092
- function start$l() {
2064
+ function start$m() {
2093
2065
  if (window["Animation"] &&
2094
2066
  window["Animation"].prototype &&
2095
2067
  window["KeyframeEffect"] &&
@@ -2127,10 +2099,10 @@ function start$l() {
2127
2099
  }
2128
2100
  }
2129
2101
  function reset$a() {
2130
- state$2 = [];
2102
+ state$3 = [];
2131
2103
  }
2132
2104
  function track$6(time, id, operation, keyFrames, timing, targetId, timeline) {
2133
- state$2.push({
2105
+ state$3.push({
2134
2106
  time: time,
2135
2107
  event: 44 /* Event.Animation */,
2136
2108
  data: {
@@ -2144,7 +2116,7 @@ function track$6(time, id, operation, keyFrames, timing, targetId, timeline) {
2144
2116
  });
2145
2117
  encode$4(44 /* Event.Animation */);
2146
2118
  }
2147
- function stop$j() {
2119
+ function stop$k() {
2148
2120
  reset$a();
2149
2121
  }
2150
2122
  function overrideAnimationHelper(functionToOverride, name) {
@@ -2199,7 +2171,7 @@ function encode$4 (type, timer, ts) {
2199
2171
  if (timer === void 0) { timer = null; }
2200
2172
  if (ts === void 0) { ts = null; }
2201
2173
  return __awaiter(this, void 0, void 0, function () {
2202
- var eventTime, tokens, _a, d, _i, _b, r, _c, _d, entry, _e, _f, entry, _g, _h, entry, values, _j, values_1, value, state, data, active, suspend, privacy, mangle, keys, _k, keys_1, key, box, factor, attr;
2174
+ var eventTime, tokens, _a, d, _i, _b, r, _c, _d, entry, _e, _f, entry, _g, _h, entry, values, _j, values_1, value, state$1, data, active, suspend, privacy, mangle, keys, _k, keys_1, key, box, factor, attr;
2203
2175
  return __generator(this, function (_l) {
2204
2176
  switch (_l.label) {
2205
2177
  case 0:
@@ -2224,7 +2196,7 @@ function encode$4 (type, timer, ts) {
2224
2196
  queue(tokens);
2225
2197
  return [3 /*break*/, 12];
2226
2198
  case 2:
2227
- for (_i = 0, _b = state$1; _i < _b.length; _i++) {
2199
+ for (_i = 0, _b = state$2; _i < _b.length; _i++) {
2228
2200
  r = _b[_i];
2229
2201
  tokens = [r.time, 7 /* Event.Region */];
2230
2202
  tokens.push(r.data.id);
@@ -2255,7 +2227,7 @@ function encode$4 (type, timer, ts) {
2255
2227
  reset$b();
2256
2228
  return [3 /*break*/, 12];
2257
2229
  case 4:
2258
- for (_g = 0, _h = state$2; _g < _h.length; _g++) {
2230
+ for (_g = 0, _h = state$3; _g < _h.length; _g++) {
2259
2231
  entry = _h[_g];
2260
2232
  tokens = [entry.time, entry.event];
2261
2233
  tokens.push(entry.data.id);
@@ -2270,7 +2242,7 @@ function encode$4 (type, timer, ts) {
2270
2242
  return [3 /*break*/, 12];
2271
2243
  case 5:
2272
2244
  // Check if we are operating within the context of the current page
2273
- if (state$a(timer) === 2 /* Task.Stop */) {
2245
+ if (state(timer) === 2 /* Task.Stop */) {
2274
2246
  return [3 /*break*/, 12];
2275
2247
  }
2276
2248
  values = updates$2();
@@ -2280,14 +2252,14 @@ function encode$4 (type, timer, ts) {
2280
2252
  case 6:
2281
2253
  if (!(_j < values_1.length)) return [3 /*break*/, 10];
2282
2254
  value = values_1[_j];
2283
- state = state$a(timer);
2284
- if (!(state === 0 /* Task.Wait */)) return [3 /*break*/, 8];
2255
+ state$1 = state(timer);
2256
+ if (!(state$1 === 0 /* Task.Wait */)) return [3 /*break*/, 8];
2285
2257
  return [4 /*yield*/, suspend$1(timer)];
2286
2258
  case 7:
2287
- state = _l.sent();
2259
+ state$1 = _l.sent();
2288
2260
  _l.label = 8;
2289
2261
  case 8:
2290
- if (state === 2 /* Task.Stop */) {
2262
+ if (state$1 === 2 /* Task.Stop */) {
2291
2263
  return [3 /*break*/, 10];
2292
2264
  }
2293
2265
  data = value.data;
@@ -2314,7 +2286,7 @@ function encode$4 (type, timer, ts) {
2314
2286
  }
2315
2287
  tokens.push(suspend ? "*M" /* Constant.SuspendMutationTag */ : data[key]);
2316
2288
  if (box && box.length === 2) {
2317
- tokens.push("".concat("#" /* Constant.Hash */).concat(str$1(box[0]), ".").concat(str$1(box[1])));
2289
+ tokens.push("".concat("#" /* Constant.Hash */).concat(str(box[0]), ".").concat(str(box[1])));
2318
2290
  }
2319
2291
  break;
2320
2292
  case "attributes":
@@ -2360,7 +2332,7 @@ function size(value) {
2360
2332
  }
2361
2333
  return value.metadata.size;
2362
2334
  }
2363
- function str$1(input) {
2335
+ function str(input) {
2364
2336
  return input.toString(36);
2365
2337
  }
2366
2338
  function attribute(key, value, privacy) {
@@ -2371,12 +2343,12 @@ var data$8;
2371
2343
  function reset$9() {
2372
2344
  data$8 = null;
2373
2345
  }
2374
- function start$k() {
2346
+ function start$l() {
2375
2347
  reset$9();
2376
- compute$7();
2348
+ compute$6();
2377
2349
  }
2378
- function compute$7() {
2379
- compute$7.dn = 19 /* FunctionNames.DocumentCompute */;
2350
+ function compute$6() {
2351
+ compute$6.dn = 19 /* FunctionNames.DocumentCompute */;
2380
2352
  var body = document.body;
2381
2353
  var d = document.documentElement;
2382
2354
  var bodyClientWidth = body ? body.clientWidth : null;
@@ -2399,13 +2371,13 @@ function compute$7() {
2399
2371
  encode$4(8 /* Event.Document */);
2400
2372
  }
2401
2373
  }
2402
- function stop$i() {
2374
+ function stop$j() {
2403
2375
  reset$9();
2404
2376
  }
2405
2377
 
2406
2378
  function traverse (root, timer, source, timestamp) {
2407
2379
  return __awaiter(this, void 0, void 0, function () {
2408
- var queue, entry, next, state, subnode;
2380
+ var queue, entry, next, state$1, subnode;
2409
2381
  return __generator(this, function (_a) {
2410
2382
  switch (_a.label) {
2411
2383
  case 0:
@@ -2419,14 +2391,14 @@ function traverse (root, timer, source, timestamp) {
2419
2391
  queue.push(next);
2420
2392
  next = next.nextSibling;
2421
2393
  }
2422
- state = state$a(timer);
2423
- if (!(state === 0 /* Task.Wait */)) return [3 /*break*/, 3];
2394
+ state$1 = state(timer);
2395
+ if (!(state$1 === 0 /* Task.Wait */)) return [3 /*break*/, 3];
2424
2396
  return [4 /*yield*/, suspend$1(timer)];
2425
2397
  case 2:
2426
- state = _a.sent();
2398
+ state$1 = _a.sent();
2427
2399
  _a.label = 3;
2428
2400
  case 3:
2429
- if (state === 2 /* Task.Stop */) {
2401
+ if (state$1 === 2 /* Task.Stop */) {
2430
2402
  return [3 /*break*/, 4];
2431
2403
  }
2432
2404
  subnode = processNode(entry, source, timestamp);
@@ -2436,93 +2408,30 @@ function traverse (root, timer, source, timestamp) {
2436
2408
  return [3 /*break*/, 1];
2437
2409
  case 4: return [2 /*return*/];
2438
2410
  }
2439
- });
2440
- });
2441
- }
2442
-
2443
- var observers = new Set();
2444
- var mutations = [];
2445
- var throttledMutations = {};
2446
- var insertRule = null;
2447
- var deleteRule = null;
2448
- var attachShadow = null;
2449
- var mediaInsertRule = null;
2450
- var mediaDeleteRule = null;
2451
- var queue$2 = [];
2452
- var timeout$1 = null;
2453
- var throttleDelay = null;
2454
- var activePeriod = null;
2455
- var history$4 = {};
2456
- var observedNodes = new WeakMap();
2457
- // We ignore mutations if these attributes are updated
2458
- var IGNORED_ATTRIBUTES = ["data-google-query-id", "data-load-complete", "data-google-container-id"];
2459
- function start$j() {
2460
- start$j.dn = 21 /* FunctionNames.MutationStart */;
2461
- observers = new Set();
2462
- queue$2 = [];
2463
- timeout$1 = null;
2464
- activePeriod = 0;
2465
- history$4 = {};
2466
- observedNodes = new WeakMap();
2467
- // Some popular open source libraries, like styled-components, optimize performance
2468
- // by injecting CSS using insertRule API vs. appending text node. A side effect of
2469
- // using javascript API is that it doesn't trigger DOM mutation and therefore we
2470
- // need to override the insertRule API and listen for changes manually.
2471
- if (insertRule === null) {
2472
- insertRule = CSSStyleSheet.prototype.insertRule;
2473
- CSSStyleSheet.prototype.insertRule = function () {
2474
- if (active()) {
2475
- schedule(this.ownerNode);
2476
- }
2477
- return insertRule.apply(this, arguments);
2478
- };
2479
- }
2480
- if ("CSSMediaRule" in window && mediaInsertRule === null) {
2481
- mediaInsertRule = CSSMediaRule.prototype.insertRule;
2482
- CSSMediaRule.prototype.insertRule = function () {
2483
- if (active()) {
2484
- schedule(this.parentStyleSheet.ownerNode);
2485
- }
2486
- return mediaInsertRule.apply(this, arguments);
2487
- };
2488
- }
2489
- if (deleteRule === null) {
2490
- deleteRule = CSSStyleSheet.prototype.deleteRule;
2491
- CSSStyleSheet.prototype.deleteRule = function () {
2492
- if (active()) {
2493
- schedule(this.ownerNode);
2494
- }
2495
- return deleteRule.apply(this, arguments);
2496
- };
2497
- }
2498
- if ("CSSMediaRule" in window && mediaDeleteRule === null) {
2499
- mediaDeleteRule = CSSMediaRule.prototype.deleteRule;
2500
- CSSMediaRule.prototype.deleteRule = function () {
2501
- if (active()) {
2502
- schedule(this.parentStyleSheet.ownerNode);
2503
- }
2504
- return mediaDeleteRule.apply(this, arguments);
2505
- };
2506
- }
2507
- // Add a hook to attachShadow API calls
2508
- // In case we are unable to add a hook and browser throws an exception,
2509
- // reset attachShadow variable and resume processing like before
2510
- if (attachShadow === null) {
2511
- attachShadow = Element.prototype.attachShadow;
2512
- try {
2513
- Element.prototype.attachShadow = function () {
2514
- if (active()) {
2515
- return schedule(attachShadow.apply(this, arguments));
2516
- }
2517
- else {
2518
- return attachShadow.apply(this, arguments);
2519
- }
2520
- };
2521
- }
2522
- catch (_a) {
2523
- attachShadow = null;
2524
- }
2525
- }
2411
+ });
2412
+ });
2413
+ }
2414
+
2415
+ var observers = new Set();
2416
+ var mutations = [];
2417
+ var throttledMutations = {};
2418
+ var queue$2 = [];
2419
+ var timeout$1 = null;
2420
+ var throttleDelay = null;
2421
+ var activePeriod = null;
2422
+ var history$4 = {};
2423
+ var observedNodes = new WeakMap();
2424
+ // We ignore mutations if these attributes are updated
2425
+ var IGNORED_ATTRIBUTES = ["data-google-query-id", "data-load-complete", "data-google-container-id"];
2426
+ function start$k() {
2427
+ start$k.dn = 21 /* FunctionNames.MutationStart */;
2428
+ observers = new Set();
2429
+ queue$2 = [];
2430
+ timeout$1 = null;
2431
+ activePeriod = 0;
2432
+ history$4 = {};
2433
+ observedNodes = new WeakMap();
2434
+ proxyStyleRules(window);
2526
2435
  }
2527
2436
  function observe$3(node) {
2528
2437
  // Create a new observer for every time a new DOM tree (e.g. root document or shadowdom root) is discovered on the page
@@ -2537,6 +2446,9 @@ function observe$3(node) {
2537
2446
  observedNodes.set(node, observer);
2538
2447
  observers.add(observer);
2539
2448
  }
2449
+ if (node['defaultView']) {
2450
+ proxyStyleRules(node['defaultView']);
2451
+ }
2540
2452
  }
2541
2453
  catch (e) {
2542
2454
  log$1(2 /* Code.MutationObserver */, 0 /* Severity.Info */, e ? e.name : null);
@@ -2550,7 +2462,7 @@ function monitor(frame) {
2550
2462
  bind(frame, "load" /* Constant.LoadEvent */, generate.bind(this, frame, "childList" /* Constant.ChildList */), true);
2551
2463
  }
2552
2464
  }
2553
- function stop$h() {
2465
+ function stop$i() {
2554
2466
  for (var _i = 0, _a = Array.from(observers); _i < _a.length; _i++) {
2555
2467
  var observer = _a[_i];
2556
2468
  if (observer) {
@@ -2583,34 +2495,34 @@ function handle$1(m) {
2583
2495
  var now = time();
2584
2496
  track$7(6 /* Event.Mutation */, now);
2585
2497
  mutations.push({ time: now, mutations: m });
2586
- schedule$1(process$2, 1 /* Priority.High */).then(function () {
2587
- setTimeout(compute$7);
2588
- measure(compute$6)();
2498
+ schedule(process$2, 1 /* Priority.High */).then(function () {
2499
+ setTimeout(compute$6);
2500
+ measure(compute$5)();
2589
2501
  });
2590
2502
  }
2591
2503
  function processMutation(timer, mutation, instance, timestamp) {
2592
2504
  return __awaiter(this, void 0, void 0, function () {
2593
- var state, target, type;
2505
+ var state$1, target, type;
2594
2506
  return __generator(this, function (_a) {
2595
2507
  switch (_a.label) {
2596
2508
  case 0:
2597
- state = state$a(timer);
2598
- if (!(state === 0 /* Task.Wait */)) return [3 /*break*/, 2];
2509
+ state$1 = state(timer);
2510
+ if (!(state$1 === 0 /* Task.Wait */)) return [3 /*break*/, 2];
2599
2511
  return [4 /*yield*/, suspend$1(timer)];
2600
2512
  case 1:
2601
- state = _a.sent();
2513
+ state$1 = _a.sent();
2602
2514
  _a.label = 2;
2603
2515
  case 2:
2604
- if (state === 2 /* Task.Stop */) {
2516
+ if (state$1 === 2 /* Task.Stop */) {
2605
2517
  return [2 /*return*/];
2606
2518
  }
2607
2519
  target = mutation.target;
2608
2520
  type = config$2.throttleDom ? track$5(mutation, timer, instance, timestamp) : mutation.type;
2609
2521
  if (type && target && target.ownerDocument) {
2610
- parse$1(target.ownerDocument);
2522
+ parse(target.ownerDocument);
2611
2523
  }
2612
2524
  if (type && target && target.nodeType == Node.DOCUMENT_FRAGMENT_NODE && target.host) {
2613
- parse$1(target);
2525
+ parse(target);
2614
2526
  }
2615
2527
  switch (type) {
2616
2528
  case "attributes" /* Constant.Attributes */:
@@ -2638,7 +2550,7 @@ function process$2() {
2638
2550
  switch (_d.label) {
2639
2551
  case 0:
2640
2552
  timer = { id: id(), cost: 3 /* Metric.LayoutCost */ };
2641
- start$z(timer);
2553
+ start$d(timer);
2642
2554
  _d.label = 1;
2643
2555
  case 1:
2644
2556
  if (!(mutations.length > 0)) return [3 /*break*/, 7];
@@ -2688,7 +2600,7 @@ function process$2() {
2688
2600
  _d.label = 13;
2689
2601
  case 13:
2690
2602
  cleanHistory();
2691
- stop$x(timer);
2603
+ stop$c(timer);
2692
2604
  return [2 /*return*/];
2693
2605
  }
2694
2606
  });
@@ -2760,7 +2672,7 @@ function names(nodes) {
2760
2672
  }
2761
2673
  function processNodeList(list, source, timer, timestamp) {
2762
2674
  return __awaiter(this, void 0, void 0, function () {
2763
- var length, i, node, state;
2675
+ var length, i, node, state$1;
2764
2676
  return __generator(this, function (_a) {
2765
2677
  switch (_a.label) {
2766
2678
  case 0:
@@ -2774,14 +2686,14 @@ function processNodeList(list, source, timer, timestamp) {
2774
2686
  traverse(node, timer, source, timestamp);
2775
2687
  return [3 /*break*/, 5];
2776
2688
  case 2:
2777
- state = state$a(timer);
2778
- if (!(state === 0 /* Task.Wait */)) return [3 /*break*/, 4];
2689
+ state$1 = state(timer);
2690
+ if (!(state$1 === 0 /* Task.Wait */)) return [3 /*break*/, 4];
2779
2691
  return [4 /*yield*/, suspend$1(timer)];
2780
2692
  case 3:
2781
- state = _a.sent();
2693
+ state$1 = _a.sent();
2782
2694
  _a.label = 4;
2783
2695
  case 4:
2784
- if (state === 2 /* Task.Stop */) {
2696
+ if (state$1 === 2 /* Task.Stop */) {
2785
2697
  return [3 /*break*/, 6];
2786
2698
  }
2787
2699
  processNode(node, source, timestamp);
@@ -2799,10 +2711,10 @@ function processThrottledMutations() {
2799
2711
  clearTimeout(throttleDelay);
2800
2712
  }
2801
2713
  throttleDelay = setTimeout(function () {
2802
- schedule$1(process$2, 1 /* Priority.High */);
2714
+ schedule(process$2, 1 /* Priority.High */);
2803
2715
  }, 33 /* Setting.LookAhead */);
2804
2716
  }
2805
- function schedule(node) {
2717
+ function schedule$1(node) {
2806
2718
  // Only schedule manual trigger for this node if it's not already in the queue
2807
2719
  if (queue$2.indexOf(node) < 0) {
2808
2720
  queue$2.push(node);
@@ -2814,11 +2726,11 @@ function schedule(node) {
2814
2726
  clearTimeout(timeout$1);
2815
2727
  }
2816
2728
  timeout$1 = setTimeout(function () {
2817
- trigger$2();
2729
+ trigger$1();
2818
2730
  }, 33 /* Setting.LookAhead */);
2819
2731
  return node;
2820
2732
  }
2821
- function trigger$2() {
2733
+ function trigger$1() {
2822
2734
  for (var _i = 0, queue_1 = queue$2; _i < queue_1.length; _i++) {
2823
2735
  var node = queue_1[_i];
2824
2736
  // Generate a mutation for this node only if it still exists
@@ -2848,6 +2760,71 @@ function generate(target, type) {
2848
2760
  type: type,
2849
2761
  },
2850
2762
  ]);
2763
+ }
2764
+ function proxyStyleRules(win) {
2765
+ if (win === null || win === undefined) {
2766
+ return;
2767
+ }
2768
+ win.clarityOverrides = win.clarityOverrides || {};
2769
+ // Some popular open source libraries, like styled-components, optimize performance
2770
+ // by injecting CSS using insertRule API vs. appending text node. A side effect of
2771
+ // using javascript API is that it doesn't trigger DOM mutation and therefore we
2772
+ // need to override the insertRule API and listen for changes manually.
2773
+ if (win.clarityOverrides.InsertRule === undefined) {
2774
+ win.clarityOverrides.InsertRule = win.CSSStyleSheet.prototype.insertRule;
2775
+ win.CSSStyleSheet.prototype.insertRule = function () {
2776
+ if (active()) {
2777
+ schedule$1(this.ownerNode);
2778
+ }
2779
+ return win.clarityOverrides.InsertRule.apply(this, arguments);
2780
+ };
2781
+ }
2782
+ if ("CSSMediaRule" in win && win.clarityOverrides.MediaInsertRule === undefined) {
2783
+ win.clarityOverrides.MediaInsertRule = win.CSSMediaRule.prototype.insertRule;
2784
+ win.CSSMediaRule.prototype.insertRule = function () {
2785
+ if (active()) {
2786
+ schedule$1(this.parentStyleSheet.ownerNode);
2787
+ }
2788
+ return win.clarityOverrides.MediaInsertRule.apply(this, arguments);
2789
+ };
2790
+ }
2791
+ if (win.clarityOverrides.DeleteRule === undefined) {
2792
+ win.clarityOverrides.DeleteRule = win.CSSStyleSheet.prototype.deleteRule;
2793
+ win.CSSStyleSheet.prototype.deleteRule = function () {
2794
+ if (active()) {
2795
+ schedule$1(this.ownerNode);
2796
+ }
2797
+ return win.clarityOverrides.DeleteRule.apply(this, arguments);
2798
+ };
2799
+ }
2800
+ if ("CSSMediaRule" in win && win.clarityOverrides.MediaDeleteRule === undefined) {
2801
+ win.clarityOverrides.MediaDeleteRule = win.CSSMediaRule.prototype.deleteRule;
2802
+ win.CSSMediaRule.prototype.deleteRule = function () {
2803
+ if (active()) {
2804
+ schedule$1(this.parentStyleSheet.ownerNode);
2805
+ }
2806
+ return win.clarityOverrides.MediaDeleteRule.apply(this, arguments);
2807
+ };
2808
+ }
2809
+ // Add a hook to attachShadow API calls
2810
+ // In case we are unable to add a hook and browser throws an exception,
2811
+ // reset attachShadow variable and resume processing like before
2812
+ if (win.clarityOverrides.AttachShadow === undefined) {
2813
+ win.clarityOverrides.AttachShadow = win.Element.prototype.attachShadow;
2814
+ try {
2815
+ win.Element.prototype.attachShadow = function () {
2816
+ if (active()) {
2817
+ return schedule$1(win.clarityOverrides.AttachShadow.apply(this, arguments));
2818
+ }
2819
+ else {
2820
+ return win.clarityOverrides.AttachShadow.apply(this, arguments);
2821
+ }
2822
+ };
2823
+ }
2824
+ catch (_a) {
2825
+ win.clarityOverrides.AttachShadow = null;
2826
+ }
2827
+ }
2851
2828
  }
2852
2829
 
2853
2830
  var digitsRegex = /[^0-9\.]/g;
@@ -2947,7 +2924,7 @@ function processNode (node, source, timestamp) {
2947
2924
  // We check for regions in the beginning when discovering document and
2948
2925
  // later whenever there are new additions or modifications to DOM (mutations)
2949
2926
  if (node === document) {
2950
- parse$1(document);
2927
+ parse(document);
2951
2928
  }
2952
2929
  checkDocumentStyles(node, timestamp);
2953
2930
  observe$2(node);
@@ -2955,7 +2932,7 @@ function processNode (node, source, timestamp) {
2955
2932
  case Node.DOCUMENT_FRAGMENT_NODE:
2956
2933
  var shadowRoot = node;
2957
2934
  if (shadowRoot.host) {
2958
- parse$1(shadowRoot);
2935
+ parse(shadowRoot);
2959
2936
  var type = typeof (shadowRoot.constructor);
2960
2937
  if (type === "function" /* Constant.Function */ && shadowRoot.constructor.toString().indexOf("[native code]" /* Constant.NativeCode */) >= 0) {
2961
2938
  observe$2(shadowRoot);
@@ -3301,11 +3278,11 @@ var iframeMap = null; // Maps iframe's contentDocument => parent iframe element
3301
3278
  var iframeContentMap = null; // Maps parent iframe element => iframe's contentDocument & contentWindow
3302
3279
  var privacyMap = null; // Maps node => Privacy (enum)
3303
3280
  var fraudMap = null; // Maps node => FraudId (number)
3304
- function start$i() {
3281
+ function start$j() {
3305
3282
  reset$7();
3306
- parse$1(document, true);
3283
+ parse(document, true);
3307
3284
  }
3308
- function stop$g() {
3285
+ function stop$h() {
3309
3286
  reset$7();
3310
3287
  }
3311
3288
  function reset$7() {
@@ -3329,7 +3306,7 @@ function reset$7() {
3329
3306
  }
3330
3307
  // We parse new root nodes for any regions or masked nodes in the beginning (document) and
3331
3308
  // later whenever there are new additions or modifications to DOM (mutations)
3332
- function parse$1(root, init) {
3309
+ function parse(root, init) {
3333
3310
  if (init === void 0) { init = false; }
3334
3311
  // Wrap selectors in a try / catch block.
3335
3312
  // It's possible for script to receive invalid selectors, e.g. "'#id'" with extra quotes, and cause the code below to fail
@@ -3404,7 +3381,7 @@ function add(node, parent, data, source) {
3404
3381
  updateImageSize(values[id]);
3405
3382
  track$4(id, source);
3406
3383
  }
3407
- function update$1(node, parent, data, source) {
3384
+ function update(node, parent, data, source) {
3408
3385
  var id = getId(node);
3409
3386
  var parentId = parent ? getId(parent) : null;
3410
3387
  var previousId = getPreviousId(node);
@@ -3678,6 +3655,9 @@ function getPreviousId(node) {
3678
3655
  function track$4(id, source, changed, parentChanged) {
3679
3656
  if (changed === void 0) { changed = true; }
3680
3657
  if (parentChanged === void 0) { parentChanged = false; }
3658
+ if (config$2.lean && config$2.lite) {
3659
+ return;
3660
+ }
3681
3661
  // Keep track of the order in which mutations happened, they may not be sequential
3682
3662
  // Edge case: If an element is added later on, and pre-discovered element is moved as a child.
3683
3663
  // In that case, we need to reorder the pre-discovered element in the update list to keep visualization consistent.
@@ -3691,13 +3671,13 @@ function track$4(id, source, changed, parentChanged) {
3691
3671
  }
3692
3672
  }
3693
3673
 
3694
- var state$1 = [];
3674
+ var state$2 = [];
3695
3675
  var regionMap = null; // Maps region nodes => region name
3696
3676
  var regions = {};
3697
3677
  var queue$1 = [];
3698
3678
  var watch = false;
3699
3679
  var observer$1 = null;
3700
- function start$h() {
3680
+ function start$i() {
3701
3681
  reset$6();
3702
3682
  observer$1 = null;
3703
3683
  regionMap = new WeakMap();
@@ -3742,8 +3722,8 @@ function track$3(id, event) {
3742
3722
  // Process updates to this region, if applicable
3743
3723
  process$1(node, data, interaction, data.visibility);
3744
3724
  }
3745
- function compute$6() {
3746
- compute$6.dn = 24 /* FunctionNames.RegionCompute */;
3725
+ function compute$5() {
3726
+ compute$5.dn = 24 /* FunctionNames.RegionCompute */;
3747
3727
  // Process any regions where we couldn't resolve an "id" for at the time of last intersection observer event
3748
3728
  // This could happen in cases where elements are not yet processed by Clarity's virtual DOM but browser reports a change, regardless.
3749
3729
  // For those cases we add them to the queue and re-process them below
@@ -3754,7 +3734,7 @@ function compute$6() {
3754
3734
  if (id) {
3755
3735
  r.state.data.id = id;
3756
3736
  regions[id] = r.state.data;
3757
- state$1.push(r.state);
3737
+ state$2.push(r.state);
3758
3738
  }
3759
3739
  else {
3760
3740
  q.push(r);
@@ -3762,7 +3742,7 @@ function compute$6() {
3762
3742
  }
3763
3743
  queue$1 = q;
3764
3744
  // Schedule encode only when we have at least one valid data entry
3765
- if (state$1.length > 0) {
3745
+ if (state$2.length > 0) {
3766
3746
  encode$4(7 /* Event.Region */);
3767
3747
  }
3768
3748
  }
@@ -3798,7 +3778,7 @@ function handler$1(entries) {
3798
3778
  }
3799
3779
  }
3800
3780
  }
3801
- if (state$1.length > 0) {
3781
+ if (state$2.length > 0) {
3802
3782
  encode$4(7 /* Event.Region */);
3803
3783
  }
3804
3784
  }
@@ -3812,21 +3792,21 @@ function process$1(n, d, s, v) {
3812
3792
  if (d.id) {
3813
3793
  if ((d.id in regions && updated) || !(d.id in regions)) {
3814
3794
  regions[d.id] = d;
3815
- state$1.push(clone$1(d));
3795
+ state$2.push(clone(d));
3816
3796
  }
3817
3797
  }
3818
3798
  else {
3819
3799
  // Get the time before adding to queue to ensure accurate event time
3820
- queue$1.push({ node: n, state: clone$1(d) });
3800
+ queue$1.push({ node: n, state: clone(d) });
3821
3801
  }
3822
3802
  }
3823
- function clone$1(r) {
3803
+ function clone(r) {
3824
3804
  return { time: time(), data: { id: r.id, interaction: r.interaction, visibility: r.visibility, name: r.name } };
3825
3805
  }
3826
3806
  function reset$6() {
3827
- state$1 = [];
3807
+ state$2 = [];
3828
3808
  }
3829
- function stop$f() {
3809
+ function stop$g() {
3830
3810
  reset$6();
3831
3811
  regionMap = null;
3832
3812
  regions = {};
@@ -3883,7 +3863,7 @@ function encode$3 (type, ts) {
3883
3863
  case 18 /* Event.TouchEnd */:
3884
3864
  case 19 /* Event.TouchMove */:
3885
3865
  case 20 /* Event.TouchCancel */:
3886
- for (_i = 0, _a = state$5; _i < _a.length; _i++) {
3866
+ for (_i = 0, _a = state$6; _i < _a.length; _i++) {
3887
3867
  entry = _a[_i];
3888
3868
  pTarget = metadata$2(entry.data.target, entry.event);
3889
3869
  if (pTarget.id > 0) {
@@ -3904,7 +3884,7 @@ function encode$3 (type, ts) {
3904
3884
  reset$i();
3905
3885
  break;
3906
3886
  case 9 /* Event.Click */:
3907
- for (_b = 0, _c = state$8; _b < _c.length; _b++) {
3887
+ for (_b = 0, _c = state$9; _b < _c.length; _b++) {
3908
3888
  entry = _c[_b];
3909
3889
  cTarget = metadata$2(entry.data.target, entry.event, entry.data.text);
3910
3890
  tokens = [entry.time, entry.event];
@@ -3928,7 +3908,7 @@ function encode$3 (type, ts) {
3928
3908
  reset$l();
3929
3909
  break;
3930
3910
  case 38 /* Event.Clipboard */:
3931
- for (_d = 0, _e = state$7; _d < _e.length; _d++) {
3911
+ for (_d = 0, _e = state$8; _d < _e.length; _d++) {
3932
3912
  entry = _e[_d];
3933
3913
  tokens = [entry.time, entry.event];
3934
3914
  target = metadata$2(entry.data.target, entry.event);
@@ -3956,7 +3936,7 @@ function encode$3 (type, ts) {
3956
3936
  queue(tokens);
3957
3937
  break;
3958
3938
  case 27 /* Event.Input */:
3959
- for (_f = 0, _g = state$6; _f < _g.length; _f++) {
3939
+ for (_f = 0, _g = state$7; _f < _g.length; _f++) {
3960
3940
  entry = _g[_f];
3961
3941
  iTarget = metadata$2(entry.data.target, entry.event, entry.data.value);
3962
3942
  tokens = [entry.time, entry.event];
@@ -3980,7 +3960,7 @@ function encode$3 (type, ts) {
3980
3960
  }
3981
3961
  break;
3982
3962
  case 10 /* Event.Scroll */:
3983
- for (_h = 0, _j = state$4; _h < _j.length; _h++) {
3963
+ for (_h = 0, _j = state$5; _h < _j.length; _h++) {
3984
3964
  entry = _j[_h];
3985
3965
  sTarget = metadata$2(entry.data.target, entry.event);
3986
3966
  top_1 = metadata$2(entry.data.top, entry.event);
@@ -4001,7 +3981,7 @@ function encode$3 (type, ts) {
4001
3981
  reset$g();
4002
3982
  break;
4003
3983
  case 42 /* Event.Change */:
4004
- for (_k = 0, _l = state$9; _k < _l.length; _k++) {
3984
+ for (_k = 0, _l = state$a; _k < _l.length; _k++) {
4005
3985
  entry = _l[_k];
4006
3986
  tokens = [entry.time, entry.event];
4007
3987
  target = metadata$2(entry.data.target, entry.event);
@@ -4017,7 +3997,7 @@ function encode$3 (type, ts) {
4017
3997
  reset$m();
4018
3998
  break;
4019
3999
  case 39 /* Event.Submit */:
4020
- for (_m = 0, _o = state$3; _m < _o.length; _m++) {
4000
+ for (_m = 0, _o = state$4; _m < _o.length; _m++) {
4021
4001
  entry = _o[_m];
4022
4002
  tokens = [entry.time, entry.event];
4023
4003
  target = metadata$2(entry.data.target, entry.event);
@@ -4055,10 +4035,10 @@ function encode$3 (type, ts) {
4055
4035
  });
4056
4036
  }
4057
4037
 
4058
- var state = [];
4038
+ var state$1 = [];
4059
4039
  var updates$1 = [];
4060
- function start$g() {
4061
- state = [];
4040
+ function start$h() {
4041
+ state$1 = [];
4062
4042
  reset$5();
4063
4043
  }
4064
4044
  function reset$5() {
@@ -4067,7 +4047,7 @@ function reset$5() {
4067
4047
  function track$2(time, event, hash, x, y, reaction, context) {
4068
4048
  if (reaction === void 0) { reaction = 1 /* BooleanFlag.True */; }
4069
4049
  if (context === void 0) { context = 0 /* BrowsingContext.Self */; }
4070
- state.push({
4050
+ state$1.push({
4071
4051
  time: time,
4072
4052
  event: 22 /* Event.Timeline */,
4073
4053
  data: {
@@ -4084,12 +4064,12 @@ function track$2(time, event, hash, x, y, reaction, context) {
4084
4064
  // We would still need to capture the last scroll position as part of the baseline event, even when timeline will be empty.
4085
4065
  track$8(event, x, y, time);
4086
4066
  }
4087
- function compute$5() {
4067
+ function compute$4() {
4088
4068
  var temp = [];
4089
4069
  updates$1 = [];
4090
4070
  var max = data$1.start + data$1.duration;
4091
4071
  var min = Math.max(max - 2000 /* Setting.TimelineSpan */, 0);
4092
- for (var _i = 0, state_1 = state; _i < state_1.length; _i++) {
4072
+ for (var _i = 0, state_1 = state$1; _i < state_1.length; _i++) {
4093
4073
  var s = state_1[_i];
4094
4074
  if (s.time >= min) {
4095
4075
  if (s.time <= max) {
@@ -4098,11 +4078,11 @@ function compute$5() {
4098
4078
  temp.push(s);
4099
4079
  }
4100
4080
  }
4101
- state = temp; // Drop events less than the min time
4081
+ state$1 = temp; // Drop events less than the min time
4102
4082
  encode$3(22 /* Event.Timeline */);
4103
4083
  }
4104
- function stop$e() {
4105
- state = [];
4084
+ function stop$f() {
4085
+ state$1 = [];
4106
4086
  reset$5();
4107
4087
  }
4108
4088
 
@@ -4115,7 +4095,7 @@ var transit;
4115
4095
  var active$1;
4116
4096
  var queuedTime = 0;
4117
4097
  var track$1;
4118
- function start$f() {
4098
+ function start$g() {
4119
4099
  active$1 = true;
4120
4100
  discoverBytes = 0;
4121
4101
  playbackBytes = 0;
@@ -4169,7 +4149,7 @@ function queue(tokens, transmit) {
4169
4149
  }
4170
4150
  }
4171
4151
  }
4172
- function stop$d() {
4152
+ function stop$e() {
4173
4153
  clearTimeout(timeout);
4174
4154
  upload(true);
4175
4155
  discoverBytes = 0;
@@ -4195,10 +4175,10 @@ function upload(final) {
4195
4175
  }
4196
4176
  // CAUTION: Ensure "transmit" is set to false in the queue function for following events
4197
4177
  // Otherwise you run a risk of infinite loop.
4198
- compute$6();
4199
4178
  compute$5();
4200
- compute$a();
4201
- compute$8();
4179
+ compute$4();
4180
+ compute$9();
4181
+ compute$7();
4202
4182
  last = final === true;
4203
4183
  e = JSON.stringify(envelope(last));
4204
4184
  a = "[".concat(analysis.join(), "]");
@@ -4376,7 +4356,7 @@ function response(payload) {
4376
4356
  break;
4377
4357
  case "EXTRACT" /* Constant.Extract */:
4378
4358
  if (parts.length > 1) {
4379
- trigger$1(parts[1]);
4359
+ trigger$2(parts[1]);
4380
4360
  }
4381
4361
  break;
4382
4362
  case "SIGNAL" /* Constant.Signal */:
@@ -4390,7 +4370,7 @@ function response(payload) {
4390
4370
 
4391
4371
  var history$3 = {};
4392
4372
  var data$7;
4393
- function start$e() {
4373
+ function start$f() {
4394
4374
  bind(window, "error", handler);
4395
4375
  history$3 = {};
4396
4376
  }
@@ -4459,7 +4439,7 @@ function encode$2 (type) {
4459
4439
 
4460
4440
  var history$2 = {};
4461
4441
  var data$6;
4462
- function start$d() {
4442
+ function start$e() {
4463
4443
  history$2 = {};
4464
4444
  }
4465
4445
  function log$1(code, severity, name, message, stack) {
@@ -4482,196 +4462,270 @@ function log$1(code, severity, name, message, stack) {
4482
4462
  }
4483
4463
  encode$2(33 /* Event.Log */);
4484
4464
  }
4485
- function stop$c() {
4465
+ function stop$d() {
4486
4466
  history$2 = {};
4487
4467
  }
4488
4468
 
4489
- var data$5 = {};
4490
- var keys = new Set();
4491
- var variables = {};
4492
- var selectors = {};
4493
- var hashes = {};
4494
- var validation = {};
4495
- function start$c() {
4496
- reset$4();
4469
+ // Track the start time to be able to compute duration at the end of the task
4470
+ var idleTimeout = 5000;
4471
+ var tracker = {};
4472
+ var queuedTasks = [];
4473
+ var activeTask = null;
4474
+ var pauseTask = null;
4475
+ var resumeResolve = null;
4476
+ function pause$1() {
4477
+ if (pauseTask === null) {
4478
+ pauseTask = new Promise(function (resolve) {
4479
+ resumeResolve = resolve;
4480
+ });
4481
+ }
4497
4482
  }
4498
- // Input string is of the following form:
4499
- // EXTRACT 101|element { "1": ".class1", "2": "~window.a.b", "3": "!abc"}
4500
- // if element is present on the page it will set up event 101 to grab the contents of the class1 selector into component 1,
4501
- // the javascript evaluated contents of window.a.b into component 2,
4502
- // and the contents of Clarity's hash abc into component 3
4503
- function trigger$1(input) {
4504
- try {
4505
- var parts = input && input.length > 0 ? input.split(/ (.*)/) : ["" /* Constant.Empty */];
4506
- var keyparts = parts[0].split(/\|(.*)/);
4507
- var key = parseInt(keyparts[0]);
4508
- var element = keyparts.length > 1 ? keyparts[1] : "" /* Constant.Empty */;
4509
- var values = parts.length > 1 ? JSON.parse(parts[1]) : {};
4510
- variables[key] = {};
4511
- selectors[key] = {};
4512
- hashes[key] = {};
4513
- validation[key] = element;
4514
- for (var v in values) {
4515
- // values is a set of strings for proper JSON parsing, but it's more efficient
4516
- // to interact with them as numbers
4517
- var id = parseInt(v);
4518
- var value = values[v];
4519
- var source = 2 /* ExtractSource.Text */;
4520
- if (value.startsWith("~" /* Constant.Tilde */)) {
4521
- source = 0 /* ExtractSource.Javascript */;
4522
- }
4523
- else if (value.startsWith("!" /* Constant.Bang */)) {
4524
- source = 4 /* ExtractSource.Hash */;
4525
- }
4526
- switch (source) {
4527
- case 0 /* ExtractSource.Javascript */:
4528
- var variable = value.slice(1);
4529
- variables[key][id] = parse(variable);
4530
- break;
4531
- case 2 /* ExtractSource.Text */:
4532
- selectors[key][id] = value;
4533
- break;
4534
- case 4 /* ExtractSource.Hash */:
4535
- var hash_1 = value.slice(1);
4536
- hashes[key][id] = hash_1;
4537
- break;
4538
- }
4483
+ function resume$1() {
4484
+ if (pauseTask) {
4485
+ resumeResolve();
4486
+ pauseTask = null;
4487
+ if (activeTask === null) {
4488
+ run();
4539
4489
  }
4540
4490
  }
4541
- catch (e) {
4542
- log$1(8 /* Code.Config */, 1 /* Severity.Warning */, e ? e.name : null);
4543
- }
4544
4491
  }
4545
- function clone(v) {
4546
- return JSON.parse(JSON.stringify(v));
4492
+ function reset$4() {
4493
+ tracker = {};
4494
+ queuedTasks = [];
4495
+ activeTask = null;
4496
+ pauseTask = null;
4547
4497
  }
4548
- function compute$4() {
4549
- try {
4550
- for (var v in variables) {
4551
- var key = parseInt(v);
4552
- if (validation[key] == "" /* Constant.Empty */ || document.querySelector(validation[key])) {
4553
- var variableData = variables[key];
4554
- for (var v_1 in variableData) {
4555
- var variableKey = parseInt(v_1);
4556
- var value = str(evaluate(clone(variableData[variableKey])));
4557
- if (value) {
4558
- update(key, variableKey, value);
4559
- }
4560
- }
4561
- var selectorData = selectors[key];
4562
- for (var s in selectorData) {
4563
- var shouldMask = false;
4564
- var selectorKey = parseInt(s);
4565
- var selector = selectorData[selectorKey];
4566
- if (selector.startsWith("@" /* Constant.At */)) {
4567
- shouldMask = true;
4568
- selector = selector.slice(1);
4569
- }
4570
- var nodes = document.querySelectorAll(selector);
4571
- if (nodes) {
4572
- var text = Array.from(nodes).map(function (e) { return e.textContent; }).join("<SEP>" /* Constant.Seperator */);
4573
- update(key, selectorKey, (shouldMask ? hash(text).trim() : text).slice(0, 10000 /* Setting.ExtractLimit */));
4574
- }
4575
- }
4576
- var hashData = hashes[key];
4577
- for (var h in hashData) {
4578
- var hashKey = parseInt(h);
4579
- var content = hashText(hashData[hashKey]).trim().slice(0, 10000 /* Setting.ExtractLimit */);
4580
- update(key, hashKey, content);
4498
+ function schedule(task, priority) {
4499
+ if (priority === void 0) { priority = 0 /* Priority.Normal */; }
4500
+ return __awaiter(this, void 0, void 0, function () {
4501
+ var _i, queuedTasks_1, q, promise;
4502
+ return __generator(this, function (_a) {
4503
+ // If this task is already scheduled, skip it
4504
+ for (_i = 0, queuedTasks_1 = queuedTasks; _i < queuedTasks_1.length; _i++) {
4505
+ q = queuedTasks_1[_i];
4506
+ if (q.task === task) {
4507
+ return [2 /*return*/];
4581
4508
  }
4582
4509
  }
4583
- }
4584
- if (keys.size > 0) {
4585
- encode$1(40 /* Event.Extract */);
4586
- }
4510
+ promise = new Promise(function (resolve) {
4511
+ var insert = priority === 1 /* Priority.High */ ? "unshift" : "push";
4512
+ // Queue this task for asynchronous execution later
4513
+ // We also store a unique page identifier (id) along with the task to ensure
4514
+ // ensure that we do not accidentally execute this task in context of a different page
4515
+ queuedTasks[insert]({ task: task, resolve: resolve, id: id() });
4516
+ });
4517
+ // If there is no active task running, and Clarity is not in pause state,
4518
+ // invoke the first task in the queue synchronously. This ensures that we don't yield the thread during unload event
4519
+ if (activeTask === null && pauseTask === null) {
4520
+ run();
4521
+ }
4522
+ return [2 /*return*/, promise];
4523
+ });
4524
+ });
4525
+ }
4526
+ function run() {
4527
+ var entry = queuedTasks.shift();
4528
+ if (entry) {
4529
+ activeTask = entry;
4530
+ entry.task().then(function () {
4531
+ // Bail out if the context in which this task was operating is different from the current page
4532
+ // An example scenario where task could span across pages is Single Page Applications (SPA)
4533
+ // A task that started on page #1, but completes on page #2
4534
+ if (entry.id !== id()) {
4535
+ return;
4536
+ }
4537
+ entry.resolve();
4538
+ activeTask = null; // Reset active task back to null now that the promise is resolved
4539
+ run();
4540
+ }).catch(function (error) {
4541
+ // If one of the scheduled tasks failed, log, recover and continue processing rest of the tasks
4542
+ if (entry.id !== id()) {
4543
+ return;
4544
+ }
4545
+ if (error) {
4546
+ log$1(0 /* Code.RunTask */, 1 /* Severity.Warning */, error.name, error.message, error.stack);
4547
+ }
4548
+ activeTask = null;
4549
+ run();
4550
+ });
4587
4551
  }
4588
- catch (e) {
4589
- log$1(5 /* Code.Selector */, 1 /* Severity.Warning */, e ? e.name : null);
4552
+ }
4553
+ function state(timer) {
4554
+ var id = key(timer);
4555
+ if (id in tracker) {
4556
+ var elapsed = performance.now() - tracker[id].start;
4557
+ return (elapsed > tracker[id].yield) ? 0 /* Task.Wait */ : 1 /* Task.Run */;
4590
4558
  }
4559
+ // If this task is no longer being tracked, send stop message to the caller
4560
+ return 2 /* Task.Stop */;
4591
4561
  }
4592
- function reset$4() {
4593
- keys.clear();
4562
+ function start$d(timer) {
4563
+ tracker[key(timer)] = { start: performance.now(), calls: 0, yield: 30 /* Setting.LongTask */ };
4594
4564
  }
4595
- function update(key, subkey, value) {
4596
- var update = false;
4597
- if (!(key in data$5)) {
4598
- data$5[key] = {};
4599
- update = true;
4600
- }
4601
- if (!isEmpty(hashes[key])
4602
- && (!(subkey in data$5[key]) || data$5[key][subkey] != value)) {
4603
- update = true;
4565
+ function restart$2(timer) {
4566
+ var id = key(timer);
4567
+ if (tracker && tracker[id]) {
4568
+ var c = tracker[id].calls;
4569
+ var y = tracker[id].yield;
4570
+ start$d(timer);
4571
+ tracker[id].calls = c + 1;
4572
+ tracker[id].yield = y;
4604
4573
  }
4605
- data$5[key][subkey] = value;
4606
- if (update) {
4607
- keys.add(key);
4574
+ }
4575
+ function stop$c(timer) {
4576
+ var end = performance.now();
4577
+ var id = key(timer);
4578
+ var duration = end - tracker[id].start;
4579
+ sum(timer.cost, duration);
4580
+ count$1(5 /* Metric.InvokeCount */);
4581
+ // For the first execution, which is synchronous, time is automatically counted towards TotalDuration.
4582
+ // However, for subsequent asynchronous runs, we need to manually update TotalDuration metric.
4583
+ if (tracker[id].calls > 0) {
4584
+ sum(4 /* Metric.TotalCost */, duration);
4608
4585
  }
4609
- return;
4610
4586
  }
4611
- function stop$b() {
4612
- reset$4();
4587
+ function suspend$1(timer) {
4588
+ var _a;
4589
+ return __awaiter(this, void 0, void 0, function () {
4590
+ var id, _b;
4591
+ return __generator(this, function (_c) {
4592
+ switch (_c.label) {
4593
+ case 0:
4594
+ id = key(timer);
4595
+ if (!(id in tracker)) return [3 /*break*/, 2];
4596
+ stop$c(timer);
4597
+ // some customer polyfills for requestIdleCallback return null
4598
+ _b = tracker[id];
4599
+ return [4 /*yield*/, wait()];
4600
+ case 1:
4601
+ // some customer polyfills for requestIdleCallback return null
4602
+ _b.yield = ((_a = (_c.sent())) === null || _a === void 0 ? void 0 : _a.timeRemaining()) || 30 /* Setting.LongTask */;
4603
+ restart$2(timer);
4604
+ _c.label = 2;
4605
+ case 2:
4606
+ // After we are done with suspending task, ensure that we are still operating in the right context
4607
+ // If the task is still being tracked, continue running the task, otherwise ask caller to stop execution
4608
+ return [2 /*return*/, id in tracker ? 1 /* Task.Run */ : 2 /* Task.Stop */];
4609
+ }
4610
+ });
4611
+ });
4613
4612
  }
4614
- function parse(variable) {
4615
- var syntax = [];
4616
- var parts = variable.split("." /* Constant.Dot */);
4617
- while (parts.length > 0) {
4618
- var part = parts.shift();
4619
- var arrayStart = part.indexOf("[" /* Constant.ArrayStart */);
4620
- var conditionStart = part.indexOf("{" /* Constant.ConditionStart */);
4621
- var conditionEnd = part.indexOf("}" /* Constant.ConditionEnd */);
4622
- syntax.push({
4623
- name: arrayStart > 0 ? part.slice(0, arrayStart) : (conditionStart > 0 ? part.slice(0, conditionStart) : part),
4624
- type: arrayStart > 0 ? 1 /* Type.Array */ : (conditionStart > 0 ? 2 /* Type.Object */ : 3 /* Type.Simple */),
4625
- condition: conditionStart > 0 ? part.slice(conditionStart + 1, conditionEnd) : null
4613
+ function key(timer) {
4614
+ return "".concat(timer.id, ".").concat(timer.cost);
4615
+ }
4616
+ function wait() {
4617
+ return __awaiter(this, void 0, void 0, function () {
4618
+ return __generator(this, function (_a) {
4619
+ switch (_a.label) {
4620
+ case 0:
4621
+ if (!pauseTask) return [3 /*break*/, 2];
4622
+ return [4 /*yield*/, pauseTask];
4623
+ case 1:
4624
+ _a.sent();
4625
+ _a.label = 2;
4626
+ case 2: return [2 /*return*/, new Promise(function (resolve) {
4627
+ requestIdleCallback(resolve, { timeout: idleTimeout });
4628
+ })];
4629
+ }
4626
4630
  });
4627
- }
4628
- return syntax;
4631
+ });
4629
4632
  }
4630
- // The function below takes in a variable name in following format: "a.b.c" and safely evaluates its value in javascript context
4631
- // For instance, for a.b.c, it will first check window["a"]. If it exists, it will recursively look at: window["a"]["b"] and finally,
4632
- // return the value for window["a"]["b"]["c"].
4633
- function evaluate(variable, base) {
4634
- if (base === void 0) { base = window; }
4635
- if (variable.length == 0) {
4636
- return base;
4637
- }
4638
- var part = variable.shift();
4639
- var output;
4640
- if (base && base[part.name]) {
4641
- var obj = base[part.name];
4642
- if (part.type !== 1 /* Type.Array */ && match(obj, part.condition)) {
4643
- output = evaluate(variable, obj);
4633
+ // Use native implementation of requestIdleCallback if it exists.
4634
+ // Otherwise, fall back to a custom implementation using requestAnimationFrame & MessageChannel.
4635
+ // While it's not possible to build a perfect polyfill given the nature of this API, the following code attempts to get close.
4636
+ // Background context: requestAnimationFrame invokes the js code right before: style, layout and paint computation within the frame.
4637
+ // This means, that any code that runs as part of requestAnimationFrame will by default be blocking in nature. Not what we want.
4638
+ // For non-blocking behavior, We need to know when browser has finished painting. This can be accomplished in two different ways (hacks):
4639
+ // (1) Use MessageChannel to pass the message, and browser will receive the message right after paint event has occured.
4640
+ // (2) Use setTimeout call within requestAnimationFrame. This also works, but there's a risk that browser may throttle setTimeout calls.
4641
+ // Given this information, we are currently using (1) from above. More information on (2) as well as some additional context is below:
4642
+ // https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Performance_best_practices_for_Firefox_fe_engineers
4643
+ function requestIdleCallbackPolyfill(callback, options) {
4644
+ var startTime = performance.now();
4645
+ var channel = new MessageChannel();
4646
+ var incoming = channel.port1;
4647
+ var outgoing = channel.port2;
4648
+ incoming.onmessage = function (event) {
4649
+ var currentTime = performance.now();
4650
+ var elapsed = currentTime - startTime;
4651
+ var duration = currentTime - event.data;
4652
+ if (duration > 30 /* Setting.LongTask */ && elapsed < options.timeout) {
4653
+ requestAnimationFrame(function () { outgoing.postMessage(currentTime); });
4644
4654
  }
4645
- else if (Array.isArray(obj)) {
4646
- var filtered = [];
4647
- for (var _i = 0, obj_1 = obj; _i < obj_1.length; _i++) {
4648
- var value = obj_1[_i];
4649
- if (match(value, part.condition)) {
4650
- var op = evaluate(variable, value);
4651
- if (op) {
4652
- filtered.push(op);
4653
- }
4654
- }
4655
- }
4656
- output = filtered;
4655
+ else {
4656
+ var didTimeout_1 = elapsed > options.timeout;
4657
+ callback({
4658
+ didTimeout: didTimeout_1,
4659
+ timeRemaining: function () { return didTimeout_1 ? 30 /* Setting.LongTask */ : Math.max(0, 30 /* Setting.LongTask */ - duration); }
4660
+ });
4657
4661
  }
4658
- return output;
4659
- }
4660
- return null;
4662
+ };
4663
+ requestAnimationFrame(function () { outgoing.postMessage(performance.now()); });
4661
4664
  }
4662
- function str(input) {
4663
- // Automatically trim string to max of Setting.ExtractLimit to avoid fetching long strings
4664
- return input ? JSON.stringify(input).slice(0, 10000 /* Setting.ExtractLimit */) : input;
4665
+ var requestIdleCallback = window["requestIdleCallback"] || requestIdleCallbackPolyfill;
4666
+
4667
+ function start$c() {
4668
+ schedule(discover, 1 /* Priority.High */).then(function () {
4669
+ measure(compute$6)();
4670
+ measure(compute$5)();
4671
+ measure(compute$8)();
4672
+ });
4665
4673
  }
4666
- function match(base, condition) {
4667
- if (condition) {
4668
- var prop = condition.split(":");
4669
- return prop.length > 1 ? base[prop[0]] == prop[1] : base[prop[0]];
4674
+ function discover() {
4675
+ return __awaiter(this, void 0, void 0, function () {
4676
+ var ts, timer;
4677
+ return __generator(this, function (_a) {
4678
+ switch (_a.label) {
4679
+ case 0:
4680
+ ts = time();
4681
+ timer = { id: id(), cost: 3 /* Metric.LayoutCost */ };
4682
+ start$d(timer);
4683
+ return [4 /*yield*/, traverse(document, timer, 0 /* Source.Discover */, ts)];
4684
+ case 1:
4685
+ _a.sent();
4686
+ checkDocumentStyles(document, ts);
4687
+ return [4 /*yield*/, encode$4(5 /* Event.Discover */, timer, ts)];
4688
+ case 2:
4689
+ _a.sent();
4690
+ stop$c(timer);
4691
+ return [2 /*return*/];
4692
+ }
4693
+ });
4694
+ });
4695
+ }
4696
+
4697
+ var data$5 = null;
4698
+ function start$b() {
4699
+ if (!config$2.lean && config$2.upgrade) {
4700
+ config$2.upgrade("Config" /* Constant.Config */);
4670
4701
  }
4671
- return true;
4702
+ data$5 = null;
4672
4703
  }
4673
- function isEmpty(obj) {
4674
- return Object.keys(obj).length == 0;
4704
+ // Following call will upgrade the session from lean mode into the full mode retroactively from the start of the page.
4705
+ // As part of the lean mode, we do not send back any layout information - including discovery of DOM and mutations.
4706
+ // However, if there's a need for full fidelity playback, calling this function will disable lean mode
4707
+ // and send all backed up layout events to the server.
4708
+ function upgrade(key) {
4709
+ // Upgrade only if Clarity was successfully activated on the page
4710
+ if (active() && config$2.lean) {
4711
+ config$2.lean = false;
4712
+ data$5 = { key: key };
4713
+ // Update metadata to track we have upgraded this session
4714
+ callback();
4715
+ save();
4716
+ // Callback upgrade handler, if configured
4717
+ if (config$2.upgrade) {
4718
+ config$2.upgrade(key);
4719
+ }
4720
+ encode$1(3 /* Event.Upgrade */);
4721
+ if (config$2.lite) {
4722
+ start$c();
4723
+ start$n();
4724
+ }
4725
+ }
4726
+ }
4727
+ function stop$b() {
4728
+ data$5 = null;
4675
4729
  }
4676
4730
 
4677
4731
  function encode$1 (event) {
@@ -4719,7 +4773,7 @@ function encode$1 (event) {
4719
4773
  queue(tokens, false);
4720
4774
  break;
4721
4775
  case 3 /* Event.Upgrade */:
4722
- tokens.push(data$f.key);
4776
+ tokens.push(data$5.key);
4723
4777
  queue(tokens);
4724
4778
  break;
4725
4779
  case 2 /* Event.Upload */:
@@ -4735,12 +4789,12 @@ function encode$1 (event) {
4735
4789
  queue(tokens);
4736
4790
  break;
4737
4791
  case 34 /* Event.Variable */:
4738
- var variableKeys = Object.keys(data$e);
4792
+ var variableKeys = Object.keys(data$f);
4739
4793
  if (variableKeys.length > 0) {
4740
4794
  for (var _i = 0, variableKeys_1 = variableKeys; _i < variableKeys_1.length; _i++) {
4741
4795
  var v = variableKeys_1[_i];
4742
4796
  tokens.push(v);
4743
- tokens.push(data$e[v]);
4797
+ tokens.push(data$f[v]);
4744
4798
  }
4745
4799
  reset$o();
4746
4800
  queue(tokens, false);
@@ -4792,20 +4846,20 @@ function encode$1 (event) {
4792
4846
  extractKeys.forEach((function (e) {
4793
4847
  tokens.push(e);
4794
4848
  var token = [];
4795
- for (var d in data$5[e]) {
4849
+ for (var d in data$e[e]) {
4796
4850
  var key = parseInt(d, 10);
4797
4851
  token.push(key);
4798
- token.push(data$5[e][d]);
4852
+ token.push(data$e[e][d]);
4799
4853
  }
4800
4854
  tokens.push(token);
4801
4855
  }));
4802
- reset$4();
4856
+ reset$n();
4803
4857
  queue(tokens, false);
4804
4858
  }
4805
4859
  }
4806
4860
 
4807
4861
  var data$4;
4808
- function start$b() {
4862
+ function start$a() {
4809
4863
  data$4 = { check: 0 /* Check.None */ };
4810
4864
  }
4811
4865
  function check$2(bytes) {
@@ -4840,7 +4894,7 @@ function stop$a() {
4840
4894
  var data$3 = null;
4841
4895
  var updates = null;
4842
4896
  var limited = false;
4843
- function start$a() {
4897
+ function start$9() {
4844
4898
  data$3 = {};
4845
4899
  updates = {};
4846
4900
  limited = false;
@@ -4900,7 +4954,7 @@ var data$2 = null;
4900
4954
  var callbacks = [];
4901
4955
  var electron = 0 /* BooleanFlag.False */;
4902
4956
  var rootDomain = null;
4903
- function start$9() {
4957
+ function start$8() {
4904
4958
  var _a, _b, _c;
4905
4959
  rootDomain = null;
4906
4960
  var ua = navigator && "userAgent" in navigator ? navigator.userAgent : "" /* Constant.Empty */;
@@ -5227,7 +5281,7 @@ function setCookie(key, value, time) {
5227
5281
  }
5228
5282
 
5229
5283
  var data$1 = null;
5230
- function start$8() {
5284
+ function start$7() {
5231
5285
  var m = data$2;
5232
5286
  data$1 = {
5233
5287
  version: version$1,
@@ -5369,7 +5423,7 @@ var pushState = null;
5369
5423
  var replaceState = null;
5370
5424
  var url = null;
5371
5425
  var count = 0;
5372
- function start$7() {
5426
+ function start$6() {
5373
5427
  url = getCurrentUrl();
5374
5428
  count = 0;
5375
5429
  bind(window, "popstate", compute$1);
@@ -5423,19 +5477,19 @@ function stop$6() {
5423
5477
  }
5424
5478
 
5425
5479
  var status = false;
5426
- function start$6() {
5480
+ function start$5() {
5427
5481
  status = true;
5428
5482
  start$I();
5429
- reset$n();
5483
+ reset$4();
5430
5484
  reset$1();
5431
5485
  reset$2();
5432
- start$7();
5486
+ start$6();
5433
5487
  }
5434
5488
  function stop$5() {
5435
5489
  stop$6();
5436
5490
  reset$2();
5437
5491
  reset$1();
5438
- reset$n();
5492
+ reset$4();
5439
5493
  stop$F();
5440
5494
  status = false;
5441
5495
  }
@@ -5492,79 +5546,49 @@ function restart() {
5492
5546
  event("clarity" /* Constant.Clarity */, "restart" /* Constant.Restart */);
5493
5547
  }
5494
5548
 
5495
- function start$5() {
5496
- start$5.dn = 3 /* FunctionNames.DiagnosticStart */;
5549
+ function start$4() {
5550
+ start$4.dn = 3 /* FunctionNames.DiagnosticStart */;
5497
5551
  start$A();
5552
+ start$f();
5498
5553
  start$e();
5499
- start$d();
5500
5554
  }
5501
5555
  function stop$4() {
5502
- stop$c();
5556
+ stop$d();
5503
5557
  }
5504
5558
 
5505
5559
  var diagnostic = /*#__PURE__*/Object.freeze({
5506
5560
  __proto__: null,
5507
- start: start$5,
5561
+ start: start$4,
5508
5562
  stop: stop$4
5509
5563
  });
5510
5564
 
5511
- function start$4() {
5512
- schedule$1(discover, 1 /* Priority.High */).then(function () {
5513
- measure(compute$7)();
5514
- measure(compute$6)();
5515
- measure(compute$9)();
5516
- });
5517
- }
5518
- function discover() {
5519
- return __awaiter(this, void 0, void 0, function () {
5520
- var ts, timer;
5521
- return __generator(this, function (_a) {
5522
- switch (_a.label) {
5523
- case 0:
5524
- ts = time();
5525
- timer = { id: id(), cost: 3 /* Metric.LayoutCost */ };
5526
- start$z(timer);
5527
- return [4 /*yield*/, traverse(document, timer, 0 /* Source.Discover */, ts)];
5528
- case 1:
5529
- _a.sent();
5530
- checkDocumentStyles(document, ts);
5531
- return [4 /*yield*/, encode$4(5 /* Event.Discover */, timer, ts)];
5532
- case 2:
5533
- _a.sent();
5534
- stop$x(timer);
5535
- return [2 /*return*/];
5536
- }
5537
- });
5538
- });
5539
- }
5540
-
5541
5565
  function start$3() {
5542
5566
  start$3.dn = 20 /* FunctionNames.LayoutStart */;
5543
5567
  // The order below is important
5544
5568
  // and is determined by interdependencies of modules
5545
- start$k();
5546
- start$h();
5569
+ start$l();
5547
5570
  start$i();
5571
+ start$j();
5548
5572
  if (config$2.delayDom) {
5549
5573
  // Lazy load layout module as part of page load time performance improvements experiment
5550
5574
  bind(window, 'load', function () {
5551
- start$j();
5575
+ start$k();
5552
5576
  });
5553
5577
  }
5554
5578
  else {
5555
- start$j();
5579
+ start$k();
5556
5580
  }
5557
- start$4();
5581
+ start$c();
5582
+ start$n();
5558
5583
  start$m();
5559
- start$l();
5560
5584
  }
5561
5585
  function stop$3() {
5562
- stop$f();
5563
5586
  stop$g();
5564
5587
  stop$h();
5565
5588
  stop$i();
5566
- stop$k();
5567
5589
  stop$j();
5590
+ stop$l();
5591
+ stop$k();
5568
5592
  }
5569
5593
 
5570
5594
  var layout = /*#__PURE__*/Object.freeze({
@@ -5862,7 +5886,7 @@ function start(config$1) {
5862
5886
  // Check that browser supports required APIs and we do not attempt to start Clarity multiple times
5863
5887
  if (check()) {
5864
5888
  config(config$1);
5865
- start$6();
5889
+ start$5();
5866
5890
  start$B();
5867
5891
  modules.forEach(function (x) { return measure(x.start)(); });
5868
5892
  // If it's an internal call to start, without explicit configuration,