@openreplay/tracker 4.1.7 → 4.1.9
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/cjs/app/index.js +8 -6
- package/cjs/index.js +1 -1
- package/cjs/modules/timing.js +2 -2
- package/cjs/modules/viewport.js +3 -1
- package/cjs/utils.d.ts +2 -0
- package/cjs/utils.js +15 -14
- package/lib/app/index.js +9 -7
- package/lib/index.js +1 -1
- package/lib/modules/timing.js +2 -2
- package/lib/modules/viewport.js +3 -1
- package/lib/utils.d.ts +2 -0
- package/lib/utils.js +12 -13
- package/package.json +1 -1
package/cjs/app/index.js
CHANGED
|
@@ -33,7 +33,7 @@ class App {
|
|
|
33
33
|
this.stopCallbacks = [];
|
|
34
34
|
this.commitCallbacks = [];
|
|
35
35
|
this.activityState = ActivityState.NotActive;
|
|
36
|
-
this.version = '4.1.
|
|
36
|
+
this.version = '4.1.8'; // TODO: version compatability check inside each plugin.
|
|
37
37
|
this.delay = 0;
|
|
38
38
|
this.projectKey = projectKey;
|
|
39
39
|
this.options = Object.assign({
|
|
@@ -276,13 +276,16 @@ class App {
|
|
|
276
276
|
return Promise.resolve(UnsuccessfulStart('OpenReplay: trying to call `start()` on the instance that has been started already.'));
|
|
277
277
|
}
|
|
278
278
|
this.activityState = ActivityState.Starting;
|
|
279
|
+
(0, utils_js_1.adjustTimeOrigin)();
|
|
279
280
|
if (startOpts.sessionHash) {
|
|
280
281
|
this.session.applySessionHash(startOpts.sessionHash);
|
|
281
282
|
}
|
|
282
|
-
if (startOpts.forceNew) {
|
|
283
|
+
if (startOpts.forceNew) {
|
|
284
|
+
// Reset session metadata only if requested directly
|
|
283
285
|
this.session.reset();
|
|
284
286
|
}
|
|
285
287
|
this.session.assign({
|
|
288
|
+
// MBTODO: maybe it would make sense to `forceNew` if the `userID` was changed
|
|
286
289
|
userID: startOpts.userID,
|
|
287
290
|
metadata: startOpts.metadata,
|
|
288
291
|
});
|
|
@@ -327,7 +330,7 @@ class App {
|
|
|
327
330
|
if (this.activityState === ActivityState.NotActive) {
|
|
328
331
|
return Promise.reject('Tracker stopped during authorisation');
|
|
329
332
|
}
|
|
330
|
-
const { token, userUUID, projectID, beaconSizeLimit, delay, //
|
|
333
|
+
const { token, userUUID, projectID, beaconSizeLimit, delay, // derived from token
|
|
331
334
|
sessionID, // derived from token
|
|
332
335
|
startTimestamp, // real startTS (server time), derived from sessionID
|
|
333
336
|
} = r;
|
|
@@ -346,9 +349,8 @@ class App {
|
|
|
346
349
|
timestamp: startTimestamp || timestamp,
|
|
347
350
|
projectID,
|
|
348
351
|
});
|
|
349
|
-
//
|
|
350
|
-
Object.entries(this.session.getInfo().metadata)
|
|
351
|
-
.forEach(([key, value]) => this.send((0, messages_gen_js_1.Metadata)(key, value)));
|
|
352
|
+
// (Re)send Metadata for the case of a new session
|
|
353
|
+
Object.entries(this.session.getInfo().metadata).forEach(([key, value]) => this.send((0, messages_gen_js_1.Metadata)(key, value)));
|
|
352
354
|
this.localStorage.setItem(this.options.local_uuid_key, userUUID);
|
|
353
355
|
this.worker.postMessage({
|
|
354
356
|
type: 'auth',
|
package/cjs/index.js
CHANGED
|
@@ -138,7 +138,7 @@ class API {
|
|
|
138
138
|
// no-cors issue only with text/plain or not-set Content-Type
|
|
139
139
|
// req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
|
140
140
|
req.send(JSON.stringify({
|
|
141
|
-
trackerVersion: '4.1.
|
|
141
|
+
trackerVersion: '4.1.8',
|
|
142
142
|
projectKey: options.projectKey,
|
|
143
143
|
doNotTrack,
|
|
144
144
|
// TODO: add precise reason (an exact API missing)
|
package/cjs/modules/timing.js
CHANGED
|
@@ -144,9 +144,9 @@ function default_1(app, opts) {
|
|
|
144
144
|
const speedIndex = paintBlocks === null
|
|
145
145
|
? 0
|
|
146
146
|
: calculateSpeedIndex(firstContentfulPaint || firstPaint, paintBlocks);
|
|
147
|
+
const { domContentLoadedEventEnd, navigationStart } = performance.timing;
|
|
147
148
|
const timeToInteractive = interactiveWindowTickTime === null
|
|
148
|
-
? Math.max(interactiveWindowStartTime, firstContentfulPaint,
|
|
149
|
-
0)
|
|
149
|
+
? Math.max(interactiveWindowStartTime, firstContentfulPaint, domContentLoadedEventEnd - navigationStart || 0)
|
|
150
150
|
: 0;
|
|
151
151
|
app.send((0, messages_gen_js_1.PageRenderTiming)(speedIndex, firstContentfulPaint > visuallyComplete ? firstContentfulPaint : visuallyComplete, timeToInteractive));
|
|
152
152
|
}
|
package/cjs/modules/viewport.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_js_1 = require("../utils.js");
|
|
3
4
|
const messages_gen_js_1 = require("../app/messages.gen.js");
|
|
4
5
|
function default_1(app) {
|
|
5
6
|
let url, width, height;
|
|
6
|
-
let navigationStart
|
|
7
|
+
let navigationStart;
|
|
7
8
|
const sendSetPageLocation = app.safe(() => {
|
|
8
9
|
const { URL } = document;
|
|
9
10
|
if (URL !== url) {
|
|
@@ -25,6 +26,7 @@ function default_1(app) {
|
|
|
25
26
|
: app.safe(() => app.send((0, messages_gen_js_1.SetPageVisibility)(document.hidden)));
|
|
26
27
|
app.attachStartCallback(() => {
|
|
27
28
|
url = '';
|
|
29
|
+
navigationStart = (0, utils_js_1.getTimeOrigin)();
|
|
28
30
|
width = height = -1;
|
|
29
31
|
sendSetPageLocation();
|
|
30
32
|
sendSetViewportSize();
|
package/cjs/utils.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare const IN_BROWSER: boolean;
|
|
2
2
|
export declare const IS_FIREFOX: false | RegExpMatchArray | null;
|
|
3
3
|
export declare const MAX_STR_LEN = 100000;
|
|
4
|
+
export declare function adjustTimeOrigin(): void;
|
|
5
|
+
export declare function getTimeOrigin(): number;
|
|
4
6
|
export declare const now: () => number;
|
|
5
7
|
export declare const stars: (str: string) => string;
|
|
6
8
|
export declare function normSpaces(str: string): string;
|
package/cjs/utils.js
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hasOpenreplayAttribute = exports.getLabelAttribute = exports.deprecationWarn = exports.DOCS_HOST = exports.isURL = exports.normSpaces = exports.stars = exports.now = exports.MAX_STR_LEN = exports.IS_FIREFOX = exports.IN_BROWSER = void 0;
|
|
3
|
+
exports.hasOpenreplayAttribute = exports.getLabelAttribute = exports.deprecationWarn = exports.DOCS_HOST = exports.isURL = exports.normSpaces = exports.stars = exports.now = exports.getTimeOrigin = exports.adjustTimeOrigin = exports.MAX_STR_LEN = exports.IS_FIREFOX = exports.IN_BROWSER = void 0;
|
|
4
4
|
const DEPRECATED_ATTRS = { htmlmasked: 'hidden', masked: 'obscured' };
|
|
5
5
|
exports.IN_BROWSER = !(typeof window === 'undefined');
|
|
6
6
|
exports.IS_FIREFOX = exports.IN_BROWSER && navigator.userAgent.match(/firefox|fxios/i);
|
|
7
7
|
exports.MAX_STR_LEN = 1e5;
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
exports.
|
|
20
|
-
|
|
8
|
+
// Buggy to use `performance.timeOrigin || performance.timing.navigationStart`
|
|
9
|
+
// https://github.com/mdn/content/issues/4713
|
|
10
|
+
// Maybe move to timer/ticker
|
|
11
|
+
let timeOrigin = exports.IN_BROWSER ? Date.now() - performance.now() : 0;
|
|
12
|
+
function adjustTimeOrigin() {
|
|
13
|
+
timeOrigin = Date.now() - performance.now();
|
|
14
|
+
}
|
|
15
|
+
exports.adjustTimeOrigin = adjustTimeOrigin;
|
|
16
|
+
function getTimeOrigin() {
|
|
17
|
+
return timeOrigin;
|
|
18
|
+
}
|
|
19
|
+
exports.getTimeOrigin = getTimeOrigin;
|
|
20
|
+
exports.now = exports.IN_BROWSER && !!performance.now
|
|
21
|
+
? () => Math.round(performance.now() + timeOrigin)
|
|
21
22
|
: () => Date.now();
|
|
22
23
|
exports.stars = 'repeat' in String.prototype
|
|
23
24
|
? (str) => '*'.repeat(str.length)
|
package/lib/app/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Timestamp, Metadata, UserID } from './messages.gen.js';
|
|
2
|
-
import { now } from '../utils.js';
|
|
2
|
+
import { now, adjustTimeOrigin } from '../utils.js';
|
|
3
3
|
import Nodes from './nodes.js';
|
|
4
4
|
import Observer from './observer/top_observer.js';
|
|
5
5
|
import Sanitizer from './sanitizer.js';
|
|
@@ -30,7 +30,7 @@ export default class App {
|
|
|
30
30
|
this.stopCallbacks = [];
|
|
31
31
|
this.commitCallbacks = [];
|
|
32
32
|
this.activityState = ActivityState.NotActive;
|
|
33
|
-
this.version = '4.1.
|
|
33
|
+
this.version = '4.1.8'; // TODO: version compatability check inside each plugin.
|
|
34
34
|
this.delay = 0;
|
|
35
35
|
this.projectKey = projectKey;
|
|
36
36
|
this.options = Object.assign({
|
|
@@ -273,13 +273,16 @@ export default class App {
|
|
|
273
273
|
return Promise.resolve(UnsuccessfulStart('OpenReplay: trying to call `start()` on the instance that has been started already.'));
|
|
274
274
|
}
|
|
275
275
|
this.activityState = ActivityState.Starting;
|
|
276
|
+
adjustTimeOrigin();
|
|
276
277
|
if (startOpts.sessionHash) {
|
|
277
278
|
this.session.applySessionHash(startOpts.sessionHash);
|
|
278
279
|
}
|
|
279
|
-
if (startOpts.forceNew) {
|
|
280
|
+
if (startOpts.forceNew) {
|
|
281
|
+
// Reset session metadata only if requested directly
|
|
280
282
|
this.session.reset();
|
|
281
283
|
}
|
|
282
284
|
this.session.assign({
|
|
285
|
+
// MBTODO: maybe it would make sense to `forceNew` if the `userID` was changed
|
|
283
286
|
userID: startOpts.userID,
|
|
284
287
|
metadata: startOpts.metadata,
|
|
285
288
|
});
|
|
@@ -324,7 +327,7 @@ export default class App {
|
|
|
324
327
|
if (this.activityState === ActivityState.NotActive) {
|
|
325
328
|
return Promise.reject('Tracker stopped during authorisation');
|
|
326
329
|
}
|
|
327
|
-
const { token, userUUID, projectID, beaconSizeLimit, delay, //
|
|
330
|
+
const { token, userUUID, projectID, beaconSizeLimit, delay, // derived from token
|
|
328
331
|
sessionID, // derived from token
|
|
329
332
|
startTimestamp, // real startTS (server time), derived from sessionID
|
|
330
333
|
} = r;
|
|
@@ -343,9 +346,8 @@ export default class App {
|
|
|
343
346
|
timestamp: startTimestamp || timestamp,
|
|
344
347
|
projectID,
|
|
345
348
|
});
|
|
346
|
-
//
|
|
347
|
-
Object.entries(this.session.getInfo().metadata)
|
|
348
|
-
.forEach(([key, value]) => this.send(Metadata(key, value)));
|
|
349
|
+
// (Re)send Metadata for the case of a new session
|
|
350
|
+
Object.entries(this.session.getInfo().metadata).forEach(([key, value]) => this.send(Metadata(key, value)));
|
|
349
351
|
this.localStorage.setItem(this.options.local_uuid_key, userUUID);
|
|
350
352
|
this.worker.postMessage({
|
|
351
353
|
type: 'auth',
|
package/lib/index.js
CHANGED
|
@@ -133,7 +133,7 @@ export default class API {
|
|
|
133
133
|
// no-cors issue only with text/plain or not-set Content-Type
|
|
134
134
|
// req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
|
135
135
|
req.send(JSON.stringify({
|
|
136
|
-
trackerVersion: '4.1.
|
|
136
|
+
trackerVersion: '4.1.8',
|
|
137
137
|
projectKey: options.projectKey,
|
|
138
138
|
doNotTrack,
|
|
139
139
|
// TODO: add precise reason (an exact API missing)
|
package/lib/modules/timing.js
CHANGED
|
@@ -142,9 +142,9 @@ export default function (app, opts) {
|
|
|
142
142
|
const speedIndex = paintBlocks === null
|
|
143
143
|
? 0
|
|
144
144
|
: calculateSpeedIndex(firstContentfulPaint || firstPaint, paintBlocks);
|
|
145
|
+
const { domContentLoadedEventEnd, navigationStart } = performance.timing;
|
|
145
146
|
const timeToInteractive = interactiveWindowTickTime === null
|
|
146
|
-
? Math.max(interactiveWindowStartTime, firstContentfulPaint,
|
|
147
|
-
0)
|
|
147
|
+
? Math.max(interactiveWindowStartTime, firstContentfulPaint, domContentLoadedEventEnd - navigationStart || 0)
|
|
148
148
|
: 0;
|
|
149
149
|
app.send(PageRenderTiming(speedIndex, firstContentfulPaint > visuallyComplete ? firstContentfulPaint : visuallyComplete, timeToInteractive));
|
|
150
150
|
}
|
package/lib/modules/viewport.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { getTimeOrigin } from '../utils.js';
|
|
1
2
|
import { SetPageLocation, SetViewportSize, SetPageVisibility } from '../app/messages.gen.js';
|
|
2
3
|
export default function (app) {
|
|
3
4
|
let url, width, height;
|
|
4
|
-
let navigationStart
|
|
5
|
+
let navigationStart;
|
|
5
6
|
const sendSetPageLocation = app.safe(() => {
|
|
6
7
|
const { URL } = document;
|
|
7
8
|
if (URL !== url) {
|
|
@@ -23,6 +24,7 @@ export default function (app) {
|
|
|
23
24
|
: app.safe(() => app.send(SetPageVisibility(document.hidden)));
|
|
24
25
|
app.attachStartCallback(() => {
|
|
25
26
|
url = '';
|
|
27
|
+
navigationStart = getTimeOrigin();
|
|
26
28
|
width = height = -1;
|
|
27
29
|
sendSetPageLocation();
|
|
28
30
|
sendSetViewportSize();
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare const IN_BROWSER: boolean;
|
|
2
2
|
export declare const IS_FIREFOX: false | RegExpMatchArray | null;
|
|
3
3
|
export declare const MAX_STR_LEN = 100000;
|
|
4
|
+
export declare function adjustTimeOrigin(): void;
|
|
5
|
+
export declare function getTimeOrigin(): number;
|
|
4
6
|
export declare const now: () => number;
|
|
5
7
|
export declare const stars: (str: string) => string;
|
|
6
8
|
export declare function normSpaces(str: string): string;
|
package/lib/utils.js
CHANGED
|
@@ -2,19 +2,18 @@ const DEPRECATED_ATTRS = { htmlmasked: 'hidden', masked: 'obscured' };
|
|
|
2
2
|
export const IN_BROWSER = !(typeof window === 'undefined');
|
|
3
3
|
export const IS_FIREFOX = IN_BROWSER && navigator.userAgent.match(/firefox|fxios/i);
|
|
4
4
|
export const MAX_STR_LEN = 1e5;
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
? () => Math.round(performance.now() + navigationStart)
|
|
5
|
+
// Buggy to use `performance.timeOrigin || performance.timing.navigationStart`
|
|
6
|
+
// https://github.com/mdn/content/issues/4713
|
|
7
|
+
// Maybe move to timer/ticker
|
|
8
|
+
let timeOrigin = IN_BROWSER ? Date.now() - performance.now() : 0;
|
|
9
|
+
export function adjustTimeOrigin() {
|
|
10
|
+
timeOrigin = Date.now() - performance.now();
|
|
11
|
+
}
|
|
12
|
+
export function getTimeOrigin() {
|
|
13
|
+
return timeOrigin;
|
|
14
|
+
}
|
|
15
|
+
export const now = IN_BROWSER && !!performance.now
|
|
16
|
+
? () => Math.round(performance.now() + timeOrigin)
|
|
18
17
|
: () => Date.now();
|
|
19
18
|
export const stars = 'repeat' in String.prototype
|
|
20
19
|
? (str) => '*'.repeat(str.length)
|