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