@openreplay/tracker 3.6.0-beta.0 → 3.6.0

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.
@@ -3,7 +3,8 @@ import App from '../index.js';
3
3
  export interface Options {
4
4
  captureIFrames: boolean;
5
5
  }
6
- declare type ContextCallback = (context: Window & typeof globalThis) => void;
6
+ declare type Context = Window & typeof globalThis;
7
+ declare type ContextCallback = (context: Context) => void;
7
8
  declare type Offset = {
8
9
  top: number;
9
10
  left: number;
@@ -12,6 +13,7 @@ export default class TopObserver extends Observer {
12
13
  private readonly options;
13
14
  constructor(app: App, options: Partial<Options>);
14
15
  private readonly contextCallbacks;
16
+ private readonly contextsSet;
15
17
  attachContextCallback(cb: ContextCallback): void;
16
18
  getDocumentOffset(doc: Document): Offset;
17
19
  private iframeObservers;
@@ -13,6 +13,8 @@ export default class TopObserver extends Observer {
13
13
  constructor(app, options) {
14
14
  super(app, true);
15
15
  this.contextCallbacks = [];
16
+ // Attached once per Tracker instance
17
+ this.contextsSet = new Set();
16
18
  this.iframeObservers = [];
17
19
  this.shadowRootObservers = [];
18
20
  this.options = Object.assign({
@@ -33,7 +35,6 @@ export default class TopObserver extends Observer {
33
35
  }
34
36
  });
35
37
  }
36
- // Attached once per Tracker instance
37
38
  attachContextCallback(cb) {
38
39
  this.contextCallbacks.push(cb);
39
40
  }
@@ -68,7 +69,12 @@ export default class TopObserver extends Observer {
68
69
  };
69
70
  };
70
71
  }
71
- if (currentWin && currentWin !== win) {
72
+ if (currentWin &&
73
+ // Sometimes currentWin.window is null (not in specification). Such window object is not functional
74
+ currentWin === currentWin.window &&
75
+ !this.contextsSet.has(currentWin) // for each context callbacks called once per Tracker (TopObserver) instance
76
+ ) {
77
+ this.contextsSet.add(currentWin);
72
78
  //@ts-ignore https://github.com/microsoft/TypeScript/issues/41684
73
79
  this.contextCallbacks.forEach((cb) => cb(currentWin));
74
80
  win = currentWin;
@@ -4,6 +4,7 @@ interface SessionInfo {
4
4
  metadata: Record<string, string>;
5
5
  userID: string | null;
6
6
  timestamp: number;
7
+ projectID?: string;
7
8
  }
8
9
  declare type OnUpdateCallback = (i: Partial<SessionInfo>) => void;
9
10
  export declare type Options = {
@@ -12,12 +13,13 @@ export declare type Options = {
12
13
  };
13
14
  export default class Session {
14
15
  private readonly app;
15
- private options;
16
+ private readonly options;
16
17
  private metadata;
17
18
  private userID;
18
19
  private sessionID;
19
20
  private readonly callbacks;
20
21
  private timestamp;
22
+ private projectID;
21
23
  constructor(app: App, options: Options);
22
24
  attachUpdateCallback(cb: OnUpdateCallback): void;
23
25
  private handleUpdate;
@@ -29,7 +31,7 @@ export default class Session {
29
31
  getSessionToken(): string | undefined;
30
32
  setSessionToken(token: string): void;
31
33
  applySessionHash(hash: string): void;
32
- getSessionHash(): string;
34
+ getSessionHash(): string | undefined;
33
35
  getInfo(): SessionInfo;
34
36
  reset(): void;
35
37
  }
@@ -33,6 +33,9 @@ export default class Session {
33
33
  if (newInfo.timestamp !== undefined) {
34
34
  this.timestamp = newInfo.timestamp;
35
35
  }
36
+ if (newInfo.projectID !== undefined) {
37
+ this.projectID = newInfo.projectID;
38
+ }
36
39
  this.handleUpdate(newInfo);
37
40
  }
38
41
  setMetadata(key, value) {
@@ -68,7 +71,13 @@ export default class Session {
68
71
  this.app.sessionStorage.setItem(this.options.session_token_key, token);
69
72
  }
70
73
  applySessionHash(hash) {
71
- const [pageNoStr, token] = decodeURI(hash).split('&');
74
+ const hashParts = decodeURI(hash).split('&');
75
+ let token = hash;
76
+ let pageNoStr = '100500'; // back-compat for sessionToken
77
+ if (hashParts.length == 2) {
78
+ ;
79
+ [token, pageNoStr] = hashParts;
80
+ }
72
81
  if (!pageNoStr || !token) {
73
82
  return;
74
83
  }
@@ -79,9 +88,9 @@ export default class Session {
79
88
  const pageNo = this.getPageNumber();
80
89
  const token = this.getSessionToken();
81
90
  if (pageNo === undefined || token === undefined) {
82
- return '';
91
+ return;
83
92
  }
84
- return encodeURI(String(pageNo) + "&" + token);
93
+ return encodeURI(String(pageNo) + '&' + token);
85
94
  }
86
95
  getInfo() {
87
96
  return {
@@ -89,6 +98,7 @@ export default class Session {
89
98
  metadata: this.metadata,
90
99
  userID: this.userID,
91
100
  timestamp: this.timestamp,
101
+ projectID: this.projectID,
92
102
  };
93
103
  }
94
104
  reset() {
@@ -1,4 +1,4 @@
1
- export declare enum Type {
1
+ export declare const enum Type {
2
2
  BatchMetadata = 81,
3
3
  PartitionedMessage = 82,
4
4
  Timestamp = 0,
@@ -56,327 +56,327 @@ export declare enum Type {
56
56
  AdoptedSSRemoveOwner = 77
57
57
  }
58
58
  export declare type BatchMetadata = [
59
- type: Type.BatchMetadata,
60
- version: number,
61
- pageNo: number,
62
- firstIndex: number,
63
- timestamp: number,
64
- location: string
59
+ Type.BatchMetadata,
60
+ number,
61
+ number,
62
+ number,
63
+ number,
64
+ string
65
65
  ];
66
66
  export declare type PartitionedMessage = [
67
- type: Type.PartitionedMessage,
68
- partNo: number,
69
- partTotal: number
67
+ Type.PartitionedMessage,
68
+ number,
69
+ number
70
70
  ];
71
71
  export declare type Timestamp = [
72
- type: Type.Timestamp,
73
- timestamp: number
72
+ Type.Timestamp,
73
+ number
74
74
  ];
75
75
  export declare type SetPageLocation = [
76
- type: Type.SetPageLocation,
77
- url: string,
78
- referrer: string,
79
- navigationStart: number
76
+ Type.SetPageLocation,
77
+ string,
78
+ string,
79
+ number
80
80
  ];
81
81
  export declare type SetViewportSize = [
82
- type: Type.SetViewportSize,
83
- width: number,
84
- height: number
82
+ Type.SetViewportSize,
83
+ number,
84
+ number
85
85
  ];
86
86
  export declare type SetViewportScroll = [
87
- type: Type.SetViewportScroll,
88
- x: number,
89
- y: number
87
+ Type.SetViewportScroll,
88
+ number,
89
+ number
90
90
  ];
91
91
  export declare type CreateDocument = [
92
- type: Type.CreateDocument
92
+ Type.CreateDocument
93
93
  ];
94
94
  export declare type CreateElementNode = [
95
- type: Type.CreateElementNode,
96
- id: number,
97
- parentID: number,
98
- index: number,
99
- tag: string,
100
- svg: boolean
95
+ Type.CreateElementNode,
96
+ number,
97
+ number,
98
+ number,
99
+ string,
100
+ boolean
101
101
  ];
102
102
  export declare type CreateTextNode = [
103
- type: Type.CreateTextNode,
104
- id: number,
105
- parentID: number,
106
- index: number
103
+ Type.CreateTextNode,
104
+ number,
105
+ number,
106
+ number
107
107
  ];
108
108
  export declare type MoveNode = [
109
- type: Type.MoveNode,
110
- id: number,
111
- parentID: number,
112
- index: number
109
+ Type.MoveNode,
110
+ number,
111
+ number,
112
+ number
113
113
  ];
114
114
  export declare type RemoveNode = [
115
- type: Type.RemoveNode,
116
- id: number
115
+ Type.RemoveNode,
116
+ number
117
117
  ];
118
118
  export declare type SetNodeAttribute = [
119
- type: Type.SetNodeAttribute,
120
- id: number,
121
- name: string,
122
- value: string
119
+ Type.SetNodeAttribute,
120
+ number,
121
+ string,
122
+ string
123
123
  ];
124
124
  export declare type RemoveNodeAttribute = [
125
- type: Type.RemoveNodeAttribute,
126
- id: number,
127
- name: string
125
+ Type.RemoveNodeAttribute,
126
+ number,
127
+ string
128
128
  ];
129
129
  export declare type SetNodeData = [
130
- type: Type.SetNodeData,
131
- id: number,
132
- data: string
130
+ Type.SetNodeData,
131
+ number,
132
+ string
133
133
  ];
134
134
  export declare type SetNodeScroll = [
135
- type: Type.SetNodeScroll,
136
- id: number,
137
- x: number,
138
- y: number
135
+ Type.SetNodeScroll,
136
+ number,
137
+ number,
138
+ number
139
139
  ];
140
140
  export declare type SetInputTarget = [
141
- type: Type.SetInputTarget,
142
- id: number,
143
- label: string
141
+ Type.SetInputTarget,
142
+ number,
143
+ string
144
144
  ];
145
145
  export declare type SetInputValue = [
146
- type: Type.SetInputValue,
147
- id: number,
148
- value: string,
149
- mask: number
146
+ Type.SetInputValue,
147
+ number,
148
+ string,
149
+ number
150
150
  ];
151
151
  export declare type SetInputChecked = [
152
- type: Type.SetInputChecked,
153
- id: number,
154
- checked: boolean
152
+ Type.SetInputChecked,
153
+ number,
154
+ boolean
155
155
  ];
156
156
  export declare type MouseMove = [
157
- type: Type.MouseMove,
158
- x: number,
159
- y: number
157
+ Type.MouseMove,
158
+ number,
159
+ number
160
160
  ];
161
161
  export declare type ConsoleLog = [
162
- type: Type.ConsoleLog,
163
- level: string,
164
- value: string
162
+ Type.ConsoleLog,
163
+ string,
164
+ string
165
165
  ];
166
166
  export declare type PageLoadTiming = [
167
- type: Type.PageLoadTiming,
168
- requestStart: number,
169
- responseStart: number,
170
- responseEnd: number,
171
- domContentLoadedEventStart: number,
172
- domContentLoadedEventEnd: number,
173
- loadEventStart: number,
174
- loadEventEnd: number,
175
- firstPaint: number,
176
- firstContentfulPaint: number
167
+ Type.PageLoadTiming,
168
+ number,
169
+ number,
170
+ number,
171
+ number,
172
+ number,
173
+ number,
174
+ number,
175
+ number,
176
+ number
177
177
  ];
178
178
  export declare type PageRenderTiming = [
179
- type: Type.PageRenderTiming,
180
- speedIndex: number,
181
- visuallyComplete: number,
182
- timeToInteractive: number
179
+ Type.PageRenderTiming,
180
+ number,
181
+ number,
182
+ number
183
183
  ];
184
184
  export declare type JSException = [
185
- type: Type.JSException,
186
- name: string,
187
- message: string,
188
- payload: string
185
+ Type.JSException,
186
+ string,
187
+ string,
188
+ string
189
189
  ];
190
190
  export declare type RawCustomEvent = [
191
- type: Type.RawCustomEvent,
192
- name: string,
193
- payload: string
191
+ Type.RawCustomEvent,
192
+ string,
193
+ string
194
194
  ];
195
195
  export declare type UserID = [
196
- type: Type.UserID,
197
- id: string
196
+ Type.UserID,
197
+ string
198
198
  ];
199
199
  export declare type UserAnonymousID = [
200
- type: Type.UserAnonymousID,
201
- id: string
200
+ Type.UserAnonymousID,
201
+ string
202
202
  ];
203
203
  export declare type Metadata = [
204
- type: Type.Metadata,
205
- key: string,
206
- value: string
204
+ Type.Metadata,
205
+ string,
206
+ string
207
207
  ];
208
208
  export declare type CSSInsertRule = [
209
- type: Type.CSSInsertRule,
210
- id: number,
211
- rule: string,
212
- index: number
209
+ Type.CSSInsertRule,
210
+ number,
211
+ string,
212
+ number
213
213
  ];
214
214
  export declare type CSSDeleteRule = [
215
- type: Type.CSSDeleteRule,
216
- id: number,
217
- index: number
215
+ Type.CSSDeleteRule,
216
+ number,
217
+ number
218
218
  ];
219
219
  export declare type Fetch = [
220
- type: Type.Fetch,
221
- method: string,
222
- url: string,
223
- request: string,
224
- response: string,
225
- status: number,
226
- timestamp: number,
227
- duration: number
220
+ Type.Fetch,
221
+ string,
222
+ string,
223
+ string,
224
+ string,
225
+ number,
226
+ number,
227
+ number
228
228
  ];
229
229
  export declare type Profiler = [
230
- type: Type.Profiler,
231
- name: string,
232
- duration: number,
233
- args: string,
234
- result: string
230
+ Type.Profiler,
231
+ string,
232
+ number,
233
+ string,
234
+ string
235
235
  ];
236
236
  export declare type OTable = [
237
- type: Type.OTable,
238
- key: string,
239
- value: string
237
+ Type.OTable,
238
+ string,
239
+ string
240
240
  ];
241
241
  export declare type StateAction = [
242
- type: Type.StateAction,
243
- type: string
242
+ Type.StateAction,
243
+ string
244
244
  ];
245
245
  export declare type Redux = [
246
- type: Type.Redux,
247
- action: string,
248
- state: string,
249
- duration: number
246
+ Type.Redux,
247
+ string,
248
+ string,
249
+ number
250
250
  ];
251
251
  export declare type Vuex = [
252
- type: Type.Vuex,
253
- mutation: string,
254
- state: string
252
+ Type.Vuex,
253
+ string,
254
+ string
255
255
  ];
256
256
  export declare type MobX = [
257
- type: Type.MobX,
258
- type: string,
259
- payload: string
257
+ Type.MobX,
258
+ string,
259
+ string
260
260
  ];
261
261
  export declare type NgRx = [
262
- type: Type.NgRx,
263
- action: string,
264
- state: string,
265
- duration: number
262
+ Type.NgRx,
263
+ string,
264
+ string,
265
+ number
266
266
  ];
267
267
  export declare type GraphQL = [
268
- type: Type.GraphQL,
269
- operationKind: string,
270
- operationName: string,
271
- variables: string,
272
- response: string
268
+ Type.GraphQL,
269
+ string,
270
+ string,
271
+ string,
272
+ string
273
273
  ];
274
274
  export declare type PerformanceTrack = [
275
- type: Type.PerformanceTrack,
276
- frames: number,
277
- ticks: number,
278
- totalJSHeapSize: number,
279
- usedJSHeapSize: number
275
+ Type.PerformanceTrack,
276
+ number,
277
+ number,
278
+ number,
279
+ number
280
280
  ];
281
281
  export declare type ResourceTiming = [
282
- type: Type.ResourceTiming,
283
- timestamp: number,
284
- duration: number,
285
- ttfb: number,
286
- headerSize: number,
287
- encodedBodySize: number,
288
- decodedBodySize: number,
289
- url: string,
290
- initiator: string
282
+ Type.ResourceTiming,
283
+ number,
284
+ number,
285
+ number,
286
+ number,
287
+ number,
288
+ number,
289
+ string,
290
+ string
291
291
  ];
292
292
  export declare type ConnectionInformation = [
293
- type: Type.ConnectionInformation,
294
- downlink: number,
295
- type: string
293
+ Type.ConnectionInformation,
294
+ number,
295
+ string
296
296
  ];
297
297
  export declare type SetPageVisibility = [
298
- type: Type.SetPageVisibility,
299
- hidden: boolean
298
+ Type.SetPageVisibility,
299
+ boolean
300
300
  ];
301
301
  export declare type LongTask = [
302
- type: Type.LongTask,
303
- timestamp: number,
304
- duration: number,
305
- context: number,
306
- containerType: number,
307
- containerSrc: string,
308
- containerId: string,
309
- containerName: string
302
+ Type.LongTask,
303
+ number,
304
+ number,
305
+ number,
306
+ number,
307
+ string,
308
+ string,
309
+ string
310
310
  ];
311
311
  export declare type SetNodeAttributeURLBased = [
312
- type: Type.SetNodeAttributeURLBased,
313
- id: number,
314
- name: string,
315
- value: string,
316
- baseURL: string
312
+ Type.SetNodeAttributeURLBased,
313
+ number,
314
+ string,
315
+ string,
316
+ string
317
317
  ];
318
318
  export declare type SetCSSDataURLBased = [
319
- type: Type.SetCSSDataURLBased,
320
- id: number,
321
- data: string,
322
- baseURL: string
319
+ Type.SetCSSDataURLBased,
320
+ number,
321
+ string,
322
+ string
323
323
  ];
324
324
  export declare type TechnicalInfo = [
325
- type: Type.TechnicalInfo,
326
- type: string,
327
- value: string
325
+ Type.TechnicalInfo,
326
+ string,
327
+ string
328
328
  ];
329
329
  export declare type CustomIssue = [
330
- type: Type.CustomIssue,
331
- name: string,
332
- payload: string
330
+ Type.CustomIssue,
331
+ string,
332
+ string
333
333
  ];
334
334
  export declare type CSSInsertRuleURLBased = [
335
- type: Type.CSSInsertRuleURLBased,
336
- id: number,
337
- rule: string,
338
- index: number,
339
- baseURL: string
335
+ Type.CSSInsertRuleURLBased,
336
+ number,
337
+ string,
338
+ number,
339
+ string
340
340
  ];
341
341
  export declare type MouseClick = [
342
- type: Type.MouseClick,
343
- id: number,
344
- hesitationTime: number,
345
- label: string,
346
- selector: string
342
+ Type.MouseClick,
343
+ number,
344
+ number,
345
+ string,
346
+ string
347
347
  ];
348
348
  export declare type CreateIFrameDocument = [
349
- type: Type.CreateIFrameDocument,
350
- frameID: number,
351
- id: number
349
+ Type.CreateIFrameDocument,
350
+ number,
351
+ number
352
352
  ];
353
353
  export declare type AdoptedSSReplaceURLBased = [
354
- type: Type.AdoptedSSReplaceURLBased,
355
- sheetID: number,
356
- text: string,
357
- baseURL: string
354
+ Type.AdoptedSSReplaceURLBased,
355
+ number,
356
+ string,
357
+ string
358
358
  ];
359
359
  export declare type AdoptedSSInsertRuleURLBased = [
360
- type: Type.AdoptedSSInsertRuleURLBased,
361
- sheetID: number,
362
- rule: string,
363
- index: number,
364
- baseURL: string
360
+ Type.AdoptedSSInsertRuleURLBased,
361
+ number,
362
+ string,
363
+ number,
364
+ string
365
365
  ];
366
366
  export declare type AdoptedSSDeleteRule = [
367
- type: Type.AdoptedSSDeleteRule,
368
- sheetID: number,
369
- index: number
367
+ Type.AdoptedSSDeleteRule,
368
+ number,
369
+ number
370
370
  ];
371
371
  export declare type AdoptedSSAddOwner = [
372
- type: Type.AdoptedSSAddOwner,
373
- sheetID: number,
374
- id: number
372
+ Type.AdoptedSSAddOwner,
373
+ number,
374
+ number
375
375
  ];
376
376
  export declare type AdoptedSSRemoveOwner = [
377
- type: Type.AdoptedSSRemoveOwner,
378
- sheetID: number,
379
- id: number
377
+ Type.AdoptedSSRemoveOwner,
378
+ number,
379
+ number
380
380
  ];
381
381
  declare type Message = BatchMetadata | PartitionedMessage | Timestamp | SetPageLocation | SetViewportSize | SetViewportScroll | CreateDocument | CreateElementNode | CreateTextNode | MoveNode | RemoveNode | SetNodeAttribute | RemoveNodeAttribute | SetNodeData | SetNodeScroll | SetInputTarget | SetInputValue | SetInputChecked | MouseMove | ConsoleLog | PageLoadTiming | PageRenderTiming | JSException | RawCustomEvent | UserID | UserAnonymousID | Metadata | CSSInsertRule | CSSDeleteRule | Fetch | Profiler | OTable | StateAction | Redux | Vuex | MobX | NgRx | GraphQL | PerformanceTrack | ResourceTiming | ConnectionInformation | SetPageVisibility | LongTask | SetNodeAttributeURLBased | SetCSSDataURLBased | TechnicalInfo | CustomIssue | CSSInsertRuleURLBased | MouseClick | CreateIFrameDocument | AdoptedSSReplaceURLBased | AdoptedSSInsertRuleURLBased | AdoptedSSDeleteRule | AdoptedSSAddOwner | AdoptedSSRemoveOwner;
382
382
  export default Message;