@openreplay/tracker 3.5.9 → 3.5.10

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.
@@ -8,16 +8,18 @@ import type { Options as ObserverOptions } from "./observer/top_observer.js";
8
8
  import type { Options as SanitizerOptions } from "./sanitizer.js";
9
9
  import type { Options as LoggerOptions } from "./logger.js";
10
10
  import type { Options as WebworkerOptions } from "../../webworker/types.js";
11
- export interface OnStartInfo {
12
- sessionID: string;
13
- sessionToken: string;
14
- userUUID: string;
15
- }
16
11
  export interface StartOptions {
17
12
  userID?: string;
18
13
  metadata?: Record<string, string>;
19
14
  forceNew?: boolean;
20
15
  }
16
+ export interface OnStartInfo {
17
+ sessionID: string;
18
+ sessionToken: string;
19
+ userUUID: string;
20
+ }
21
+ declare type StartCallback = (i: OnStartInfo) => void;
22
+ declare type CommitCallback = (messages: Array<Message>) => void;
21
23
  declare type AppOptions = {
22
24
  revID: string;
23
25
  node_id: string;
@@ -31,11 +33,9 @@ declare type AppOptions = {
31
33
  __is_snippet: boolean;
32
34
  __debug_report_edp: string | null;
33
35
  __debug__?: LoggerOptions;
34
- onStart?: (info: OnStartInfo) => void;
36
+ onStart?: StartCallback;
35
37
  } & WebworkerOptions;
36
38
  export declare type Options = AppOptions & ObserverOptions & SanitizerOptions;
37
- declare type Callback = () => void;
38
- declare type CommitCallback = (messages: Array<Message>) => void;
39
39
  export declare const CANCELED = "canceled";
40
40
  export declare const DEFAULT_INGEST_POINT = "https://api.openreplay.com/ingest";
41
41
  export default class App {
@@ -58,13 +58,12 @@ export default class App {
58
58
  private readonly worker?;
59
59
  constructor(projectKey: string, sessionToken: string | null | undefined, options: Partial<Options>);
60
60
  private _debug;
61
- private readonly preStartMessages;
62
61
  send(message: Message, urgent?: boolean): void;
63
62
  private commit;
64
63
  safe<T extends (...args: any[]) => void>(fn: T): T;
65
64
  attachCommitCallback(cb: CommitCallback): void;
66
- attachStartCallback(cb: Callback): void;
67
- attachStopCallback(cb: Callback): void;
65
+ attachStartCallback(cb: StartCallback): void;
66
+ attachStopCallback(cb: Function): void;
68
67
  attachEventListener(target: EventTarget, type: string, listener: EventListener, useSafe?: boolean, useCapture?: boolean): void;
69
68
  checkRequiredVersion(version: string): boolean;
70
69
  private getStartInfo;
package/cjs/app/index.js CHANGED
@@ -29,8 +29,7 @@ class App {
29
29
  this.stopCallbacks = [];
30
30
  this.commitCallbacks = [];
31
31
  this.activityState = ActivityState.NotActive;
32
- this.version = '3.5.9'; // TODO: version compatability check inside each plugin.
33
- this.preStartMessages = [];
32
+ this.version = '3.5.10'; // TODO: version compatability check inside each plugin.
34
33
  this.projectKey = projectKey;
35
34
  this.options = Object.assign({
36
35
  revID: '',
@@ -103,15 +102,12 @@ class App {
103
102
  if (this.activityState === ActivityState.NotActive) {
104
103
  return;
105
104
  }
106
- if (this.activityState === ActivityState.Starting) {
107
- this.preStartMessages.push(message);
108
- }
109
- if (this.preStartMessages.length) {
110
- this.messages.push(...this.preStartMessages);
111
- this.preStartMessages.length = 0;
112
- }
113
105
  this.messages.push(message);
114
- if (urgent) {
106
+ // TODO: commit on start if there were `urgent` sends;
107
+ // Clearify where urgent can be used for;
108
+ // Clearify workflow for each type of message in case it was sent before start
109
+ // (like Fetch before start; maybe add an option "preCapture: boolean" or sth alike)
110
+ if (this.activityState === ActivityState.Active && urgent) {
115
111
  this.commit();
116
112
  }
117
113
  }
@@ -292,12 +288,12 @@ class App {
292
288
  beaconSizeLimit
293
289
  };
294
290
  this.worker.postMessage(startWorkerMsg);
295
- this.startCallbacks.forEach((cb) => cb());
291
+ const onStartInfo = { sessionToken: token, userUUID, sessionID };
292
+ this.startCallbacks.forEach((cb) => cb(onStartInfo));
296
293
  this.observer.observe();
297
294
  this.ticker.start();
298
295
  this.notify.log("OpenReplay tracking started.");
299
296
  // TODO: get rid of onStart
300
- const onStartInfo = { sessionToken: token, userUUID, sessionID };
301
297
  if (typeof this.options.onStart === 'function') {
302
298
  this.options.onStart(onStartInfo);
303
299
  }
package/cjs/index.js CHANGED
@@ -127,7 +127,7 @@ class API {
127
127
  // no-cors issue only with text/plain or not-set Content-Type
128
128
  // req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
129
129
  req.send(JSON.stringify({
130
- trackerVersion: '3.5.9',
130
+ trackerVersion: '3.5.10',
131
131
  projectKey: options.projectKey,
132
132
  doNotTrack,
133
133
  // TODO: add precise reason (an exact API missing)
@@ -70,18 +70,6 @@ function default_1(app, opts) {
70
70
  if (!options.captureResourceTimings) {
71
71
  return;
72
72
  } // Resources are necessary for all timings
73
- const mQueue = [];
74
- function sendOnStart(m) {
75
- if (app.active()) {
76
- app.send(m);
77
- }
78
- else {
79
- mQueue.push(m);
80
- }
81
- }
82
- app.attachStartCallback(function () {
83
- mQueue.forEach(m => app.send(m));
84
- });
85
73
  let resources = {};
86
74
  function resourceTiming(entry) {
87
75
  if (entry.duration < 0 || !(0, utils_js_1.isURL)(entry.name) || app.isServiceURL(entry.name))
@@ -89,15 +77,24 @@ function default_1(app, opts) {
89
77
  if (resources !== null) {
90
78
  resources[entry.name] = entry.startTime + entry.duration;
91
79
  }
92
- sendOnStart(new index_js_1.ResourceTiming(entry.startTime + performance.timing.navigationStart, entry.duration, entry.responseStart && entry.startTime
80
+ app.send(new index_js_1.ResourceTiming(entry.startTime + performance.timing.navigationStart, entry.duration, entry.responseStart && entry.startTime
93
81
  ? entry.responseStart - entry.startTime
94
82
  : 0, entry.transferSize > entry.encodedBodySize
95
83
  ? entry.transferSize - entry.encodedBodySize
96
84
  : 0, entry.encodedBodySize || 0, entry.decodedBodySize || 0, entry.name, entry.initiatorType));
97
85
  }
98
86
  const observer = new PerformanceObserver((list) => list.getEntries().forEach(resourceTiming));
99
- performance.getEntriesByType('resource').forEach(resourceTiming);
100
- observer.observe({ entryTypes: ['resource'] });
87
+ let prevSessionID;
88
+ app.attachStartCallback(function ({ sessionID }) {
89
+ if (sessionID !== prevSessionID) { // Send past page resources on a newly started session
90
+ performance.getEntriesByType('resource').forEach(resourceTiming);
91
+ prevSessionID = sessionID;
92
+ }
93
+ observer.observe({ entryTypes: ['resource'] });
94
+ });
95
+ app.attachStopCallback(function () {
96
+ observer.disconnect();
97
+ });
101
98
  let firstPaint = 0, firstContentfulPaint = 0;
102
99
  if (options.capturePageLoadTimings) {
103
100
  let pageLoadTimingSent = false;
@@ -8,16 +8,18 @@ import type { Options as ObserverOptions } from "./observer/top_observer.js";
8
8
  import type { Options as SanitizerOptions } from "./sanitizer.js";
9
9
  import type { Options as LoggerOptions } from "./logger.js";
10
10
  import type { Options as WebworkerOptions } from "../../webworker/types.js";
11
- export interface OnStartInfo {
12
- sessionID: string;
13
- sessionToken: string;
14
- userUUID: string;
15
- }
16
11
  export interface StartOptions {
17
12
  userID?: string;
18
13
  metadata?: Record<string, string>;
19
14
  forceNew?: boolean;
20
15
  }
16
+ export interface OnStartInfo {
17
+ sessionID: string;
18
+ sessionToken: string;
19
+ userUUID: string;
20
+ }
21
+ declare type StartCallback = (i: OnStartInfo) => void;
22
+ declare type CommitCallback = (messages: Array<Message>) => void;
21
23
  declare type AppOptions = {
22
24
  revID: string;
23
25
  node_id: string;
@@ -31,11 +33,9 @@ declare type AppOptions = {
31
33
  __is_snippet: boolean;
32
34
  __debug_report_edp: string | null;
33
35
  __debug__?: LoggerOptions;
34
- onStart?: (info: OnStartInfo) => void;
36
+ onStart?: StartCallback;
35
37
  } & WebworkerOptions;
36
38
  export declare type Options = AppOptions & ObserverOptions & SanitizerOptions;
37
- declare type Callback = () => void;
38
- declare type CommitCallback = (messages: Array<Message>) => void;
39
39
  export declare const CANCELED = "canceled";
40
40
  export declare const DEFAULT_INGEST_POINT = "https://api.openreplay.com/ingest";
41
41
  export default class App {
@@ -58,13 +58,12 @@ export default class App {
58
58
  private readonly worker?;
59
59
  constructor(projectKey: string, sessionToken: string | null | undefined, options: Partial<Options>);
60
60
  private _debug;
61
- private readonly preStartMessages;
62
61
  send(message: Message, urgent?: boolean): void;
63
62
  private commit;
64
63
  safe<T extends (...args: any[]) => void>(fn: T): T;
65
64
  attachCommitCallback(cb: CommitCallback): void;
66
- attachStartCallback(cb: Callback): void;
67
- attachStopCallback(cb: Callback): void;
65
+ attachStartCallback(cb: StartCallback): void;
66
+ attachStopCallback(cb: Function): void;
68
67
  attachEventListener(target: EventTarget, type: string, listener: EventListener, useSafe?: boolean, useCapture?: boolean): void;
69
68
  checkRequiredVersion(version: string): boolean;
70
69
  private getStartInfo;
package/lib/app/index.js CHANGED
@@ -26,8 +26,7 @@ export default class App {
26
26
  this.stopCallbacks = [];
27
27
  this.commitCallbacks = [];
28
28
  this.activityState = ActivityState.NotActive;
29
- this.version = '3.5.9'; // TODO: version compatability check inside each plugin.
30
- this.preStartMessages = [];
29
+ this.version = '3.5.10'; // TODO: version compatability check inside each plugin.
31
30
  this.projectKey = projectKey;
32
31
  this.options = Object.assign({
33
32
  revID: '',
@@ -100,15 +99,12 @@ export default class App {
100
99
  if (this.activityState === ActivityState.NotActive) {
101
100
  return;
102
101
  }
103
- if (this.activityState === ActivityState.Starting) {
104
- this.preStartMessages.push(message);
105
- }
106
- if (this.preStartMessages.length) {
107
- this.messages.push(...this.preStartMessages);
108
- this.preStartMessages.length = 0;
109
- }
110
102
  this.messages.push(message);
111
- if (urgent) {
103
+ // TODO: commit on start if there were `urgent` sends;
104
+ // Clearify where urgent can be used for;
105
+ // Clearify workflow for each type of message in case it was sent before start
106
+ // (like Fetch before start; maybe add an option "preCapture: boolean" or sth alike)
107
+ if (this.activityState === ActivityState.Active && urgent) {
112
108
  this.commit();
113
109
  }
114
110
  }
@@ -289,12 +285,12 @@ export default class App {
289
285
  beaconSizeLimit
290
286
  };
291
287
  this.worker.postMessage(startWorkerMsg);
292
- this.startCallbacks.forEach((cb) => cb());
288
+ const onStartInfo = { sessionToken: token, userUUID, sessionID };
289
+ this.startCallbacks.forEach((cb) => cb(onStartInfo));
293
290
  this.observer.observe();
294
291
  this.ticker.start();
295
292
  this.notify.log("OpenReplay tracking started.");
296
293
  // TODO: get rid of onStart
297
- const onStartInfo = { sessionToken: token, userUUID, sessionID };
298
294
  if (typeof this.options.onStart === 'function') {
299
295
  this.options.onStart(onStartInfo);
300
296
  }
package/lib/index.js CHANGED
@@ -123,7 +123,7 @@ export default class API {
123
123
  // no-cors issue only with text/plain or not-set Content-Type
124
124
  // req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
125
125
  req.send(JSON.stringify({
126
- trackerVersion: '3.5.9',
126
+ trackerVersion: '3.5.10',
127
127
  projectKey: options.projectKey,
128
128
  doNotTrack,
129
129
  // TODO: add precise reason (an exact API missing)
@@ -68,18 +68,6 @@ export default function (app, opts) {
68
68
  if (!options.captureResourceTimings) {
69
69
  return;
70
70
  } // Resources are necessary for all timings
71
- const mQueue = [];
72
- function sendOnStart(m) {
73
- if (app.active()) {
74
- app.send(m);
75
- }
76
- else {
77
- mQueue.push(m);
78
- }
79
- }
80
- app.attachStartCallback(function () {
81
- mQueue.forEach(m => app.send(m));
82
- });
83
71
  let resources = {};
84
72
  function resourceTiming(entry) {
85
73
  if (entry.duration < 0 || !isURL(entry.name) || app.isServiceURL(entry.name))
@@ -87,15 +75,24 @@ export default function (app, opts) {
87
75
  if (resources !== null) {
88
76
  resources[entry.name] = entry.startTime + entry.duration;
89
77
  }
90
- sendOnStart(new ResourceTiming(entry.startTime + performance.timing.navigationStart, entry.duration, entry.responseStart && entry.startTime
78
+ app.send(new ResourceTiming(entry.startTime + performance.timing.navigationStart, entry.duration, entry.responseStart && entry.startTime
91
79
  ? entry.responseStart - entry.startTime
92
80
  : 0, entry.transferSize > entry.encodedBodySize
93
81
  ? entry.transferSize - entry.encodedBodySize
94
82
  : 0, entry.encodedBodySize || 0, entry.decodedBodySize || 0, entry.name, entry.initiatorType));
95
83
  }
96
84
  const observer = new PerformanceObserver((list) => list.getEntries().forEach(resourceTiming));
97
- performance.getEntriesByType('resource').forEach(resourceTiming);
98
- observer.observe({ entryTypes: ['resource'] });
85
+ let prevSessionID;
86
+ app.attachStartCallback(function ({ sessionID }) {
87
+ if (sessionID !== prevSessionID) { // Send past page resources on a newly started session
88
+ performance.getEntriesByType('resource').forEach(resourceTiming);
89
+ prevSessionID = sessionID;
90
+ }
91
+ observer.observe({ entryTypes: ['resource'] });
92
+ });
93
+ app.attachStopCallback(function () {
94
+ observer.disconnect();
95
+ });
99
96
  let firstPaint = 0, firstContentfulPaint = 0;
100
97
  if (options.capturePageLoadTimings) {
101
98
  let pageLoadTimingSent = false;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@openreplay/tracker",
3
3
  "description": "The OpenReplay tracker main package",
4
- "version": "3.5.9",
4
+ "version": "3.5.10",
5
5
  "keywords": [
6
6
  "logging",
7
7
  "replay"