clarity-js 0.8.1 → 0.8.2

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 (102) 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 +5537 -5537
  5. package/build/clarity.min.js +1 -1
  6. package/build/clarity.module.js +5537 -5537
  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 +32 -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 +180 -180
  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 +356 -356
  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 +37 -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 +162 -162
  56. package/src/interaction/clipboard.ts +34 -34
  57. package/src/interaction/encode.ts +193 -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 +437 -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 +150 -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/tsconfig.test.json +5 -5
  94. package/tsconfig.json +21 -21
  95. package/tslint.json +32 -32
  96. package/types/core.d.ts +153 -153
  97. package/types/data.d.ts +510 -510
  98. package/types/diagnostic.d.ts +24 -24
  99. package/types/index.d.ts +39 -39
  100. package/types/interaction.d.ts +165 -165
  101. package/types/layout.d.ts +272 -272
  102. package/types/performance.d.ts +64 -64
@@ -1,150 +1,150 @@
1
- import { Event, Metric } from "@clarity-types/data";
2
- import { StyleSheetOperation, StyleSheetState } from "@clarity-types/layout";
3
- import { time } from "@src/core/time";
4
- import { shortid } from "@src/data/metadata";
5
- import encode from "@src/layout/encode";
6
- import { getId } from "@src/layout/dom";
7
- import * as core from "@src/core";
8
- import { getCssRules } from "./node";
9
- import * as metric from "@src/data/metric";
10
-
11
- export let sheetUpdateState: StyleSheetState[] = [];
12
- export let sheetAdoptionState: StyleSheetState[] = [];
13
- let replace: (text?: string) => Promise<CSSStyleSheet> = null;
14
- let replaceSync: (text?: string) => void = null;
15
- const styleSheetId = 'claritySheetId';
16
- let styleSheetMap = {};
17
- let styleTimeMap: {[key: string]: number} = {};
18
- let documentNodes = [];
19
- let createdSheetIds = [];
20
-
21
- export function start(): void {
22
- if (window['CSSStyleSheet'] && CSSStyleSheet.prototype) {
23
- if (replace === null) {
24
- replace = CSSStyleSheet.prototype.replace;
25
- CSSStyleSheet.prototype.replace = function(): Promise<CSSStyleSheet> {
26
- if (core.active()) {
27
- metric.max(Metric.ConstructedStyles, 1);
28
- // if we haven't seen this stylesheet on this page yet, wait until the checkDocumentStyles has found it
29
- // and attached the sheet to a document. This way the timestamp of the style sheet creation will align
30
- // to when it is used in the document rather than potentially being misaligned during the traverse process.
31
- if (createdSheetIds.indexOf(this[styleSheetId]) > -1) {
32
- trackStyleChange(time(), this[styleSheetId], StyleSheetOperation.Replace, arguments[0]);
33
- }
34
- }
35
- return replace.apply(this, arguments);
36
- };
37
- }
38
-
39
- if (replaceSync === null) {
40
- replaceSync = CSSStyleSheet.prototype.replaceSync;
41
- CSSStyleSheet.prototype.replaceSync = function(): void {
42
- if (core.active()) {
43
- metric.max(Metric.ConstructedStyles, 1);
44
- // if we haven't seen this stylesheet on this page yet, wait until the checkDocumentStyles has found it
45
- // and attached the sheet to a document. This way the timestamp of the style sheet creation will align
46
- // to when it is used in the document rather than potentially being misaligned during the traverse process.
47
- if (createdSheetIds.indexOf(this[styleSheetId]) > -1) {
48
- trackStyleChange(time(), this[styleSheetId], StyleSheetOperation.ReplaceSync, arguments[0]);
49
- }
50
- }
51
- return replaceSync.apply(this, arguments);
52
- };
53
- }
54
- }
55
- }
56
-
57
- export function checkDocumentStyles(documentNode: Document, timestamp: number): void {
58
- if (documentNodes.indexOf(documentNode) === -1) {
59
- documentNodes.push(documentNode);
60
- }
61
- timestamp = timestamp || time();
62
- if (!documentNode?.adoptedStyleSheets) {
63
- // if we don't have adoptedStyledSheets on the Node passed to us, we can short circuit.
64
- return;
65
- }
66
- metric.max(Metric.ConstructedStyles, 1);
67
- let currentStyleSheets: string[] = [];
68
- for (var styleSheet of documentNode.adoptedStyleSheets) {
69
- // If we haven't seen this style sheet on this page yet, we create a reference to it for the visualizer.
70
- // For SPA or times in which Clarity restarts on a given page, our visualizer would lose context
71
- // on the previously created style sheet for page N-1.
72
- // Then we synthetically call replaceSync with its contents to bootstrap it
73
- if (!styleSheet[styleSheetId] || createdSheetIds.indexOf(styleSheet[styleSheetId]) === -1) {
74
- styleSheet[styleSheetId] = shortid();
75
- createdSheetIds.push(styleSheet[styleSheetId]);
76
- trackStyleChange(timestamp, styleSheet[styleSheetId], StyleSheetOperation.Create);
77
- trackStyleChange(timestamp, styleSheet[styleSheetId], StyleSheetOperation.ReplaceSync, getCssRules(styleSheet));
78
- }
79
-
80
- currentStyleSheets.push(styleSheet[styleSheetId]);
81
- }
82
-
83
- let documentId = getId(documentNode, true);
84
- if (!styleSheetMap[documentId]) {
85
- styleSheetMap[documentId] = [];
86
- }
87
- if (!arraysEqual(currentStyleSheets, styleSheetMap[documentId])) {
88
- // Using -1 to signify the root document node as we don't track that as part of our nodeMap
89
- trackStyleAdoption(timestamp, documentNode == document ? -1 : getId(documentNode), StyleSheetOperation.SetAdoptedStyles, currentStyleSheets);
90
- styleSheetMap[documentId] = currentStyleSheets;
91
- styleTimeMap[documentId] = timestamp;
92
- }
93
- }
94
-
95
- export function compute(): void {
96
- for (var documentNode of documentNodes) {
97
- var docId = documentNode == document ? -1 : getId(documentNode);
98
- let ts = docId in styleTimeMap ? styleTimeMap[docId] : null;
99
- checkDocumentStyles(document, ts);
100
- }
101
- }
102
-
103
- export function reset(): void {
104
- sheetAdoptionState = [];
105
- sheetUpdateState = [];
106
- }
107
-
108
- export function stop(): void {
109
- styleSheetMap = {};
110
- styleTimeMap = {};
111
- documentNodes = [];
112
- createdSheetIds = [];
113
- reset();
114
- }
115
-
116
- function trackStyleChange(time: number, id: string, operation: StyleSheetOperation, cssRules?: string): void {
117
- sheetUpdateState.push({
118
- time,
119
- event: Event.StyleSheetUpdate,
120
- data: {
121
- id,
122
- operation,
123
- cssRules
124
- }
125
- });
126
-
127
- encode(Event.StyleSheetUpdate);
128
- }
129
-
130
- function trackStyleAdoption(time: number, id: number, operation: StyleSheetOperation, newIds: string[]): void {
131
- sheetAdoptionState.push({
132
- time,
133
- event: Event.StyleSheetAdoption,
134
- data: {
135
- id,
136
- operation,
137
- newIds
138
- }
139
- });
140
-
141
- encode(Event.StyleSheetAdoption);
142
- }
143
-
144
- function arraysEqual(a: string[], b: string[]): boolean {
145
- if (a.length !== b.length) {
146
- return false;
147
- }
148
-
149
- return a.every((value, index) => value === b[index]);
150
- }
1
+ import { Event, Metric } from "@clarity-types/data";
2
+ import { StyleSheetOperation, StyleSheetState } from "@clarity-types/layout";
3
+ import { time } from "@src/core/time";
4
+ import { shortid } from "@src/data/metadata";
5
+ import encode from "@src/layout/encode";
6
+ import { getId } from "@src/layout/dom";
7
+ import * as core from "@src/core";
8
+ import { getCssRules } from "./node";
9
+ import * as metric from "@src/data/metric";
10
+
11
+ export let sheetUpdateState: StyleSheetState[] = [];
12
+ export let sheetAdoptionState: StyleSheetState[] = [];
13
+ let replace: (text?: string) => Promise<CSSStyleSheet> = null;
14
+ let replaceSync: (text?: string) => void = null;
15
+ const styleSheetId = 'claritySheetId';
16
+ let styleSheetMap = {};
17
+ let styleTimeMap: {[key: string]: number} = {};
18
+ let documentNodes = [];
19
+ let createdSheetIds = [];
20
+
21
+ export function start(): void {
22
+ if (window['CSSStyleSheet'] && CSSStyleSheet.prototype) {
23
+ if (replace === null) {
24
+ replace = CSSStyleSheet.prototype.replace;
25
+ CSSStyleSheet.prototype.replace = function(): Promise<CSSStyleSheet> {
26
+ if (core.active()) {
27
+ metric.max(Metric.ConstructedStyles, 1);
28
+ // if we haven't seen this stylesheet on this page yet, wait until the checkDocumentStyles has found it
29
+ // and attached the sheet to a document. This way the timestamp of the style sheet creation will align
30
+ // to when it is used in the document rather than potentially being misaligned during the traverse process.
31
+ if (createdSheetIds.indexOf(this[styleSheetId]) > -1) {
32
+ trackStyleChange(time(), this[styleSheetId], StyleSheetOperation.Replace, arguments[0]);
33
+ }
34
+ }
35
+ return replace.apply(this, arguments);
36
+ };
37
+ }
38
+
39
+ if (replaceSync === null) {
40
+ replaceSync = CSSStyleSheet.prototype.replaceSync;
41
+ CSSStyleSheet.prototype.replaceSync = function(): void {
42
+ if (core.active()) {
43
+ metric.max(Metric.ConstructedStyles, 1);
44
+ // if we haven't seen this stylesheet on this page yet, wait until the checkDocumentStyles has found it
45
+ // and attached the sheet to a document. This way the timestamp of the style sheet creation will align
46
+ // to when it is used in the document rather than potentially being misaligned during the traverse process.
47
+ if (createdSheetIds.indexOf(this[styleSheetId]) > -1) {
48
+ trackStyleChange(time(), this[styleSheetId], StyleSheetOperation.ReplaceSync, arguments[0]);
49
+ }
50
+ }
51
+ return replaceSync.apply(this, arguments);
52
+ };
53
+ }
54
+ }
55
+ }
56
+
57
+ export function checkDocumentStyles(documentNode: Document, timestamp: number): void {
58
+ if (documentNodes.indexOf(documentNode) === -1) {
59
+ documentNodes.push(documentNode);
60
+ }
61
+ timestamp = timestamp || time();
62
+ if (!documentNode?.adoptedStyleSheets) {
63
+ // if we don't have adoptedStyledSheets on the Node passed to us, we can short circuit.
64
+ return;
65
+ }
66
+ metric.max(Metric.ConstructedStyles, 1);
67
+ let currentStyleSheets: string[] = [];
68
+ for (var styleSheet of documentNode.adoptedStyleSheets) {
69
+ // If we haven't seen this style sheet on this page yet, we create a reference to it for the visualizer.
70
+ // For SPA or times in which Clarity restarts on a given page, our visualizer would lose context
71
+ // on the previously created style sheet for page N-1.
72
+ // Then we synthetically call replaceSync with its contents to bootstrap it
73
+ if (!styleSheet[styleSheetId] || createdSheetIds.indexOf(styleSheet[styleSheetId]) === -1) {
74
+ styleSheet[styleSheetId] = shortid();
75
+ createdSheetIds.push(styleSheet[styleSheetId]);
76
+ trackStyleChange(timestamp, styleSheet[styleSheetId], StyleSheetOperation.Create);
77
+ trackStyleChange(timestamp, styleSheet[styleSheetId], StyleSheetOperation.ReplaceSync, getCssRules(styleSheet));
78
+ }
79
+
80
+ currentStyleSheets.push(styleSheet[styleSheetId]);
81
+ }
82
+
83
+ let documentId = getId(documentNode, true);
84
+ if (!styleSheetMap[documentId]) {
85
+ styleSheetMap[documentId] = [];
86
+ }
87
+ if (!arraysEqual(currentStyleSheets, styleSheetMap[documentId])) {
88
+ // Using -1 to signify the root document node as we don't track that as part of our nodeMap
89
+ trackStyleAdoption(timestamp, documentNode == document ? -1 : getId(documentNode), StyleSheetOperation.SetAdoptedStyles, currentStyleSheets);
90
+ styleSheetMap[documentId] = currentStyleSheets;
91
+ styleTimeMap[documentId] = timestamp;
92
+ }
93
+ }
94
+
95
+ export function compute(): void {
96
+ for (var documentNode of documentNodes) {
97
+ var docId = documentNode == document ? -1 : getId(documentNode);
98
+ let ts = docId in styleTimeMap ? styleTimeMap[docId] : null;
99
+ checkDocumentStyles(document, ts);
100
+ }
101
+ }
102
+
103
+ export function reset(): void {
104
+ sheetAdoptionState = [];
105
+ sheetUpdateState = [];
106
+ }
107
+
108
+ export function stop(): void {
109
+ styleSheetMap = {};
110
+ styleTimeMap = {};
111
+ documentNodes = [];
112
+ createdSheetIds = [];
113
+ reset();
114
+ }
115
+
116
+ function trackStyleChange(time: number, id: string, operation: StyleSheetOperation, cssRules?: string): void {
117
+ sheetUpdateState.push({
118
+ time,
119
+ event: Event.StyleSheetUpdate,
120
+ data: {
121
+ id,
122
+ operation,
123
+ cssRules
124
+ }
125
+ });
126
+
127
+ encode(Event.StyleSheetUpdate);
128
+ }
129
+
130
+ function trackStyleAdoption(time: number, id: number, operation: StyleSheetOperation, newIds: string[]): void {
131
+ sheetAdoptionState.push({
132
+ time,
133
+ event: Event.StyleSheetAdoption,
134
+ data: {
135
+ id,
136
+ operation,
137
+ newIds
138
+ }
139
+ });
140
+
141
+ encode(Event.StyleSheetAdoption);
142
+ }
143
+
144
+ function arraysEqual(a: string[], b: string[]): boolean {
145
+ if (a.length !== b.length) {
146
+ return false;
147
+ }
148
+
149
+ return a.every((value, index) => value === b[index]);
150
+ }
@@ -1,32 +1,32 @@
1
- import { Privacy } from "@clarity-types/core";
2
- import { Event } from "@clarity-types/data";
3
- import { TargetMetadata } from "@clarity-types/layout";
4
- import * as fraud from "@src/diagnostic/fraud";
5
- import * as region from "@src/layout/region";
6
- import * as dom from "@src/layout/dom";
7
- import * as mutation from "@src/layout/mutation";
8
-
9
- export function target(evt: UIEvent): Node {
10
- let path = evt.composed && evt.composedPath ? evt.composedPath() : null;
11
- let node = (path && path.length > 0 ? path[0] : evt.target) as Node;
12
- mutation.active(); // Mark active periods of time so mutations can continue uninterrupted
13
- return node && node.nodeType === Node.DOCUMENT_NODE ? (node as Document).documentElement : node;
14
- }
15
-
16
- export function metadata(node: Node, event: Event, text: string = null): TargetMetadata {
17
- // If the node is null, we return a reserved value for id: 0. Valid assignment of id begins from 1+.
18
- let output: TargetMetadata = { id: 0, hash: null, privacy: Privacy.Text };
19
- if (node) {
20
- let value = dom.get(node);
21
- if (value !== null) {
22
- let metadata = value.metadata;
23
- output.id = value.id;
24
- output.hash = value.hash;
25
- output.privacy = metadata.privacy;
26
- if (value.region) { region.track(value.region, event); }
27
- if (metadata.fraud) { fraud.check(metadata.fraud, value.id, text || value.data.value); }
28
- }
29
- }
30
-
31
- return output;
32
- }
1
+ import { Privacy } from "@clarity-types/core";
2
+ import { Event } from "@clarity-types/data";
3
+ import { TargetMetadata } from "@clarity-types/layout";
4
+ import * as fraud from "@src/diagnostic/fraud";
5
+ import * as region from "@src/layout/region";
6
+ import * as dom from "@src/layout/dom";
7
+ import * as mutation from "@src/layout/mutation";
8
+
9
+ export function target(evt: UIEvent): Node {
10
+ let path = evt.composed && evt.composedPath ? evt.composedPath() : null;
11
+ let node = (path && path.length > 0 ? path[0] : evt.target) as Node;
12
+ mutation.active(); // Mark active periods of time so mutations can continue uninterrupted
13
+ return node && node.nodeType === Node.DOCUMENT_NODE ? (node as Document).documentElement : node;
14
+ }
15
+
16
+ export function metadata(node: Node, event: Event, text: string = null): TargetMetadata {
17
+ // If the node is null, we return a reserved value for id: 0. Valid assignment of id begins from 1+.
18
+ let output: TargetMetadata = { id: 0, hash: null, privacy: Privacy.Text };
19
+ if (node) {
20
+ let value = dom.get(node);
21
+ if (value !== null) {
22
+ let metadata = value.metadata;
23
+ output.id = value.id;
24
+ output.hash = value.hash;
25
+ output.privacy = metadata.privacy;
26
+ if (value.region) { region.track(value.region, event); }
27
+ if (metadata.fraud) { fraud.check(metadata.fraud, value.id, text || value.data.value); }
28
+ }
29
+ }
30
+
31
+ return output;
32
+ }
@@ -1,28 +1,28 @@
1
- import { Task, Timer } from "@clarity-types/core";
2
- import { Source } from "@clarity-types/layout";
3
- import * as task from "@src/core/task";
4
- import node from "@src/layout/node";
5
-
6
- export default async function(root: Node, timer: Timer, source: Source, timestamp: number): Promise<void> {
7
- let queue = [root];
8
- while (queue.length > 0) {
9
- let entry = queue.shift();
10
- let next = entry.firstChild;
11
-
12
- while (next) {
13
- queue.push(next);
14
- next = next.nextSibling;
15
- }
16
-
17
- // Check the status of current task to see if we should yield before continuing
18
- let state = task.state(timer);
19
- if (state === Task.Wait) { state = await task.suspend(timer); }
20
- if (state === Task.Stop) { break; }
21
-
22
- // Check if processing a node gives us a pointer to one of its sub nodes for traversal
23
- // E.g. an element node may give us a pointer to traverse shadowDom if shadowRoot property is set
24
- // Or, an iframe from the same origin could give a pointer to it's document for traversing contents of iframe.
25
- let subnode = node(entry, source, timestamp);
26
- if (subnode) { queue.push(subnode); }
27
- }
1
+ import { Task, Timer } from "@clarity-types/core";
2
+ import { Source } from "@clarity-types/layout";
3
+ import * as task from "@src/core/task";
4
+ import node from "@src/layout/node";
5
+
6
+ export default async function(root: Node, timer: Timer, source: Source, timestamp: number): Promise<void> {
7
+ let queue = [root];
8
+ while (queue.length > 0) {
9
+ let entry = queue.shift();
10
+ let next = entry.firstChild;
11
+
12
+ while (next) {
13
+ queue.push(next);
14
+ next = next.nextSibling;
15
+ }
16
+
17
+ // Check the status of current task to see if we should yield before continuing
18
+ let state = task.state(timer);
19
+ if (state === Task.Wait) { state = await task.suspend(timer); }
20
+ if (state === Task.Stop) { break; }
21
+
22
+ // Check if processing a node gives us a pointer to one of its sub nodes for traversal
23
+ // E.g. an element node may give us a pointer to traverse shadowDom if shadowRoot property is set
24
+ // Or, an iframe from the same origin could give a pointer to it's document for traversing contents of iframe.
25
+ let subnode = node(entry, source, timestamp);
26
+ if (subnode) { queue.push(subnode); }
27
+ }
28
28
  }
@@ -1,7 +1,7 @@
1
- export * from "@src/insight/blank";
2
-
3
- export let keys = [];
4
-
5
- /* Intentionally blank module with empty code */
6
- export function hashText(): void {}
7
- export function trigger(): void {}
1
+ export * from "@src/insight/blank";
2
+
3
+ export let keys = [];
4
+
5
+ /* Intentionally blank module with empty code */
6
+ export function hashText(): void {}
7
+ export function trigger(): void {}
@@ -1,31 +1,31 @@
1
- import {Event, Token} from "@clarity-types/data";
2
- import { time } from "@src/core/time";
3
- import { queue } from "@src/data/upload";
4
- import * as navigation from "@src/performance/navigation";
5
-
6
- export default async function(type: Event): Promise<void> {
7
- let t = time();
8
- let tokens: Token[] = [t, type];
9
- switch (type) {
10
- case Event.Navigation:
11
- tokens.push(navigation.data.fetchStart);
12
- tokens.push(navigation.data.connectStart);
13
- tokens.push(navigation.data.connectEnd);
14
- tokens.push(navigation.data.requestStart);
15
- tokens.push(navigation.data.responseStart);
16
- tokens.push(navigation.data.responseEnd);
17
- tokens.push(navigation.data.domInteractive);
18
- tokens.push(navigation.data.domComplete);
19
- tokens.push(navigation.data.loadEventStart);
20
- tokens.push(navigation.data.loadEventEnd);
21
- tokens.push(navigation.data.redirectCount);
22
- tokens.push(navigation.data.size);
23
- tokens.push(navigation.data.type);
24
- tokens.push(navigation.data.protocol);
25
- tokens.push(navigation.data.encodedSize);
26
- tokens.push(navigation.data.decodedSize);
27
- navigation.reset();
28
- queue(tokens);
29
- break;
30
- }
31
- }
1
+ import {Event, Token} from "@clarity-types/data";
2
+ import { time } from "@src/core/time";
3
+ import { queue } from "@src/data/upload";
4
+ import * as navigation from "@src/performance/navigation";
5
+
6
+ export default async function(type: Event): Promise<void> {
7
+ let t = time();
8
+ let tokens: Token[] = [t, type];
9
+ switch (type) {
10
+ case Event.Navigation:
11
+ tokens.push(navigation.data.fetchStart);
12
+ tokens.push(navigation.data.connectStart);
13
+ tokens.push(navigation.data.connectEnd);
14
+ tokens.push(navigation.data.requestStart);
15
+ tokens.push(navigation.data.responseStart);
16
+ tokens.push(navigation.data.responseEnd);
17
+ tokens.push(navigation.data.domInteractive);
18
+ tokens.push(navigation.data.domComplete);
19
+ tokens.push(navigation.data.loadEventStart);
20
+ tokens.push(navigation.data.loadEventEnd);
21
+ tokens.push(navigation.data.redirectCount);
22
+ tokens.push(navigation.data.size);
23
+ tokens.push(navigation.data.type);
24
+ tokens.push(navigation.data.protocol);
25
+ tokens.push(navigation.data.encodedSize);
26
+ tokens.push(navigation.data.decodedSize);
27
+ navigation.reset();
28
+ queue(tokens);
29
+ break;
30
+ }
31
+ }
@@ -1,14 +1,14 @@
1
- import { FunctionNames } from "@clarity-types/performance";
2
- import * as navigation from "@src/performance/navigation";
3
- import * as observer from "@src/performance/observer";
4
-
5
- export function start(): void {
6
- start.dn = FunctionNames.PerformanceStart;
7
- navigation.reset();
8
- observer.start();
9
- }
10
-
11
- export function stop(): void {
12
- observer.stop();
13
- navigation.reset();
14
- }
1
+ import { FunctionNames } from "@clarity-types/performance";
2
+ import * as navigation from "@src/performance/navigation";
3
+ import * as observer from "@src/performance/observer";
4
+
5
+ export function start(): void {
6
+ start.dn = FunctionNames.PerformanceStart;
7
+ navigation.reset();
8
+ observer.start();
9
+ }
10
+
11
+ export function stop(): void {
12
+ observer.stop();
13
+ navigation.reset();
14
+ }