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