clarity-js 0.7.1 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/clarity.insight.js +1 -0
- package/build/clarity.js +126 -90
- package/build/clarity.min.js +1 -1
- package/build/clarity.module.js +126 -88
- package/package.json +15 -13
- package/rollup.config.ts +29 -5
- package/src/clarity.ts +7 -1
- package/src/core/blank.ts +9 -0
- package/src/core/version.ts +1 -1
- package/src/diagnostic/index.ts +3 -3
- package/src/global.ts +3 -19
- package/src/interaction/encode.ts +12 -12
- package/src/layout/mutation.ts +11 -7
- package/src/performance/observer.ts +1 -6
- package/src/queue.ts +31 -0
- package/tsconfig.json +1 -1
- package/types/data.d.ts +3 -0
- package/types/layout.d.ts +1 -1
package/src/layout/mutation.ts
CHANGED
|
@@ -124,12 +124,13 @@ async function process(): Promise<void> {
|
|
|
124
124
|
task.start(timer);
|
|
125
125
|
while (mutations.length > 0) {
|
|
126
126
|
let record = mutations.shift();
|
|
127
|
+
let instance = time();
|
|
127
128
|
for (let mutation of record.mutations) {
|
|
128
129
|
let state = task.state(timer);
|
|
129
130
|
if (state === Task.Wait) { state = await task.suspend(timer); }
|
|
130
131
|
if (state === Task.Stop) { break; }
|
|
131
132
|
let target = mutation.target;
|
|
132
|
-
let type = track(mutation, timer);
|
|
133
|
+
let type = track(mutation, timer, instance);
|
|
133
134
|
if (type && target && target.ownerDocument) { dom.parse(target.ownerDocument); }
|
|
134
135
|
if (type && target && target.nodeType == Node.DOCUMENT_FRAGMENT_NODE && (target as ShadowRoot).host) { dom.parse(target as ShadowRoot); }
|
|
135
136
|
switch (type) {
|
|
@@ -156,7 +157,7 @@ async function process(): Promise<void> {
|
|
|
156
157
|
task.stop(timer);
|
|
157
158
|
}
|
|
158
159
|
|
|
159
|
-
function track(m: MutationRecord, timer: Timer): string {
|
|
160
|
+
function track(m: MutationRecord, timer: Timer, instance: number): string {
|
|
160
161
|
let value = m.target ? dom.get(m.target.parentNode) : null;
|
|
161
162
|
// Check if the parent is already discovered and that the parent is not the document root
|
|
162
163
|
if (value && value.data.tag !== Constant.HTML) {
|
|
@@ -169,19 +170,22 @@ function track(m: MutationRecord, timer: Timer): string {
|
|
|
169
170
|
// In those cases, IDs will change however the selector (which is relative to DOM xPath) remains the same
|
|
170
171
|
let key = [parent, element, m.attributeName, names(m.addedNodes), names(m.removedNodes)].join();
|
|
171
172
|
// Initialize an entry if it doesn't already exist
|
|
172
|
-
history[key] = key in history ? history[key] : [0];
|
|
173
|
+
history[key] = key in history ? history[key] : [0, instance];
|
|
173
174
|
let h = history[key];
|
|
174
175
|
// Lookup any pending nodes queued up for removal, and process them now if we suspended a mutation before
|
|
175
|
-
if (inactive === false && h[0] >= Setting.MutationSuspendThreshold) { processNodeList(h[
|
|
176
|
+
if (inactive === false && h[0] >= Setting.MutationSuspendThreshold) { processNodeList(h[2], Source.ChildListRemove, timer); }
|
|
176
177
|
// Update the counter
|
|
177
|
-
h[0] = inactive ? h[0] + 1 : 1;
|
|
178
|
+
h[0] = inactive ? (h[1] === instance ? h[0] : h[0] + 1) : 1;
|
|
179
|
+
h[1] = instance;
|
|
178
180
|
// Return updated mutation type based on if we have already hit the threshold or not
|
|
179
181
|
if (h[0] === Setting.MutationSuspendThreshold) {
|
|
180
182
|
// Store a reference to removedNodes so we can process them later
|
|
181
183
|
// when we resume mutations again on user interactions
|
|
182
|
-
h[
|
|
184
|
+
h[2] = m.removedNodes;
|
|
183
185
|
return Constant.Suspend;
|
|
184
|
-
} else if (h[0] > Setting.MutationSuspendThreshold) {
|
|
186
|
+
} else if (h[0] > Setting.MutationSuspendThreshold) {
|
|
187
|
+
return Constant.Empty;
|
|
188
|
+
}
|
|
185
189
|
}
|
|
186
190
|
return m.type;
|
|
187
191
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Code, Constant, Dimension, Metric,
|
|
1
|
+
import { Code, Constant, Dimension, Metric, Severity } from "@clarity-types/data";
|
|
2
2
|
import config from "@src/core/config";
|
|
3
3
|
import { bind } from "@src/core/event";
|
|
4
4
|
import measure from "@src/core/measure";
|
|
@@ -81,11 +81,6 @@ function process(entries: PerformanceEntryList): void {
|
|
|
81
81
|
break;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
if (performance && Constant.Memory in performance && performance[Constant.Memory].usedJSHeapSize) {
|
|
85
|
-
// Track consumed memory (MBs) where "memory" API is available
|
|
86
|
-
// Reference: https://developer.mozilla.org/en-US/docs/Web/API/Performance/memory
|
|
87
|
-
metric.max(Metric.UsedMemory, Math.abs(performance[Constant.Memory].usedJSHeapSize / Setting.MegaByte));
|
|
88
|
-
}
|
|
89
84
|
}
|
|
90
85
|
|
|
91
86
|
export function stop(): void {
|
package/src/queue.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Constant } from "@clarity-types/data";
|
|
2
|
+
import * as clarity from "@src/clarity";
|
|
3
|
+
|
|
4
|
+
const w = window;
|
|
5
|
+
const c = Constant.Clarity;
|
|
6
|
+
|
|
7
|
+
export function setup() {
|
|
8
|
+
// Start queuing up calls while Clarity is inactive and we are in a browser enviornment
|
|
9
|
+
if (typeof w !== "undefined") {
|
|
10
|
+
w[c] = function() {
|
|
11
|
+
(w[c].q = w[c].q || []).push(arguments);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function process() {
|
|
17
|
+
if (typeof w !== "undefined") {
|
|
18
|
+
// Do not execute or reset global "clarity" variable if a version of Clarity is already running on the page
|
|
19
|
+
if (w[c] && w[c].v) { return console.warn("Error CL001: Multiple Clarity tags detected."); }
|
|
20
|
+
|
|
21
|
+
// Expose clarity in a browser environment
|
|
22
|
+
// To be efficient about queuing up operations while Clarity is wiring up, we expose clarity.*(args) => clarity(*, args);
|
|
23
|
+
// This allows us to reprocess any calls that we missed once Clarity is available on the page
|
|
24
|
+
// Once Clarity script bundle is loaded on the page, we also initialize a "v" property that holds current version
|
|
25
|
+
// We use the presence or absence of "v" to determine if we are attempting to run a duplicate instance
|
|
26
|
+
let queue = w[c] ? (w[c].q || []) : [];
|
|
27
|
+
w[c] = function(method: string, ...args: any[]): void { return clarity[method](...args); }
|
|
28
|
+
w[c].v = clarity.version;
|
|
29
|
+
while (queue.length > 0) { w[c](...queue.shift()); }
|
|
30
|
+
}
|
|
31
|
+
}
|
package/tsconfig.json
CHANGED
package/types/data.d.ts
CHANGED
|
@@ -97,6 +97,9 @@ export const enum Metric {
|
|
|
97
97
|
Mobile = 27,
|
|
98
98
|
UploadTime = 28,
|
|
99
99
|
SinglePage = 29,
|
|
100
|
+
/**
|
|
101
|
+
* @deprecated Browser API is deprecated. Reference: https://developer.mozilla.org/en-US/docs/Web/API/Performance/memory
|
|
102
|
+
*/
|
|
100
103
|
UsedMemory = 30,
|
|
101
104
|
Iframed = 31,
|
|
102
105
|
MaxTouchPoints = 32,
|
package/types/layout.d.ts
CHANGED
|
@@ -186,7 +186,7 @@ export interface MutationQueue {
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
export interface MutationHistory {
|
|
189
|
-
[key: string]: [/* Count */ number, /* Remove Nodes Buffer */ NodeList?];
|
|
189
|
+
[key: string]: [/* Count */ number, /* Instance */ number, /* Remove Nodes Buffer */ NodeList?];
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
export interface RegionQueue {
|