clarity-js 0.8.5 → 0.8.6-beta

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.
Files changed (103) hide show
  1. package/README.md +26 -26
  2. package/build/clarity.extended.js +1 -1
  3. package/build/clarity.insight.js +1 -1
  4. package/build/clarity.js +5588 -5562
  5. package/build/clarity.min.js +1 -1
  6. package/build/clarity.module.js +5588 -5562
  7. package/build/clarity.performance.js +1 -1
  8. package/package.json +70 -70
  9. package/rollup.config.ts +98 -98
  10. package/src/clarity.ts +60 -60
  11. package/src/core/api.ts +8 -8
  12. package/src/core/config.ts +33 -32
  13. package/src/core/copy.ts +3 -3
  14. package/src/core/event.ts +53 -53
  15. package/src/core/hash.ts +19 -19
  16. package/src/core/history.ts +73 -73
  17. package/src/core/index.ts +83 -83
  18. package/src/core/measure.ts +19 -19
  19. package/src/core/report.ts +28 -28
  20. package/src/core/scrub.ts +196 -196
  21. package/src/core/task.ts +181 -181
  22. package/src/core/time.ts +19 -19
  23. package/src/core/timeout.ts +10 -10
  24. package/src/core/version.ts +2 -2
  25. package/src/data/baseline.ts +155 -155
  26. package/src/data/compress.ts +31 -31
  27. package/src/data/consent.ts +20 -20
  28. package/src/data/custom.ts +23 -23
  29. package/src/data/dimension.ts +53 -53
  30. package/src/data/encode.ts +140 -140
  31. package/src/data/envelope.ts +53 -53
  32. package/src/data/extract.ts +211 -211
  33. package/src/data/index.ts +46 -46
  34. package/src/data/limit.ts +44 -44
  35. package/src/data/metadata.ts +344 -344
  36. package/src/data/metric.ts +51 -51
  37. package/src/data/ping.ts +36 -36
  38. package/src/data/signal.ts +30 -30
  39. package/src/data/summary.ts +34 -34
  40. package/src/data/token.ts +39 -39
  41. package/src/data/upgrade.ts +44 -37
  42. package/src/data/upload.ts +283 -283
  43. package/src/data/variable.ts +83 -83
  44. package/src/diagnostic/encode.ts +40 -40
  45. package/src/diagnostic/fraud.ts +36 -36
  46. package/src/diagnostic/index.ts +15 -15
  47. package/src/diagnostic/internal.ts +28 -28
  48. package/src/diagnostic/script.ts +37 -37
  49. package/src/global.ts +6 -6
  50. package/src/index.ts +9 -9
  51. package/src/insight/blank.ts +14 -14
  52. package/src/insight/encode.ts +60 -60
  53. package/src/insight/snapshot.ts +114 -114
  54. package/src/interaction/change.ts +40 -40
  55. package/src/interaction/click.ts +173 -162
  56. package/src/interaction/clipboard.ts +34 -34
  57. package/src/interaction/encode.ts +196 -193
  58. package/src/interaction/index.ts +59 -59
  59. package/src/interaction/input.ts +59 -59
  60. package/src/interaction/pointer.ts +139 -139
  61. package/src/interaction/resize.ts +47 -47
  62. package/src/interaction/scroll.ts +124 -124
  63. package/src/interaction/selection.ts +68 -68
  64. package/src/interaction/submit.ts +32 -32
  65. package/src/interaction/timeline.ts +65 -65
  66. package/src/interaction/unload.ts +28 -28
  67. package/src/interaction/visibility.ts +26 -26
  68. package/src/layout/animation.ts +133 -133
  69. package/src/layout/discover.ts +31 -31
  70. package/src/layout/document.ts +48 -48
  71. package/src/layout/dom.ts +439 -437
  72. package/src/layout/encode.ts +147 -147
  73. package/src/layout/index.ts +41 -41
  74. package/src/layout/mutation.ts +409 -409
  75. package/src/layout/node.ts +292 -292
  76. package/src/layout/offset.ts +19 -19
  77. package/src/layout/region.ts +153 -153
  78. package/src/layout/schema.ts +63 -63
  79. package/src/layout/selector.ts +82 -82
  80. package/src/layout/style.ts +155 -150
  81. package/src/layout/target.ts +32 -32
  82. package/src/layout/traverse.ts +27 -27
  83. package/src/performance/blank.ts +7 -7
  84. package/src/performance/encode.ts +31 -31
  85. package/src/performance/index.ts +14 -14
  86. package/src/performance/interaction.ts +125 -125
  87. package/src/performance/navigation.ts +31 -31
  88. package/src/performance/observer.ts +108 -108
  89. package/src/queue.ts +33 -33
  90. package/test/core.test.ts +139 -139
  91. package/test/helper.ts +162 -162
  92. package/test/html/core.html +27 -27
  93. package/test/stub.test.ts +7 -7
  94. package/test/tsconfig.test.json +5 -5
  95. package/tsconfig.json +21 -21
  96. package/tslint.json +32 -32
  97. package/types/core.d.ts +154 -153
  98. package/types/data.d.ts +514 -511
  99. package/types/diagnostic.d.ts +24 -24
  100. package/types/index.d.ts +39 -39
  101. package/types/interaction.d.ts +168 -165
  102. package/types/layout.d.ts +272 -272
  103. package/types/performance.d.ts +64 -64
@@ -1,32 +1,33 @@
1
- import { Config, Time } from "@clarity-types/core";
2
-
3
- let config: Config = {
4
- projectId: null,
5
- delay: 1 * Time.Second,
6
- lean: false,
7
- track: true,
8
- content: true,
9
- drop: [],
10
- mask: [],
11
- unmask: [],
12
- regions: [],
13
- cookies: [],
14
- fraud: true,
15
- checksum: [],
16
- report: null,
17
- upload: null,
18
- fallback: null,
19
- upgrade: null,
20
- action: null,
21
- dob: null,
22
- delayDom: false,
23
- throttleDom: true,
24
- conversions: false,
25
- includeSubdomains: true,
26
- throttleMutations: false,
27
- dropMutations: false,
28
- criticalMs: 200,
29
- discard: [],
30
- };
31
-
32
- export default config;
1
+ import { Config, Time } from "@clarity-types/core";
2
+
3
+ let config: Config = {
4
+ projectId: null,
5
+ delay: 1 * Time.Second,
6
+ lean: false,
7
+ lite: false,
8
+ track: true,
9
+ content: true,
10
+ drop: [],
11
+ mask: [],
12
+ unmask: [],
13
+ regions: [],
14
+ cookies: [],
15
+ fraud: true,
16
+ checksum: [],
17
+ report: null,
18
+ upload: null,
19
+ fallback: null,
20
+ upgrade: null,
21
+ action: null,
22
+ dob: null,
23
+ delayDom: false,
24
+ throttleDom: true,
25
+ conversions: false,
26
+ includeSubdomains: true,
27
+ throttleMutations: false,
28
+ dropMutations: false,
29
+ criticalMs: 200,
30
+ discard: [],
31
+ };
32
+
33
+ export default config;
package/src/core/copy.ts CHANGED
@@ -1,3 +1,3 @@
1
- export default function<T>(input: T): T {
2
- return JSON.parse(JSON.stringify(input));
3
- }
1
+ export default function<T>(input: T): T {
2
+ return JSON.parse(JSON.stringify(input));
3
+ }
package/src/core/event.ts CHANGED
@@ -1,53 +1,53 @@
1
- import { BrowserEvent, Constant } from "@clarity-types/core";
2
- import api from "./api";
3
- import measure from "./measure";
4
-
5
- let bindings: Map<EventTarget, BrowserEvent[]> = new Map();
6
-
7
- export function bind(target: EventTarget, event: string, listener: EventListener, capture: boolean = false, passive: boolean = true): void {
8
- listener = measure(listener) as EventListener;
9
- // Wrapping following lines inside try / catch to cover edge cases where we might try to access an inaccessible element.
10
- // E.g. Iframe may start off as same-origin but later turn into cross-origin, and the following lines will throw an exception.
11
- try {
12
- target[api(Constant.AddEventListener)](event, listener, { capture, passive });
13
- if (!has(target)) {
14
- bindings.set(target, []);
15
- }
16
-
17
- bindings.get(target).push({ event, listener, options: { capture, passive } });
18
- } catch {
19
- /* do nothing */
20
- }
21
- }
22
-
23
- export function reset(): void {
24
- // Walk through existing list of bindings and remove them all
25
- bindings.forEach((bindingsPerTarget: BrowserEvent[], target: EventTarget) => {
26
- resetByTarget(bindingsPerTarget, target);
27
- });
28
-
29
- bindings = new Map();
30
- }
31
-
32
- export function unbind(target: EventTarget) {
33
- if (!has(target)) {
34
- return;
35
- }
36
- resetByTarget(bindings.get(target), target);
37
- }
38
-
39
- export function has(target: EventTarget): boolean {
40
- return bindings.has(target);
41
- }
42
-
43
- function resetByTarget(bindingsPerTarget: BrowserEvent[], target: EventTarget): void {
44
- bindingsPerTarget.forEach((binding) => {
45
- // Wrapping inside try / catch to avoid situations where the element may be destroyed before we get a chance to unbind
46
- try {
47
- target[api(Constant.RemoveEventListener)](binding.event, binding.listener, { capture: binding.options.capture, passive: binding.options.passive });
48
- } catch {
49
- /* do nothing */
50
- }
51
- });
52
- bindings.delete(target);
53
- }
1
+ import { BrowserEvent, Constant } from "@clarity-types/core";
2
+ import api from "./api";
3
+ import measure from "./measure";
4
+
5
+ let bindings: Map<EventTarget, BrowserEvent[]> = new Map();
6
+
7
+ export function bind(target: EventTarget, event: string, listener: EventListener, capture: boolean = false, passive: boolean = true): void {
8
+ listener = measure(listener) as EventListener;
9
+ // Wrapping following lines inside try / catch to cover edge cases where we might try to access an inaccessible element.
10
+ // E.g. Iframe may start off as same-origin but later turn into cross-origin, and the following lines will throw an exception.
11
+ try {
12
+ target[api(Constant.AddEventListener)](event, listener, { capture, passive });
13
+ if (!has(target)) {
14
+ bindings.set(target, []);
15
+ }
16
+
17
+ bindings.get(target).push({ event, listener, options: { capture, passive } });
18
+ } catch {
19
+ /* do nothing */
20
+ }
21
+ }
22
+
23
+ export function reset(): void {
24
+ // Walk through existing list of bindings and remove them all
25
+ bindings.forEach((bindingsPerTarget: BrowserEvent[], target: EventTarget) => {
26
+ resetByTarget(bindingsPerTarget, target);
27
+ });
28
+
29
+ bindings = new Map();
30
+ }
31
+
32
+ export function unbind(target: EventTarget) {
33
+ if (!has(target)) {
34
+ return;
35
+ }
36
+ resetByTarget(bindings.get(target), target);
37
+ }
38
+
39
+ export function has(target: EventTarget): boolean {
40
+ return bindings.has(target);
41
+ }
42
+
43
+ function resetByTarget(bindingsPerTarget: BrowserEvent[], target: EventTarget): void {
44
+ bindingsPerTarget.forEach((binding) => {
45
+ // Wrapping inside try / catch to avoid situations where the element may be destroyed before we get a chance to unbind
46
+ try {
47
+ target[api(Constant.RemoveEventListener)](binding.event, binding.listener, { capture: binding.options.capture, passive: binding.options.passive });
48
+ } catch {
49
+ /* do nothing */
50
+ }
51
+ });
52
+ bindings.delete(target);
53
+ }
package/src/core/hash.ts CHANGED
@@ -1,19 +1,19 @@
1
- // tslint:disable: no-bitwise
2
- export default function(input: string, precision: number = null): string {
3
- // Code inspired from C# GetHashCode: https://github.com/Microsoft/referencesource/blob/master/mscorlib/system/string.cs
4
- let hash = 0;
5
- let hashOne = 5381;
6
- let hashTwo = hashOne;
7
- for (let i = 0; i < input.length; i += 2) {
8
- let charOne = input.charCodeAt(i);
9
- hashOne = ((hashOne << 5) + hashOne) ^ charOne;
10
- if (i + 1 < input.length) {
11
- let charTwo = input.charCodeAt(i + 1);
12
- hashTwo = ((hashTwo << 5) + hashTwo) ^ charTwo;
13
- }
14
- }
15
- // Replace the magic number from C# implementation (1566083941) with a smaller prime number (11579)
16
- // This ensures we don't hit integer overflow and prevent collisions
17
- hash = Math.abs(hashOne + (hashTwo * 11579));
18
- return (precision ? hash % Math.pow(2, precision) : hash).toString(36);
19
- }
1
+ // tslint:disable: no-bitwise
2
+ export default function(input: string, precision: number = null): string {
3
+ // Code inspired from C# GetHashCode: https://github.com/Microsoft/referencesource/blob/master/mscorlib/system/string.cs
4
+ let hash = 0;
5
+ let hashOne = 5381;
6
+ let hashTwo = hashOne;
7
+ for (let i = 0; i < input.length; i += 2) {
8
+ let charOne = input.charCodeAt(i);
9
+ hashOne = ((hashOne << 5) + hashOne) ^ charOne;
10
+ if (i + 1 < input.length) {
11
+ let charTwo = input.charCodeAt(i + 1);
12
+ hashTwo = ((hashTwo << 5) + hashTwo) ^ charTwo;
13
+ }
14
+ }
15
+ // Replace the magic number from C# implementation (1566083941) with a smaller prime number (11579)
16
+ // This ensures we don't hit integer overflow and prevent collisions
17
+ hash = Math.abs(hashOne + (hashTwo * 11579));
18
+ return (precision ? hash % Math.pow(2, precision) : hash).toString(36);
19
+ }
@@ -1,73 +1,73 @@
1
- import { BooleanFlag, Code, Constant, Metric, Setting, Severity } from "@clarity-types/data";
2
- import { FunctionNames } from "@clarity-types/performance";
3
- import * as clarity from "@src/clarity";
4
- import * as core from "@src/core"
5
- import { bind } from "@src/core/event";
6
- import * as internal from "@src/diagnostic/internal";
7
- import * as metric from "@src/data/metric";
8
-
9
- let pushState = null;
10
- let replaceState = null;
11
- let url = null;
12
- let count = 0;
13
-
14
- export function start(): void {
15
- url = getCurrentUrl();
16
- count = 0;
17
- bind(window, "popstate", compute);
18
-
19
- // Add a proxy to history.pushState function
20
- if (pushState === null) {
21
- pushState = history.pushState;
22
- history.pushState = function(): void {
23
- pushState.apply(this, arguments);
24
- if (core.active() && check()) {
25
- compute();
26
- }
27
- };
28
- }
29
-
30
- // Add a proxy to history.replaceState function
31
- if (replaceState === null)
32
- {
33
- replaceState = history.replaceState;
34
- history.replaceState = function(): void {
35
- replaceState.apply(this, arguments);
36
- if (core.active() && check()) {
37
- compute();
38
- }
39
- };
40
- }
41
- }
42
-
43
- function check(): boolean {
44
- if (count++ > Setting.CallStackDepth) {
45
- internal.log(Code.CallStackDepth, Severity.Info);
46
- return false;
47
- }
48
- return true;
49
- }
50
-
51
- function compute(): void {
52
- compute.dn = FunctionNames.HistoryCompute;
53
- count = 0; // Reset the counter
54
- if (url !== getCurrentUrl()) {
55
- // If the url changed, start tracking it as a new page
56
- clarity.stop();
57
- window.setTimeout(restart, Setting.RestartDelay);
58
- }
59
- }
60
-
61
- function restart(): void {
62
- clarity.start();
63
- metric.max(Metric.SinglePage, BooleanFlag.True);
64
- }
65
-
66
- function getCurrentUrl(): string {
67
- return location.href ? location.href.replace(location.hash, Constant.Empty) : location.href;
68
- }
69
-
70
- export function stop(): void {
71
- url = null;
72
- count = 0;
73
- }
1
+ import { BooleanFlag, Code, Constant, Metric, Setting, Severity } from "@clarity-types/data";
2
+ import { FunctionNames } from "@clarity-types/performance";
3
+ import * as clarity from "@src/clarity";
4
+ import * as core from "@src/core"
5
+ import { bind } from "@src/core/event";
6
+ import * as internal from "@src/diagnostic/internal";
7
+ import * as metric from "@src/data/metric";
8
+
9
+ let pushState = null;
10
+ let replaceState = null;
11
+ let url = null;
12
+ let count = 0;
13
+
14
+ export function start(): void {
15
+ url = getCurrentUrl();
16
+ count = 0;
17
+ bind(window, "popstate", compute);
18
+
19
+ // Add a proxy to history.pushState function
20
+ if (pushState === null) {
21
+ pushState = history.pushState;
22
+ history.pushState = function(): void {
23
+ pushState.apply(this, arguments);
24
+ if (core.active() && check()) {
25
+ compute();
26
+ }
27
+ };
28
+ }
29
+
30
+ // Add a proxy to history.replaceState function
31
+ if (replaceState === null)
32
+ {
33
+ replaceState = history.replaceState;
34
+ history.replaceState = function(): void {
35
+ replaceState.apply(this, arguments);
36
+ if (core.active() && check()) {
37
+ compute();
38
+ }
39
+ };
40
+ }
41
+ }
42
+
43
+ function check(): boolean {
44
+ if (count++ > Setting.CallStackDepth) {
45
+ internal.log(Code.CallStackDepth, Severity.Info);
46
+ return false;
47
+ }
48
+ return true;
49
+ }
50
+
51
+ function compute(): void {
52
+ compute.dn = FunctionNames.HistoryCompute;
53
+ count = 0; // Reset the counter
54
+ if (url !== getCurrentUrl()) {
55
+ // If the url changed, start tracking it as a new page
56
+ clarity.stop();
57
+ window.setTimeout(restart, Setting.RestartDelay);
58
+ }
59
+ }
60
+
61
+ function restart(): void {
62
+ clarity.start();
63
+ metric.max(Metric.SinglePage, BooleanFlag.True);
64
+ }
65
+
66
+ function getCurrentUrl(): string {
67
+ return location.href ? location.href.replace(location.hash, Constant.Empty) : location.href;
68
+ }
69
+
70
+ export function stop(): void {
71
+ url = null;
72
+ count = 0;
73
+ }
package/src/core/index.ts CHANGED
@@ -1,83 +1,83 @@
1
- import { Config } from "@clarity-types/core";
2
- import { Constant } from "@clarity-types/data";
3
- import { FunctionNames } from "@clarity-types/performance";
4
- import configuration from "@src/core/config";
5
- import * as event from "@src/core/event";
6
- import * as history from "@src/core/history";
7
- import * as report from "@src/core/report";
8
- import * as task from "@src/core/task";
9
- import * as time from "@src/core/time";
10
- import * as clarity from "@src/clarity";
11
- import * as custom from "@src/data/custom";
12
-
13
- let status = false;
14
-
15
- export function start(): void {
16
- status = true;
17
- time.start();
18
- task.reset();
19
- event.reset();
20
- report.reset();
21
- history.start();
22
- }
23
-
24
- export function stop(): void {
25
- history.stop();
26
- report.reset();
27
- event.reset();
28
- task.reset();
29
- time.stop();
30
- status = false;
31
- }
32
-
33
- export function active(): boolean {
34
- return status;
35
- }
36
-
37
- export function check(): boolean {
38
- try {
39
- let globalPrivacyControlSet = navigator && "globalPrivacyControl" in navigator && navigator['globalPrivacyControl'] == true;
40
- return status === false &&
41
- typeof Promise !== "undefined" &&
42
- window["MutationObserver"] &&
43
- document["createTreeWalker"] &&
44
- "now" in Date &&
45
- "now" in performance &&
46
- typeof WeakMap !== "undefined" &&
47
- !globalPrivacyControlSet
48
- } catch (ex) {
49
- return false;
50
- }
51
- }
52
-
53
- export function config(override: Config): boolean {
54
- // Process custom configuration overrides, if available
55
- if (override === null || status) { return false; }
56
- for (let key in override) {
57
- if (key in configuration) { configuration[key] = override[key]; }
58
- }
59
- return true;
60
- }
61
-
62
- // Suspend ends the current Clarity instance after a configured timeout period
63
- // The way it differs from the "end" call is that it starts listening to
64
- // user interaction events as soon as it terminates existing clarity instance.
65
- // On the next interaction, it automatically starts another instance under a different page id
66
- // E.g. if configured timeout is 10m, and user stays inactive for an hour.
67
- // In this case, we will suspend clarity after 10m of inactivity and after another 50m when user interacts again
68
- // Clarity will restart and start another instance seamlessly. Effectively not missing any active time, but also
69
- // not holding the session during inactive time periods.
70
- export function suspend(): void {
71
- if (status) {
72
- custom.event(Constant.Clarity, Constant.Suspend);
73
- clarity.stop();
74
- ["mousemove", "touchstart"].forEach(x => event.bind(document, x, restart));
75
- ["resize", "scroll", "pageshow"].forEach(x => event.bind(window, x, restart));
76
- }
77
- }
78
-
79
- function restart(): void {
80
- restart.dn = FunctionNames.Restart;
81
- clarity.start();
82
- custom.event(Constant.Clarity, Constant.Restart);
83
- }
1
+ import { Config } from "@clarity-types/core";
2
+ import { Constant } from "@clarity-types/data";
3
+ import { FunctionNames } from "@clarity-types/performance";
4
+ import configuration from "@src/core/config";
5
+ import * as event from "@src/core/event";
6
+ import * as history from "@src/core/history";
7
+ import * as report from "@src/core/report";
8
+ import * as task from "@src/core/task";
9
+ import * as time from "@src/core/time";
10
+ import * as clarity from "@src/clarity";
11
+ import * as custom from "@src/data/custom";
12
+
13
+ let status = false;
14
+
15
+ export function start(): void {
16
+ status = true;
17
+ time.start();
18
+ task.reset();
19
+ event.reset();
20
+ report.reset();
21
+ history.start();
22
+ }
23
+
24
+ export function stop(): void {
25
+ history.stop();
26
+ report.reset();
27
+ event.reset();
28
+ task.reset();
29
+ time.stop();
30
+ status = false;
31
+ }
32
+
33
+ export function active(): boolean {
34
+ return status;
35
+ }
36
+
37
+ export function check(): boolean {
38
+ try {
39
+ let globalPrivacyControlSet = navigator && "globalPrivacyControl" in navigator && navigator['globalPrivacyControl'] == true;
40
+ return status === false &&
41
+ typeof Promise !== "undefined" &&
42
+ window["MutationObserver"] &&
43
+ document["createTreeWalker"] &&
44
+ "now" in Date &&
45
+ "now" in performance &&
46
+ typeof WeakMap !== "undefined" &&
47
+ !globalPrivacyControlSet
48
+ } catch (ex) {
49
+ return false;
50
+ }
51
+ }
52
+
53
+ export function config(override: Config): boolean {
54
+ // Process custom configuration overrides, if available
55
+ if (override === null || status) { return false; }
56
+ for (let key in override) {
57
+ if (key in configuration) { configuration[key] = override[key]; }
58
+ }
59
+ return true;
60
+ }
61
+
62
+ // Suspend ends the current Clarity instance after a configured timeout period
63
+ // The way it differs from the "end" call is that it starts listening to
64
+ // user interaction events as soon as it terminates existing clarity instance.
65
+ // On the next interaction, it automatically starts another instance under a different page id
66
+ // E.g. if configured timeout is 10m, and user stays inactive for an hour.
67
+ // In this case, we will suspend clarity after 10m of inactivity and after another 50m when user interacts again
68
+ // Clarity will restart and start another instance seamlessly. Effectively not missing any active time, but also
69
+ // not holding the session during inactive time periods.
70
+ export function suspend(): void {
71
+ if (status) {
72
+ custom.event(Constant.Clarity, Constant.Suspend);
73
+ clarity.stop();
74
+ ["mousemove", "touchstart"].forEach(x => event.bind(document, x, restart));
75
+ ["resize", "scroll", "pageshow"].forEach(x => event.bind(window, x, restart));
76
+ }
77
+ }
78
+
79
+ function restart(): void {
80
+ restart.dn = FunctionNames.Restart;
81
+ clarity.start();
82
+ custom.event(Constant.Clarity, Constant.Restart);
83
+ }
@@ -1,19 +1,19 @@
1
- import { Code, Metric, Setting, Severity } from "@clarity-types/data";
2
- import { report } from "@src/core/report";
3
- import * as metric from "@src/data/metric";
4
- import * as internal from "@src/diagnostic/internal";
5
-
6
- // tslint:disable-next-line: ban-types
7
- export default function (method: Function): Function {
8
- return function (): void {
9
- let start = performance.now();
10
- try { method.apply(this, arguments); } catch (ex) { throw report(ex); }
11
- let duration = performance.now() - start;
12
- metric.sum(Metric.TotalCost, duration);
13
- if (duration > Setting.LongTask) {
14
- metric.count(Metric.LongTaskCount);
15
- metric.max(Metric.ThreadBlockedTime, duration);
16
- internal.log(Code.FunctionExecutionTime, Severity.Info, `${method.dn || method.name}-${duration}`);
17
- }
18
- };
19
- }
1
+ import { Code, Metric, Setting, Severity } from "@clarity-types/data";
2
+ import { report } from "@src/core/report";
3
+ import * as metric from "@src/data/metric";
4
+ import * as internal from "@src/diagnostic/internal";
5
+
6
+ // tslint:disable-next-line: ban-types
7
+ export default function (method: Function): Function {
8
+ return function (): void {
9
+ let start = performance.now();
10
+ try { method.apply(this, arguments); } catch (ex) { throw report(ex); }
11
+ let duration = performance.now() - start;
12
+ metric.sum(Metric.TotalCost, duration);
13
+ if (duration > Setting.LongTask) {
14
+ metric.count(Metric.LongTaskCount);
15
+ metric.max(Metric.ThreadBlockedTime, duration);
16
+ internal.log(Code.FunctionExecutionTime, Severity.Info, `${method.dn || method.name}-${duration}`);
17
+ }
18
+ };
19
+ }
@@ -1,28 +1,28 @@
1
- import { Report } from "@clarity-types/core";
2
- import config from "@src/core/config";
3
- import { data } from "@src/data/envelope";
4
-
5
- let history: string[];
6
-
7
- export function reset(): void {
8
- history = [];
9
- }
10
-
11
- export function report(e: Error): Error {
12
- // Do not report the same message twice for the same page
13
- if (history && history.indexOf(e.message) === -1) {
14
- const url = config.report;
15
- if (url && url.length > 0) {
16
- let payload: Report = {v: data.version, p: data.projectId, u: data.userId, s: data.sessionId, n: data.pageNum};
17
- if (e.message) { payload.m = e.message; }
18
- if (e.stack) { payload.e = e.stack; }
19
- // Using POST request instead of a GET request (img-src) to not violate existing CSP rules
20
- // Since, Clarity already uses XHR to upload data, we stick with similar POST mechanism for reporting too
21
- let xhr = new XMLHttpRequest();
22
- xhr.open("POST", url, true);
23
- xhr.send(JSON.stringify(payload));
24
- history.push(e.message);
25
- }
26
- }
27
- return e;
28
- }
1
+ import { Report } from "@clarity-types/core";
2
+ import config from "@src/core/config";
3
+ import { data } from "@src/data/envelope";
4
+
5
+ let history: string[];
6
+
7
+ export function reset(): void {
8
+ history = [];
9
+ }
10
+
11
+ export function report(e: Error): Error {
12
+ // Do not report the same message twice for the same page
13
+ if (history && history.indexOf(e.message) === -1) {
14
+ const url = config.report;
15
+ if (url && url.length > 0) {
16
+ let payload: Report = {v: data.version, p: data.projectId, u: data.userId, s: data.sessionId, n: data.pageNum};
17
+ if (e.message) { payload.m = e.message; }
18
+ if (e.stack) { payload.e = e.stack; }
19
+ // Using POST request instead of a GET request (img-src) to not violate existing CSP rules
20
+ // Since, Clarity already uses XHR to upload data, we stick with similar POST mechanism for reporting too
21
+ let xhr = new XMLHttpRequest();
22
+ xhr.open("POST", url, true);
23
+ xhr.send(JSON.stringify(payload));
24
+ history.push(e.message);
25
+ }
26
+ }
27
+ return e;
28
+ }