@openreplay/tracker 5.0.1-beta.3 → 5.0.2-beta

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 (136) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/package.json +1 -1
  3. package/cjs/app/guards.d.ts +0 -20
  4. package/cjs/app/guards.js +0 -33
  5. package/cjs/app/index.d.ts +0 -121
  6. package/cjs/app/index.js +0 -439
  7. package/cjs/app/logger.d.ts +0 -26
  8. package/cjs/app/logger.js +0 -45
  9. package/cjs/app/messages.gen.d.ts +0 -63
  10. package/cjs/app/messages.gen.js +0 -551
  11. package/cjs/app/nodes.d.ts +0 -18
  12. package/cjs/app/nodes.js +0 -82
  13. package/cjs/app/observer/iframe_observer.d.ts +0 -4
  14. package/cjs/app/observer/iframe_observer.js +0 -23
  15. package/cjs/app/observer/iframe_offsets.d.ts +0 -8
  16. package/cjs/app/observer/iframe_offsets.js +0 -59
  17. package/cjs/app/observer/observer.d.ts +0 -23
  18. package/cjs/app/observer/observer.js +0 -337
  19. package/cjs/app/observer/shadow_root_observer.d.ts +0 -4
  20. package/cjs/app/observer/shadow_root_observer.js +0 -21
  21. package/cjs/app/observer/top_observer.d.ts +0 -24
  22. package/cjs/app/observer/top_observer.js +0 -115
  23. package/cjs/app/sanitizer.d.ts +0 -24
  24. package/cjs/app/sanitizer.js +0 -76
  25. package/cjs/app/session.d.ts +0 -38
  26. package/cjs/app/session.js +0 -114
  27. package/cjs/app/ticker.d.ts +0 -12
  28. package/cjs/app/ticker.js +0 -42
  29. package/cjs/common/interaction.d.ts +0 -24
  30. package/cjs/common/interaction.js +0 -2
  31. package/cjs/common/messages.gen.d.ts +0 -427
  32. package/cjs/common/messages.gen.js +0 -4
  33. package/cjs/index.d.ts +0 -47
  34. package/cjs/index.js +0 -254
  35. package/cjs/modules/connection.d.ts +0 -2
  36. package/cjs/modules/connection.js +0 -15
  37. package/cjs/modules/console.d.ts +0 -6
  38. package/cjs/modules/console.js +0 -119
  39. package/cjs/modules/constructedStyleSheets.d.ts +0 -4
  40. package/cjs/modules/constructedStyleSheets.js +0 -131
  41. package/cjs/modules/cssrules.d.ts +0 -2
  42. package/cjs/modules/cssrules.js +0 -99
  43. package/cjs/modules/exception.d.ts +0 -16
  44. package/cjs/modules/exception.js +0 -77
  45. package/cjs/modules/focus.d.ts +0 -2
  46. package/cjs/modules/focus.js +0 -45
  47. package/cjs/modules/fonts.d.ts +0 -2
  48. package/cjs/modules/fonts.js +0 -57
  49. package/cjs/modules/img.d.ts +0 -2
  50. package/cjs/modules/img.js +0 -110
  51. package/cjs/modules/input.d.ts +0 -16
  52. package/cjs/modules/input.js +0 -163
  53. package/cjs/modules/mouse.d.ts +0 -2
  54. package/cjs/modules/mouse.js +0 -148
  55. package/cjs/modules/network.d.ts +0 -28
  56. package/cjs/modules/network.js +0 -237
  57. package/cjs/modules/performance.d.ts +0 -7
  58. package/cjs/modules/performance.js +0 -53
  59. package/cjs/modules/scroll.d.ts +0 -2
  60. package/cjs/modules/scroll.js +0 -79
  61. package/cjs/modules/timing.d.ts +0 -7
  62. package/cjs/modules/timing.js +0 -160
  63. package/cjs/modules/viewport.d.ts +0 -2
  64. package/cjs/modules/viewport.js +0 -43
  65. package/cjs/package.json +0 -1
  66. package/cjs/utils.d.ts +0 -13
  67. package/cjs/utils.js +0 -71
  68. package/cjs/vendors/finder/finder.d.ts +0 -12
  69. package/cjs/vendors/finder/finder.js +0 -352
  70. package/lib/app/guards.d.ts +0 -20
  71. package/lib/app/guards.js +0 -23
  72. package/lib/app/index.d.ts +0 -121
  73. package/lib/app/index.js +0 -435
  74. package/lib/app/logger.d.ts +0 -26
  75. package/lib/app/logger.js +0 -41
  76. package/lib/app/messages.gen.d.ts +0 -63
  77. package/lib/app/messages.gen.js +0 -486
  78. package/lib/app/nodes.d.ts +0 -18
  79. package/lib/app/nodes.js +0 -79
  80. package/lib/app/observer/iframe_observer.d.ts +0 -4
  81. package/lib/app/observer/iframe_observer.js +0 -20
  82. package/lib/app/observer/iframe_offsets.d.ts +0 -8
  83. package/lib/app/observer/iframe_offsets.js +0 -56
  84. package/lib/app/observer/observer.d.ts +0 -23
  85. package/lib/app/observer/observer.js +0 -334
  86. package/lib/app/observer/shadow_root_observer.d.ts +0 -4
  87. package/lib/app/observer/shadow_root_observer.js +0 -18
  88. package/lib/app/observer/top_observer.d.ts +0 -24
  89. package/lib/app/observer/top_observer.js +0 -112
  90. package/lib/app/sanitizer.d.ts +0 -24
  91. package/lib/app/sanitizer.js +0 -72
  92. package/lib/app/session.d.ts +0 -38
  93. package/lib/app/session.js +0 -111
  94. package/lib/app/ticker.d.ts +0 -12
  95. package/lib/app/ticker.js +0 -39
  96. package/lib/common/interaction.d.ts +0 -24
  97. package/lib/common/interaction.js +0 -1
  98. package/lib/common/messages.gen.d.ts +0 -427
  99. package/lib/common/messages.gen.js +0 -3
  100. package/lib/common/tsconfig.tsbuildinfo +0 -1
  101. package/lib/index.d.ts +0 -47
  102. package/lib/index.js +0 -248
  103. package/lib/modules/connection.d.ts +0 -2
  104. package/lib/modules/connection.js +0 -12
  105. package/lib/modules/console.d.ts +0 -6
  106. package/lib/modules/console.js +0 -116
  107. package/lib/modules/constructedStyleSheets.d.ts +0 -4
  108. package/lib/modules/constructedStyleSheets.js +0 -126
  109. package/lib/modules/cssrules.d.ts +0 -2
  110. package/lib/modules/cssrules.js +0 -97
  111. package/lib/modules/exception.d.ts +0 -16
  112. package/lib/modules/exception.js +0 -71
  113. package/lib/modules/focus.d.ts +0 -2
  114. package/lib/modules/focus.js +0 -42
  115. package/lib/modules/fonts.d.ts +0 -2
  116. package/lib/modules/fonts.js +0 -54
  117. package/lib/modules/img.d.ts +0 -2
  118. package/lib/modules/img.js +0 -107
  119. package/lib/modules/input.d.ts +0 -16
  120. package/lib/modules/input.js +0 -158
  121. package/lib/modules/mouse.d.ts +0 -2
  122. package/lib/modules/mouse.js +0 -145
  123. package/lib/modules/network.d.ts +0 -28
  124. package/lib/modules/network.js +0 -234
  125. package/lib/modules/performance.d.ts +0 -7
  126. package/lib/modules/performance.js +0 -49
  127. package/lib/modules/scroll.d.ts +0 -2
  128. package/lib/modules/scroll.js +0 -76
  129. package/lib/modules/timing.d.ts +0 -7
  130. package/lib/modules/timing.js +0 -157
  131. package/lib/modules/viewport.d.ts +0 -2
  132. package/lib/modules/viewport.js +0 -40
  133. package/lib/utils.d.ts +0 -13
  134. package/lib/utils.js +0 -61
  135. package/lib/vendors/finder/finder.d.ts +0 -12
  136. package/lib/vendors/finder/finder.js +0 -348
package/CHANGELOG.md CHANGED
@@ -1,5 +1,6 @@
1
1
  ## 5.0.1
2
2
 
3
+ - Re-init worker after device sleep/hybernation
3
4
  - Default text input mode is now Obscured
4
5
  - Use `@medv/finder` instead of our own implementation of `getSelector` for better clickmaps experience
5
6
 
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": "5.0.1-beta.3",
4
+ "version": "5.0.2-beta",
5
5
  "keywords": [
6
6
  "logging",
7
7
  "replay"
@@ -1,20 +0,0 @@
1
- export declare function isNode(sth: any): sth is Node;
2
- export declare function isSVGElement(node: Element): node is SVGElement;
3
- export declare function isElementNode(node: Node): node is Element;
4
- export declare function isTextNode(node: Node): node is Text;
5
- export declare function isDocument(node: Node): node is Document;
6
- export declare function isRootNode(node: Node): node is Document | DocumentFragment;
7
- type TagTypeMap = {
8
- html: HTMLHtmlElement;
9
- body: HTMLBodyElement;
10
- img: HTMLImageElement;
11
- input: HTMLInputElement;
12
- textarea: HTMLTextAreaElement;
13
- select: HTMLSelectElement;
14
- label: HTMLLabelElement;
15
- iframe: HTMLIFrameElement;
16
- style: HTMLStyleElement | SVGStyleElement;
17
- link: HTMLLinkElement;
18
- };
19
- export declare function hasTag<T extends keyof TagTypeMap>(el: Node, tagName: T): el is TagTypeMap[typeof tagName];
20
- export {};
package/cjs/app/guards.js DELETED
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasTag = exports.isRootNode = exports.isDocument = exports.isTextNode = exports.isElementNode = exports.isSVGElement = exports.isNode = void 0;
4
- //@ts-ignore
5
- function isNode(sth) {
6
- return !!sth && sth.nodeType != null;
7
- }
8
- exports.isNode = isNode;
9
- function isSVGElement(node) {
10
- return node.namespaceURI === 'http://www.w3.org/2000/svg';
11
- }
12
- exports.isSVGElement = isSVGElement;
13
- function isElementNode(node) {
14
- return node.nodeType === Node.ELEMENT_NODE;
15
- }
16
- exports.isElementNode = isElementNode;
17
- function isTextNode(node) {
18
- return node.nodeType === Node.TEXT_NODE;
19
- }
20
- exports.isTextNode = isTextNode;
21
- function isDocument(node) {
22
- return node.nodeType === Node.DOCUMENT_NODE;
23
- }
24
- exports.isDocument = isDocument;
25
- function isRootNode(node) {
26
- return node.nodeType === Node.DOCUMENT_NODE || node.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
27
- }
28
- exports.isRootNode = isRootNode;
29
- function hasTag(el, tagName) {
30
- // @ts-ignore
31
- return el.localName === tagName;
32
- }
33
- exports.hasTag = hasTag;
@@ -1,121 +0,0 @@
1
- import type Message from './messages.gen.js';
2
- import Nodes from './nodes.js';
3
- import Observer from './observer/top_observer.js';
4
- import Sanitizer from './sanitizer.js';
5
- import Ticker from './ticker.js';
6
- import Logger from './logger.js';
7
- import Session from './session.js';
8
- import type { Options as ObserverOptions } from './observer/top_observer.js';
9
- import type { Options as SanitizerOptions } from './sanitizer.js';
10
- import type { Options as LoggerOptions } from './logger.js';
11
- import type { Options as SessOptions } from './session.js';
12
- import type { Options as NetworkOptions } from '../modules/network.js';
13
- import type { Options as WebworkerOptions } from '../common/interaction.js';
14
- export interface StartOptions {
15
- userID?: string;
16
- metadata?: Record<string, string>;
17
- forceNew?: boolean;
18
- sessionHash?: string;
19
- }
20
- interface OnStartInfo {
21
- sessionID: string;
22
- sessionToken: string;
23
- userUUID: string;
24
- }
25
- declare const CANCELED: "canceled";
26
- type SuccessfulStart = OnStartInfo & {
27
- success: true;
28
- };
29
- type UnsuccessfulStart = {
30
- reason: typeof CANCELED | string;
31
- success: false;
32
- };
33
- declare const UnsuccessfulStart: (reason: string) => UnsuccessfulStart;
34
- declare const SuccessfulStart: (body: OnStartInfo) => SuccessfulStart;
35
- export type StartPromiseReturn = SuccessfulStart | UnsuccessfulStart;
36
- type StartCallback = (i: OnStartInfo) => void;
37
- type CommitCallback = (messages: Array<Message>) => void;
38
- type AppOptions = {
39
- revID: string;
40
- node_id: string;
41
- session_reset_key: string;
42
- session_token_key: string;
43
- session_pageno_key: string;
44
- local_uuid_key: string;
45
- ingestPoint: string;
46
- resourceBaseHref: string | null;
47
- verbose: boolean;
48
- __is_snippet: boolean;
49
- __debug_report_edp: string | null;
50
- __debug__?: LoggerOptions;
51
- localStorage: Storage | null;
52
- sessionStorage: Storage | null;
53
- onStart?: StartCallback;
54
- network?: NetworkOptions;
55
- } & WebworkerOptions & SessOptions;
56
- export type Options = AppOptions & ObserverOptions & SanitizerOptions;
57
- export declare const DEFAULT_INGEST_POINT = "https://api.openreplay.com/ingest";
58
- export default class App {
59
- readonly nodes: Nodes;
60
- readonly ticker: Ticker;
61
- readonly projectKey: string;
62
- readonly sanitizer: Sanitizer;
63
- readonly debug: Logger;
64
- readonly notify: Logger;
65
- readonly session: Session;
66
- readonly localStorage: Storage;
67
- readonly sessionStorage: Storage;
68
- private readonly messages;
69
- readonly observer: Observer;
70
- private readonly startCallbacks;
71
- private readonly stopCallbacks;
72
- private readonly commitCallbacks;
73
- private readonly options;
74
- readonly networkOptions?: NetworkOptions;
75
- private readonly revID;
76
- private activityState;
77
- private readonly version;
78
- private readonly worker?;
79
- constructor(projectKey: string, sessionToken: string | undefined, options: Partial<Options>);
80
- private _debug;
81
- private _usingOldFetchPlugin;
82
- send(message: Message, urgent?: boolean): void;
83
- private commit;
84
- private delay;
85
- timestamp(): number;
86
- safe<T extends (this: any, ...args: any[]) => void>(fn: T): T;
87
- attachCommitCallback(cb: CommitCallback): void;
88
- attachStartCallback(cb: StartCallback, useSafe?: boolean): void;
89
- attachStopCallback(cb: () => any, useSafe?: boolean): void;
90
- attachEventListener(target: EventTarget, type: string, listener: EventListener, useSafe?: boolean, useCapture?: boolean): void;
91
- checkRequiredVersion(version: string): boolean;
92
- private getTrackerInfo;
93
- getSessionInfo(): {
94
- userUUID: string | null;
95
- projectKey: string;
96
- revID: string;
97
- trackerVersion: string;
98
- isSnippet: boolean;
99
- sessionID: string | undefined;
100
- metadata: Record<string, string>;
101
- userID: string | null;
102
- timestamp: number;
103
- projectID?: string | undefined;
104
- };
105
- getSessionToken(): string | undefined;
106
- getSessionID(): string | undefined;
107
- getSessionURL(options?: {
108
- withCurrentTime?: boolean;
109
- }): string | undefined;
110
- getHost(): string;
111
- getProjectKey(): string;
112
- getBaseHref(): string;
113
- resolveResourceURL(resourceURL: string): string;
114
- isServiceURL(url: string): boolean;
115
- active(): boolean;
116
- resetNextPageSession(flag: boolean): void;
117
- private _start;
118
- start(...args: Parameters<App['_start']>): Promise<StartPromiseReturn>;
119
- stop(stopWorker?: boolean): void;
120
- }
121
- export {};
package/cjs/app/index.js DELETED
@@ -1,439 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_INGEST_POINT = void 0;
4
- const messages_gen_js_1 = require("./messages.gen.js");
5
- const utils_js_1 = require("../utils.js");
6
- const nodes_js_1 = require("./nodes.js");
7
- const top_observer_js_1 = require("./observer/top_observer.js");
8
- const sanitizer_js_1 = require("./sanitizer.js");
9
- const ticker_js_1 = require("./ticker.js");
10
- const logger_js_1 = require("./logger.js");
11
- const session_js_1 = require("./session.js");
12
- const performance_js_1 = require("../modules/performance.js");
13
- const CANCELED = 'canceled';
14
- const START_ERROR = ':(';
15
- const UnsuccessfulStart = (reason) => ({ reason, success: false });
16
- const SuccessfulStart = (body) => (Object.assign(Object.assign({}, body), { success: true }));
17
- var ActivityState;
18
- (function (ActivityState) {
19
- ActivityState[ActivityState["NotActive"] = 0] = "NotActive";
20
- ActivityState[ActivityState["Starting"] = 1] = "Starting";
21
- ActivityState[ActivityState["Active"] = 2] = "Active";
22
- })(ActivityState || (ActivityState = {}));
23
- // TODO: use backendHost only
24
- exports.DEFAULT_INGEST_POINT = 'https://api.openreplay.com/ingest';
25
- class App {
26
- constructor(projectKey, sessionToken, options) {
27
- // if (options.onStart !== undefined) {
28
- // deprecationWarn("'onStart' option", "tracker.start().then(/* handle session info */)")
29
- // } ?? maybe onStart is good
30
- var _a, _b;
31
- this.messages = [];
32
- this.startCallbacks = [];
33
- this.stopCallbacks = [];
34
- this.commitCallbacks = [];
35
- this.activityState = ActivityState.NotActive;
36
- this.version = '5.0.1-beta.3'; // TODO: version compatability check inside each plugin.
37
- this._usingOldFetchPlugin = false;
38
- this.delay = 0;
39
- this.projectKey = projectKey;
40
- this.networkOptions = options.network;
41
- this.options = Object.assign({
42
- revID: '',
43
- node_id: '__openreplay_id',
44
- session_token_key: '__openreplay_token',
45
- session_pageno_key: '__openreplay_pageno',
46
- session_reset_key: '__openreplay_reset',
47
- local_uuid_key: '__openreplay_uuid',
48
- ingestPoint: exports.DEFAULT_INGEST_POINT,
49
- resourceBaseHref: null,
50
- verbose: false,
51
- __is_snippet: false,
52
- __debug_report_edp: null,
53
- localStorage: null,
54
- sessionStorage: null,
55
- }, options);
56
- this.revID = this.options.revID;
57
- this.localStorage = (_a = this.options.localStorage) !== null && _a !== void 0 ? _a : window.localStorage;
58
- this.sessionStorage = (_b = this.options.sessionStorage) !== null && _b !== void 0 ? _b : window.sessionStorage;
59
- this.sanitizer = new sanitizer_js_1.default(this, options);
60
- this.nodes = new nodes_js_1.default(this.options.node_id);
61
- this.observer = new top_observer_js_1.default(this, options);
62
- this.ticker = new ticker_js_1.default(this);
63
- this.ticker.attach(() => this.commit());
64
- this.debug = new logger_js_1.default(this.options.__debug__);
65
- this.notify = new logger_js_1.default(this.options.verbose ? logger_js_1.LogLevel.Warnings : logger_js_1.LogLevel.Silent);
66
- this.session = new session_js_1.default(this, this.options);
67
- this.session.attachUpdateCallback(({ userID, metadata }) => {
68
- if (userID != null) {
69
- // TODO: nullable userID
70
- this.send((0, messages_gen_js_1.UserID)(userID));
71
- }
72
- if (metadata != null) {
73
- Object.entries(metadata).forEach(([key, value]) => this.send((0, messages_gen_js_1.Metadata)(key, value)));
74
- }
75
- });
76
- // @depricated (use sessionHash on start instead)
77
- if (sessionToken != null) {
78
- this.session.applySessionHash(sessionToken);
79
- }
80
- try {
81
- this.worker = new Worker(URL.createObjectURL(new Blob(['"use strict";class t{constructor(t,i,s,e=10,n=1e3){this.onUnauthorised=i,this.onFailure=s,this.MAX_ATTEMPTS_COUNT=e,this.ATTEMPT_TIMEOUT=n,this.attemptsCount=0,this.busy=!1,this.queue=[],this.token=null,this.ingestURL=t+"/v1/web/i"}authorise(t){this.token=t,this.busy||this.sendNext()}push(t){this.busy||!this.token?this.queue.push(t):this.sendBatch(t)}sendNext(){const t=this.queue.shift();t?this.sendBatch(t):this.busy=!1}retry(t){this.attemptsCount>=this.MAX_ATTEMPTS_COUNT?this.onFailure(`Failed to send batch after ${this.attemptsCount} attempts.`):(this.attemptsCount++,setTimeout(()=>this.sendBatch(t),this.ATTEMPT_TIMEOUT*this.attemptsCount))}sendBatch(t){this.busy=!0,fetch(this.ingestURL,{body:t,method:"POST",headers:{Authorization:"Bearer "+this.token},keepalive:t.length<65536}).then(i=>{if(401===i.status)return this.busy=!1,void this.onUnauthorised();i.status>=400?this.retry(t):(this.attemptsCount=0,this.sendNext())}).catch(i=>{console.warn("OpenReplay:",i),this.retry(t)})}clean(){this.queue.length=0,this.token=null}}const i="function"==typeof TextEncoder?new TextEncoder:{encode(t){const i=t.length,s=new Uint8Array(3*i);let e=-1;for(let n=0,r=0,h=0;h!==i;){if(n=t.charCodeAt(h),h+=1,n>=55296&&n<=56319){if(h===i){s[e+=1]=239,s[e+=1]=191,s[e+=1]=189;break}if(r=t.charCodeAt(h),!(r>=56320&&r<=57343)){s[e+=1]=239,s[e+=1]=191,s[e+=1]=189;continue}if(n=1024*(n-55296)+r-56320+65536,h+=1,n>65535){s[e+=1]=240|n>>>18,s[e+=1]=128|n>>>12&63,s[e+=1]=128|n>>>6&63,s[e+=1]=128|63&n;continue}}n<=127?s[e+=1]=0|n:n<=2047?(s[e+=1]=192|n>>>6,s[e+=1]=128|63&n):(s[e+=1]=224|n>>>12,s[e+=1]=128|n>>>6&63,s[e+=1]=128|63&n)}return s.subarray(0,e+1)}};class s extends class{constructor(t){this.size=t,this.offset=0,this.checkpointOffset=0,this.data=new Uint8Array(t)}getCurrentOffset(){return this.offset}checkpoint(){this.checkpointOffset=this.offset}get isEmpty(){return 0===this.offset}skip(t){return this.offset+=t,this.offset<=this.size}set(t,i){this.data.set(t,i)}boolean(t){return this.data[this.offset++]=+t,this.offset<=this.size}uint(t){for((t<0||t>Number.MAX_SAFE_INTEGER)&&(t=0);t>=128;)this.data[this.offset++]=t%256|128,t=Math.floor(t/128);return this.data[this.offset++]=t,this.offset<=this.size}int(t){return t=Math.round(t),this.uint(t>=0?2*t:-2*t-1)}string(t){const s=i.encode(t),e=s.byteLength;return!(!this.uint(e)||this.offset+e>this.size)&&(this.data.set(s,this.offset),this.offset+=e,!0)}reset(){this.offset=0,this.checkpointOffset=0}flush(){const t=this.data.slice(0,this.checkpointOffset);return this.reset(),t}}{encode(t){switch(t[0]){case 0:return this.uint(t[1]);case 4:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3]);case 5:return this.uint(t[1])&&this.uint(t[2]);case 6:return this.int(t[1])&&this.int(t[2]);case 7:return!0;case 8:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.string(t[4])&&this.boolean(t[5]);case 9:case 10:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3]);case 11:return this.uint(t[1]);case 12:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3]);case 13:case 14:return this.uint(t[1])&&this.string(t[2]);case 16:return this.uint(t[1])&&this.int(t[2])&&this.int(t[3]);case 17:return this.uint(t[1])&&this.string(t[2]);case 18:return this.uint(t[1])&&this.string(t[2])&&this.int(t[3]);case 19:return this.uint(t[1])&&this.boolean(t[2]);case 20:return this.uint(t[1])&&this.uint(t[2]);case 21:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.string(t[5])&&this.uint(t[6])&&this.uint(t[7])&&this.uint(t[8]);case 22:return this.string(t[1])&&this.string(t[2]);case 23:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.uint(t[7])&&this.uint(t[8])&&this.uint(t[9]);case 24:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3]);case 27:return this.string(t[1])&&this.string(t[2]);case 28:case 29:return this.string(t[1]);case 30:return this.string(t[1])&&this.string(t[2]);case 37:return this.uint(t[1])&&this.string(t[2])&&this.uint(t[3]);case 38:return this.uint(t[1])&&this.uint(t[2]);case 39:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.uint(t[7]);case 40:return this.string(t[1])&&this.uint(t[2])&&this.string(t[3])&&this.string(t[4]);case 41:return this.string(t[1])&&this.string(t[2]);case 42:return this.string(t[1]);case 44:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3]);case 45:case 46:return this.string(t[1])&&this.string(t[2]);case 47:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3]);case 48:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4]);case 49:return this.int(t[1])&&this.int(t[2])&&this.uint(t[3])&&this.uint(t[4]);case 50:return this.uint(t[1])&&this.string(t[2]);case 51:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3]);case 53:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.string(t[7])&&this.string(t[8]);case 54:return this.uint(t[1])&&this.string(t[2]);case 55:return this.boolean(t[1]);case 57:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4]);case 58:return this.int(t[1]);case 59:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.string(t[5])&&this.string(t[6])&&this.string(t[7]);case 60:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4]);case 61:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3]);case 63:case 64:return this.string(t[1])&&this.string(t[2]);case 67:return this.uint(t[1])&&this.string(t[2])&&this.uint(t[3])&&this.string(t[4]);case 69:return this.uint(t[1])&&this.uint(t[2])&&this.string(t[3])&&this.string(t[4]);case 70:return this.uint(t[1])&&this.uint(t[2]);case 71:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3]);case 73:return this.uint(t[1])&&this.string(t[2])&&this.uint(t[3])&&this.string(t[4]);case 75:case 76:case 77:return this.uint(t[1])&&this.uint(t[2]);case 78:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4]);case 79:return this.string(t[1])&&this.string(t[2]);case 81:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.int(t[4])&&this.string(t[5]);case 82:return this.uint(t[1])&&this.uint(t[2])}}}class e{constructor(){this.idx=1,this.backDict={}}getKey(t){let i=!1;return this.backDict[t]||(i=!0,this.backDict[t]=this.idx++),[this.backDict[t],i]}}class n{constructor(t,i,n,r){this.pageNo=t,this.timestamp=i,this.url=n,this.onBatch=r,this.nextIndex=0,this.beaconSize=2e5,this.encoder=new s(this.beaconSize),this.strDict=new e,this.sizeBuffer=new Uint8Array(3),this.isEmpty=!0,this.beaconSizeLimit=1e6,this.prepare()}writeType(t){return this.encoder.uint(t[0])}writeFields(t){return this.encoder.encode(t)}writeSizeAt(t,i){for(let i=0;i<3;i++)this.sizeBuffer[i]=t>>8*i;this.encoder.set(this.sizeBuffer,i)}prepare(){if(!this.encoder.isEmpty)return;const t=[81,1,this.pageNo,this.nextIndex,this.timestamp,this.url];this.writeType(t),this.writeFields(t),this.isEmpty=!0}writeWithSize(t){const i=this.encoder;if(!this.writeType(t)||!i.skip(3))return!1;const s=i.getCurrentOffset(),e=this.writeFields(t);if(e){const e=i.getCurrentOffset()-s;if(e>16777215)return console.warn("OpenReplay: max message size overflow."),!1;this.writeSizeAt(e,s-3),i.checkpoint(),this.isEmpty=this.isEmpty&&0===t[0],this.nextIndex++}return e}setBeaconSizeLimit(t){this.beaconSizeLimit=t}applyDict(t){const[i,s]=this.strDict.getKey(t);return s&&this.writeMessage([50,i,t]),i}writeMessage(t){0===t[0]&&(this.timestamp=t[1]),4===t[0]&&(this.url=t[1]),12===t[0]&&(t=[51,t[1],this.applyDict(t[2]),this.applyDict(t[3])]),this.writeWithSize(t)||(this.finaliseBatch(),this.writeWithSize(t)||(this.encoder=new s(this.beaconSizeLimit),this.prepare(),this.writeWithSize(t)||console.warn("OpenReplay: beacon size overflow. Skipping large message.",t,this),this.encoder=new s(this.beaconSize),this.prepare()))}finaliseBatch(){this.isEmpty||(this.onBatch(this.encoder.flush()),this.prepare())}clean(){this.encoder.reset()}}var r;!function(t){t[t.NotActive=0]="NotActive",t[t.Starting=1]="Starting",t[t.Stopping=2]="Stopping",t[t.Active=3]="Active"}(r||(r={}));let h=null,u=null;r.NotActive;let a=0;function c(){u&&u.finaliseBatch()}function o(){r.Stopping,null!==l&&(clearInterval(l),l=null),u&&(u.clean(),u=null),h&&(h.clean(),h=null),r.NotActive}function g(){postMessage("restart"),o()}let f,l=null;self.onmessage=({data:i})=>{if(null!=i){if("stop"===i)return c(),void o();if(Array.isArray(i)){if(null!==u){const t=u;i.forEach(i=>{55===i[0]&&(i[1]?f=setTimeout(()=>g(),18e5):clearTimeout(f)),t.writeMessage(i)})}u||(postMessage("not_init"),0===a&&(a+=1,g()))}else{if("start"===i.type)return r.Starting,h=new t(i.ingestPoint,()=>{g()},t=>{!function(t){postMessage({type:"failure",reason:t}),o()}(t)},i.connAttemptCount,i.connAttemptGap),u=new n(i.pageNo,i.timestamp,i.url,t=>h&&h.push(t)),null===l&&(l=setInterval(c,1e4)),r.Active;if("auth"===i.type){if(!h)throw new Error("WebWorker: sender not initialised. Received auth.");if(!u)throw new Error("WebWorker: writer not initialised. Received auth.");return h.authorise(i.token),void(i.beaconSizeLimit&&u.setBeaconSizeLimit(i.beaconSizeLimit))}}}else c()};'], { type: 'text/javascript' })));
82
- this.worker.onerror = (e) => {
83
- this._debug('webworker_error', e);
84
- };
85
- this.worker.onmessage = ({ data }) => {
86
- if (data === 'restart') {
87
- this.stop(false);
88
- this.start({}, true);
89
- }
90
- else if (data === 'not_init') {
91
- console.warn('WebWorker: writer not initialised. Restarting tracker');
92
- }
93
- else if (data.type === 'failure') {
94
- this.stop(false);
95
- this._debug('worker_failed', data.reason);
96
- }
97
- };
98
- const alertWorker = () => {
99
- if (this.worker) {
100
- this.worker.postMessage(null);
101
- }
102
- };
103
- // keep better tactics, discard others?
104
- this.attachEventListener(window, 'beforeunload', alertWorker, false);
105
- this.attachEventListener(document.body, 'mouseleave', alertWorker, false, false);
106
- // TODO: stop session after inactivity timeout (make configurable)
107
- this.attachEventListener(document, 'visibilitychange', alertWorker, false);
108
- }
109
- catch (e) {
110
- this._debug('worker_start', e);
111
- }
112
- }
113
- _debug(context, e) {
114
- if (this.options.__debug_report_edp !== null) {
115
- void fetch(this.options.__debug_report_edp, {
116
- method: 'POST',
117
- headers: { 'Content-Type': 'application/json' },
118
- body: JSON.stringify({
119
- context,
120
- error: `${e}`,
121
- }),
122
- });
123
- }
124
- this.debug.error('OpenReplay error: ', context, e);
125
- }
126
- send(message, urgent = false) {
127
- if (this.activityState === ActivityState.NotActive) {
128
- return;
129
- }
130
- // === Back compatibility with Fetch/Axios plugins ===
131
- if (message[0] === 39 /* MType.Fetch */) {
132
- this._usingOldFetchPlugin = true;
133
- (0, utils_js_1.deprecationWarn)('Fetch plugin', "'network' init option", '/installation/network-options');
134
- (0, utils_js_1.deprecationWarn)('Axios plugin', "'network' init option", '/installation/network-options');
135
- }
136
- if (this._usingOldFetchPlugin && message[0] === 21 /* MType.NetworkRequest */) {
137
- return;
138
- }
139
- // ====================================================
140
- this.messages.push(message);
141
- // TODO: commit on start if there were `urgent` sends;
142
- // Clarify where urgent can be used for;
143
- // Clarify workflow for each type of message in case it was sent before start
144
- // (like Fetch before start; maybe add an option "preCapture: boolean" or sth alike)
145
- // Careful: `this.delay` is equal to zero before start hense all Timestamp-s will have to be updated on start
146
- if (this.activityState === ActivityState.Active && urgent) {
147
- this.commit();
148
- }
149
- }
150
- commit() {
151
- if (this.worker && this.messages.length) {
152
- this.messages.unshift((0, messages_gen_js_1.Timestamp)(this.timestamp()));
153
- this.worker.postMessage(this.messages);
154
- this.commitCallbacks.forEach((cb) => cb(this.messages));
155
- this.messages.length = 0;
156
- }
157
- }
158
- timestamp() {
159
- return (0, utils_js_1.now)() + this.delay;
160
- }
161
- safe(fn) {
162
- const app = this;
163
- return function (...args) {
164
- try {
165
- fn.apply(this, args);
166
- }
167
- catch (e) {
168
- app._debug('safe_fn_call', e);
169
- // time: this.timestamp(),
170
- // name: e.name,
171
- // message: e.message,
172
- // stack: e.stack
173
- }
174
- }; // TODO: correct typing
175
- }
176
- attachCommitCallback(cb) {
177
- this.commitCallbacks.push(cb);
178
- }
179
- attachStartCallback(cb, useSafe = false) {
180
- if (useSafe) {
181
- cb = this.safe(cb);
182
- }
183
- this.startCallbacks.push(cb);
184
- }
185
- attachStopCallback(cb, useSafe = false) {
186
- if (useSafe) {
187
- cb = this.safe(cb);
188
- }
189
- this.stopCallbacks.push(cb);
190
- }
191
- // Use app.nodes.attachNodeListener for registered nodes instead
192
- attachEventListener(target, type, listener, useSafe = true, useCapture = true) {
193
- if (useSafe) {
194
- listener = this.safe(listener);
195
- }
196
- this.attachStartCallback(() => target === null || target === void 0 ? void 0 : target.addEventListener(type, listener, useCapture), useSafe);
197
- this.attachStopCallback(() => target === null || target === void 0 ? void 0 : target.removeEventListener(type, listener, useCapture), useSafe);
198
- }
199
- // TODO: full correct semantic
200
- checkRequiredVersion(version) {
201
- const reqVer = version.split(/[.-]/);
202
- const ver = this.version.split(/[.-]/);
203
- for (let i = 0; i < 3; i++) {
204
- if (isNaN(Number(ver[i])) || isNaN(Number(reqVer[i]))) {
205
- return false;
206
- }
207
- if (Number(ver[i]) > Number(reqVer[i])) {
208
- return true;
209
- }
210
- if (Number(ver[i]) < Number(reqVer[i])) {
211
- return false;
212
- }
213
- }
214
- return true;
215
- }
216
- getTrackerInfo() {
217
- return {
218
- userUUID: this.localStorage.getItem(this.options.local_uuid_key),
219
- projectKey: this.projectKey,
220
- revID: this.revID,
221
- trackerVersion: this.version,
222
- isSnippet: this.options.__is_snippet,
223
- };
224
- }
225
- getSessionInfo() {
226
- return Object.assign(Object.assign({}, this.session.getInfo()), this.getTrackerInfo());
227
- }
228
- getSessionToken() {
229
- return this.session.getSessionToken();
230
- }
231
- getSessionID() {
232
- return this.session.getInfo().sessionID || undefined;
233
- }
234
- getSessionURL(options) {
235
- const { projectID, sessionID, timestamp } = this.session.getInfo();
236
- if (!projectID || !sessionID) {
237
- this.debug.error('OpenReplay error: Unable to build session URL');
238
- return undefined;
239
- }
240
- const ingest = this.options.ingestPoint;
241
- const isSaas = /api\.openreplay\.com/.test(ingest);
242
- const projectPath = isSaas ? 'https://openreplay.com/ingest' : ingest;
243
- const url = projectPath.replace(/ingest$/, `${projectID}/session/${sessionID}`);
244
- if (options === null || options === void 0 ? void 0 : options.withCurrentTime) {
245
- const jumpTo = (0, utils_js_1.now)() - timestamp;
246
- return `${url}?jumpto=${jumpTo}`;
247
- }
248
- return url;
249
- }
250
- getHost() {
251
- return new URL(this.options.ingestPoint).host;
252
- }
253
- getProjectKey() {
254
- return this.projectKey;
255
- }
256
- getBaseHref() {
257
- var _a, _b;
258
- if (typeof this.options.resourceBaseHref === 'string') {
259
- return this.options.resourceBaseHref;
260
- }
261
- else if (typeof this.options.resourceBaseHref === 'object') {
262
- //TODO: switch between types
263
- }
264
- if (document.baseURI) {
265
- return document.baseURI;
266
- }
267
- // IE only
268
- return (((_b = (_a = document.head) === null || _a === void 0 ? void 0 : _a.getElementsByTagName('base')[0]) === null || _b === void 0 ? void 0 : _b.getAttribute('href')) ||
269
- location.origin + location.pathname);
270
- }
271
- resolveResourceURL(resourceURL) {
272
- const base = new URL(this.getBaseHref());
273
- base.pathname += '/' + new URL(resourceURL).pathname;
274
- base.pathname.replace(/\/+/g, '/');
275
- return base.toString();
276
- }
277
- isServiceURL(url) {
278
- return url.startsWith(this.options.ingestPoint);
279
- }
280
- active() {
281
- return this.activityState === ActivityState.Active;
282
- }
283
- resetNextPageSession(flag) {
284
- if (flag) {
285
- this.sessionStorage.setItem(this.options.session_reset_key, 't');
286
- }
287
- else {
288
- this.sessionStorage.removeItem(this.options.session_reset_key);
289
- }
290
- }
291
- _start(startOpts = {}, resetByWorker = false) {
292
- if (!this.worker) {
293
- return Promise.resolve(UnsuccessfulStart('No worker found: perhaps, CSP is not set.'));
294
- }
295
- if (this.activityState !== ActivityState.NotActive) {
296
- return Promise.resolve(UnsuccessfulStart('OpenReplay: trying to call `start()` on the instance that has been started already.'));
297
- }
298
- this.activityState = ActivityState.Starting;
299
- (0, utils_js_1.adjustTimeOrigin)();
300
- if (startOpts.sessionHash) {
301
- this.session.applySessionHash(startOpts.sessionHash);
302
- }
303
- if (startOpts.forceNew) {
304
- // Reset session metadata only if requested directly
305
- this.session.reset();
306
- }
307
- this.session.assign({
308
- // MBTODO: maybe it would make sense to `forceNew` if the `userID` was changed
309
- userID: startOpts.userID,
310
- metadata: startOpts.metadata,
311
- });
312
- const timestamp = (0, utils_js_1.now)();
313
- this.worker.postMessage({
314
- type: 'start',
315
- pageNo: this.session.incPageNo(),
316
- ingestPoint: this.options.ingestPoint,
317
- timestamp,
318
- url: document.URL,
319
- connAttemptCount: this.options.connAttemptCount,
320
- connAttemptGap: this.options.connAttemptGap,
321
- });
322
- const lsReset = this.sessionStorage.getItem(this.options.session_reset_key) !== null;
323
- this.sessionStorage.removeItem(this.options.session_reset_key);
324
- const needNewSessionID = startOpts.forceNew || lsReset || resetByWorker;
325
- return window
326
- .fetch(this.options.ingestPoint + '/v1/web/start', {
327
- method: 'POST',
328
- headers: {
329
- 'Content-Type': 'application/json',
330
- },
331
- body: JSON.stringify(Object.assign(Object.assign({}, this.getTrackerInfo()), { timestamp, userID: this.session.getInfo().userID, token: needNewSessionID ? undefined : this.session.getSessionToken(), deviceMemory: performance_js_1.deviceMemory,
332
- jsHeapSizeLimit: performance_js_1.jsHeapSizeLimit })),
333
- })
334
- .then((r) => {
335
- if (r.status === 200) {
336
- return r.json();
337
- }
338
- else {
339
- return r
340
- .text()
341
- .then((text) => text === CANCELED
342
- ? Promise.reject(CANCELED)
343
- : Promise.reject(`Server error: ${r.status}. ${text}`));
344
- }
345
- })
346
- .then((r) => {
347
- if (!this.worker) {
348
- return Promise.reject('no worker found after start request (this might not happen)');
349
- }
350
- if (this.activityState === ActivityState.NotActive) {
351
- return Promise.reject('Tracker stopped during authorization');
352
- }
353
- const { token, userUUID, projectID, beaconSizeLimit, delay, // derived from token
354
- sessionID, // derived from token
355
- startTimestamp, // real startTS (server time), derived from sessionID
356
- } = r;
357
- if (typeof token !== 'string' ||
358
- typeof userUUID !== 'string' ||
359
- (typeof startTimestamp !== 'number' && typeof startTimestamp !== 'undefined') ||
360
- typeof sessionID !== 'string' ||
361
- typeof delay !== 'number' ||
362
- (typeof beaconSizeLimit !== 'number' && typeof beaconSizeLimit !== 'undefined')) {
363
- return Promise.reject(`Incorrect server response: ${JSON.stringify(r)}`);
364
- }
365
- this.delay = delay;
366
- this.session.setSessionToken(token);
367
- this.session.assign({
368
- sessionID,
369
- timestamp: startTimestamp || timestamp,
370
- projectID,
371
- });
372
- // (Re)send Metadata for the case of a new session
373
- Object.entries(this.session.getInfo().metadata).forEach(([key, value]) => this.send((0, messages_gen_js_1.Metadata)(key, value)));
374
- this.localStorage.setItem(this.options.local_uuid_key, userUUID);
375
- this.worker.postMessage({
376
- type: 'auth',
377
- token,
378
- beaconSizeLimit,
379
- });
380
- const onStartInfo = { sessionToken: token, userUUID, sessionID };
381
- // TODO: start as early as possible (before receiving the token)
382
- this.startCallbacks.forEach((cb) => cb(onStartInfo)); // MBTODO: callbacks after DOM "mounted" (observed)
383
- this.observer.observe();
384
- this.ticker.start();
385
- this.activityState = ActivityState.Active;
386
- this.notify.log('OpenReplay tracking started.');
387
- // get rid of onStart ?
388
- if (typeof this.options.onStart === 'function') {
389
- this.options.onStart(onStartInfo);
390
- }
391
- return SuccessfulStart(onStartInfo);
392
- })
393
- .catch((reason) => {
394
- this.stop();
395
- this.session.reset();
396
- if (reason === CANCELED) {
397
- return UnsuccessfulStart(CANCELED);
398
- }
399
- this.notify.log('OpenReplay was unable to start. ', reason);
400
- this._debug('session_start', reason);
401
- return UnsuccessfulStart(START_ERROR);
402
- });
403
- }
404
- start(...args) {
405
- if (!document.hidden) {
406
- return this._start(...args);
407
- }
408
- else {
409
- return new Promise((resolve) => {
410
- const onVisibilityChange = () => {
411
- if (!document.hidden) {
412
- document.removeEventListener('visibilitychange', onVisibilityChange);
413
- resolve(this._start(...args));
414
- }
415
- };
416
- document.addEventListener('visibilitychange', onVisibilityChange);
417
- });
418
- }
419
- }
420
- stop(stopWorker = true) {
421
- if (this.activityState !== ActivityState.NotActive) {
422
- try {
423
- this.sanitizer.clear();
424
- this.observer.disconnect();
425
- this.nodes.clear();
426
- this.ticker.stop();
427
- this.stopCallbacks.forEach((cb) => cb());
428
- this.notify.log('OpenReplay tracking stopped.');
429
- if (this.worker && stopWorker) {
430
- this.worker.postMessage('stop');
431
- }
432
- }
433
- finally {
434
- this.activityState = ActivityState.NotActive;
435
- }
436
- }
437
- }
438
- }
439
- exports.default = App;
@@ -1,26 +0,0 @@
1
- export declare const LogLevel: {
2
- readonly Verbose: 5;
3
- readonly Log: 4;
4
- readonly Warnings: 3;
5
- readonly Errors: 2;
6
- readonly Silent: 0;
7
- };
8
- type LogLevel = typeof LogLevel[keyof typeof LogLevel];
9
- type CustomLevel = {
10
- error: boolean;
11
- warn: boolean;
12
- log: boolean;
13
- };
14
- interface _Options {
15
- level: LogLevel | CustomLevel;
16
- messages?: number[];
17
- }
18
- export type Options = true | _Options | LogLevel;
19
- export default class Logger {
20
- private readonly options;
21
- constructor(options?: Options);
22
- log(...args: any): void;
23
- warn(...args: any): void;
24
- error(...args: any): void;
25
- }
26
- export {};