@openreplay/tracker 14.0.10-beta.2 → 14.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{cjs → dist/cjs}/index.js +27 -49
- package/dist/cjs/index.js.map +1 -0
- package/{cjs → dist/cjs/main}/app/index.d.ts +17 -5
- package/{lib → dist/cjs/main}/app/messages.gen.d.ts +2 -2
- package/{lib/app/nodes.d.ts → dist/cjs/main/app/nodes/index.d.ts} +14 -7
- package/dist/cjs/main/app/nodes/maintainer.d.ts +28 -0
- package/{lib → dist/cjs/main}/app/observer/iframe_offsets.d.ts +1 -1
- package/{lib → dist/cjs/main}/app/observer/observer.d.ts +3 -1
- package/{lib → dist/cjs/main}/app/observer/top_observer.d.ts +5 -1
- package/{cjs → dist/cjs/main}/app/sanitizer.d.ts +5 -2
- package/{cjs → dist/cjs/main}/app/session.d.ts +6 -3
- package/{cjs → dist/cjs/main}/index.d.ts +2 -2
- package/{cjs → dist/cjs/main}/modules/attributeSender.d.ts +5 -2
- package/{cjs → dist/cjs/main}/modules/conditionsManager.d.ts +1 -1
- package/{cjs → dist/cjs/main}/modules/tagWatcher.d.ts +8 -4
- package/{lib → dist/cjs/main}/modules/userTesting/SignalManager.d.ts +2 -2
- package/{lib → dist/cjs/main}/utils.d.ts +4 -3
- package/dist/lib/index.js +9323 -0
- package/dist/lib/index.js.map +1 -0
- package/{lib → dist/lib/main}/app/index.d.ts +17 -5
- package/{cjs → dist/lib/main}/app/messages.gen.d.ts +2 -2
- package/{cjs/app/nodes.d.ts → dist/lib/main/app/nodes/index.d.ts} +14 -7
- package/dist/lib/main/app/nodes/maintainer.d.ts +28 -0
- package/{cjs → dist/lib/main}/app/observer/iframe_offsets.d.ts +1 -1
- package/{cjs → dist/lib/main}/app/observer/observer.d.ts +3 -1
- package/{cjs → dist/lib/main}/app/observer/top_observer.d.ts +5 -1
- package/{lib → dist/lib/main}/app/sanitizer.d.ts +5 -2
- package/{lib → dist/lib/main}/app/session.d.ts +6 -3
- package/{lib → dist/lib/main}/index.d.ts +2 -2
- package/{lib → dist/lib/main}/modules/attributeSender.d.ts +5 -2
- package/{lib → dist/lib/main}/modules/conditionsManager.d.ts +1 -1
- package/{lib → dist/lib/main}/modules/tagWatcher.d.ts +8 -4
- package/{cjs → dist/lib/main}/modules/userTesting/SignalManager.d.ts +2 -2
- package/{cjs → dist/lib/main}/utils.d.ts +4 -3
- package/package.json +29 -10
- package/.eslintignore +0 -11
- package/.nvmrc +0 -1
- package/.prettierignore +0 -1
- package/CHANGELOG.md +0 -297
- package/bun.lockb +0 -0
- package/cjs/app/canvas.js +0 -204
- package/cjs/app/guards.js +0 -37
- package/cjs/app/index.js +0 -1397
- package/cjs/app/logger.js +0 -37
- package/cjs/app/messages.gen.js +0 -702
- package/cjs/app/nodes.js +0 -111
- package/cjs/app/observer/iframe_observer.js +0 -35
- package/cjs/app/observer/iframe_offsets.js +0 -56
- package/cjs/app/observer/observer.js +0 -383
- package/cjs/app/observer/shadow_root_observer.js +0 -24
- package/cjs/app/observer/top_observer.js +0 -134
- package/cjs/app/sanitizer.js +0 -82
- package/cjs/app/session.js +0 -140
- package/cjs/app/ticker.js +0 -48
- package/cjs/common/interaction.js +0 -2
- package/cjs/common/messages.gen.js +0 -4
- package/cjs/modules/attributeSender.js +0 -51
- package/cjs/modules/axiosSpy.js +0 -122
- package/cjs/modules/conditionsManager.js +0 -343
- package/cjs/modules/connection.js +0 -15
- package/cjs/modules/console.js +0 -127
- package/cjs/modules/constructedStyleSheets.js +0 -138
- package/cjs/modules/cssrules.js +0 -99
- package/cjs/modules/exception.js +0 -85
- package/cjs/modules/featureFlags.js +0 -89
- package/cjs/modules/focus.js +0 -45
- package/cjs/modules/fonts.js +0 -57
- package/cjs/modules/img.js +0 -110
- package/cjs/modules/input.js +0 -203
- package/cjs/modules/mouse.js +0 -195
- package/cjs/modules/network.js +0 -244
- package/cjs/modules/performance.js +0 -53
- package/cjs/modules/scroll.js +0 -84
- package/cjs/modules/selection.js +0 -37
- package/cjs/modules/tabs.js +0 -13
- package/cjs/modules/tagWatcher.js +0 -76
- package/cjs/modules/timing.js +0 -173
- package/cjs/modules/userTesting/SignalManager.js +0 -83
- package/cjs/modules/userTesting/dnd.js +0 -40
- package/cjs/modules/userTesting/index.js +0 -464
- package/cjs/modules/userTesting/recorder.js +0 -101
- package/cjs/modules/userTesting/styles.js +0 -266
- package/cjs/modules/userTesting/utils.js +0 -87
- package/cjs/modules/viewport.js +0 -43
- package/cjs/package.json +0 -1
- package/cjs/utils.js +0 -249
- package/coverage/clover.xml +0 -4304
- package/coverage/coverage-final.json +0 -55
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -206
- package/coverage/lcov-report/main/app/canvas.ts.html +0 -712
- package/coverage/lcov-report/main/app/guards.ts.html +0 -232
- package/coverage/lcov-report/main/app/index.html +0 -236
- package/coverage/lcov-report/main/app/index.ts.html +0 -3955
- package/coverage/lcov-report/main/app/logger.ts.html +0 -211
- package/coverage/lcov-report/main/app/messages.gen.ts.html +0 -3034
- package/coverage/lcov-report/main/app/nodes.ts.html +0 -406
- package/coverage/lcov-report/main/app/observer/iframe_observer.ts.html +0 -148
- package/coverage/lcov-report/main/app/observer/iframe_offsets.ts.html +0 -289
- package/coverage/lcov-report/main/app/observer/index.html +0 -161
- package/coverage/lcov-report/main/app/observer/shadow_root_observer.ts.html +0 -142
- package/coverage/lcov-report/main/app/observer/top_observer.ts.html +0 -541
- package/coverage/lcov-report/main/app/sanitizer.ts.html +0 -403
- package/coverage/lcov-report/main/app/session.ts.html +0 -622
- package/coverage/lcov-report/main/app/ticker.ts.html +0 -250
- package/coverage/lcov-report/main/index.html +0 -131
- package/coverage/lcov-report/main/index.ts.html +0 -1597
- package/coverage/lcov-report/main/modules/Network/beaconProxy.ts.html +0 -400
- package/coverage/lcov-report/main/modules/Network/fetchProxy.ts.html +0 -1075
- package/coverage/lcov-report/main/modules/Network/index.html +0 -191
- package/coverage/lcov-report/main/modules/Network/index.ts.html +0 -244
- package/coverage/lcov-report/main/modules/Network/networkMessage.ts.html +0 -400
- package/coverage/lcov-report/main/modules/Network/utils.ts.html +0 -709
- package/coverage/lcov-report/main/modules/Network/xhrProxy.ts.html +0 -877
- package/coverage/lcov-report/main/modules/attributeSender.ts.html +0 -241
- package/coverage/lcov-report/main/modules/axiosSpy.ts.html +0 -709
- package/coverage/lcov-report/main/modules/conditionsManager.ts.html +0 -1381
- package/coverage/lcov-report/main/modules/connection.ts.html +0 -160
- package/coverage/lcov-report/main/modules/console.ts.html +0 -541
- package/coverage/lcov-report/main/modules/constructedStyleSheets.ts.html +0 -571
- package/coverage/lcov-report/main/modules/cssrules.ts.html +0 -418
- package/coverage/lcov-report/main/modules/exception.ts.html +0 -385
- package/coverage/lcov-report/main/modules/featureFlags.ts.html +0 -415
- package/coverage/lcov-report/main/modules/focus.ts.html +0 -220
- package/coverage/lcov-report/main/modules/fonts.ts.html +0 -289
- package/coverage/lcov-report/main/modules/img.ts.html +0 -436
- package/coverage/lcov-report/main/modules/index.html +0 -431
- package/coverage/lcov-report/main/modules/input.ts.html +0 -826
- package/coverage/lcov-report/main/modules/mouse.ts.html +0 -826
- package/coverage/lcov-report/main/modules/network.ts.html +0 -1123
- package/coverage/lcov-report/main/modules/performance.ts.html +0 -367
- package/coverage/lcov-report/main/modules/scroll.ts.html +0 -364
- package/coverage/lcov-report/main/modules/selection.ts.html +0 -202
- package/coverage/lcov-report/main/modules/tabs.ts.html +0 -124
- package/coverage/lcov-report/main/modules/tagWatcher.ts.html +0 -337
- package/coverage/lcov-report/main/modules/timing.ts.html +0 -877
- package/coverage/lcov-report/main/modules/userTesting/SignalManager.ts.html +0 -370
- package/coverage/lcov-report/main/modules/userTesting/dnd.ts.html +0 -220
- package/coverage/lcov-report/main/modules/userTesting/index.html +0 -191
- package/coverage/lcov-report/main/modules/userTesting/index.ts.html +0 -1909
- package/coverage/lcov-report/main/modules/userTesting/recorder.ts.html +0 -430
- package/coverage/lcov-report/main/modules/userTesting/styles.ts.html +0 -937
- package/coverage/lcov-report/main/modules/userTesting/utils.ts.html +0 -364
- package/coverage/lcov-report/main/modules/viewport.ts.html +0 -250
- package/coverage/lcov-report/main/utils.ts.html +0 -814
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/webworker/BatchWriter.ts.html +0 -499
- package/coverage/lcov-report/webworker/MessageEncoder.gen.ts.html +0 -1021
- package/coverage/lcov-report/webworker/PrimitiveEncoder.ts.html +0 -436
- package/coverage/lcov-report/webworker/QueueSender.ts.html +0 -547
- package/coverage/lcov-report/webworker/index.html +0 -176
- package/coverage/lcov-report/webworker/index.ts.html +0 -667
- package/coverage/lcov.info +0 -8425
- package/jest.config.js +0 -13
- package/lib/app/canvas.js +0 -202
- package/lib/app/guards.js +0 -26
- package/lib/app/index.js +0 -1367
- package/lib/app/logger.js +0 -33
- package/lib/app/messages.gen.js +0 -622
- package/lib/app/nodes.js +0 -108
- package/lib/app/observer/iframe_observer.js +0 -29
- package/lib/app/observer/iframe_offsets.js +0 -53
- package/lib/app/observer/observer.js +0 -380
- package/lib/app/observer/shadow_root_observer.js +0 -18
- package/lib/app/observer/top_observer.js +0 -128
- package/lib/app/sanitizer.js +0 -77
- package/lib/app/session.js +0 -137
- package/lib/app/ticker.js +0 -45
- package/lib/common/interaction.js +0 -1
- package/lib/common/messages.gen.js +0 -3
- package/lib/common/tsconfig.tsbuildinfo +0 -1
- package/lib/index.js +0 -423
- package/lib/modules/attributeSender.js +0 -46
- package/lib/modules/axiosSpy.js +0 -119
- package/lib/modules/conditionsManager.js +0 -340
- package/lib/modules/connection.js +0 -12
- package/lib/modules/console.js +0 -124
- package/lib/modules/constructedStyleSheets.js +0 -133
- package/lib/modules/cssrules.js +0 -97
- package/lib/modules/exception.js +0 -76
- package/lib/modules/featureFlags.js +0 -86
- package/lib/modules/focus.js +0 -42
- package/lib/modules/fonts.js +0 -54
- package/lib/modules/img.js +0 -107
- package/lib/modules/input.js +0 -198
- package/lib/modules/mouse.js +0 -192
- package/lib/modules/network.js +0 -238
- package/lib/modules/performance.js +0 -49
- package/lib/modules/scroll.js +0 -81
- package/lib/modules/selection.js +0 -35
- package/lib/modules/tabs.js +0 -10
- package/lib/modules/tagWatcher.js +0 -73
- package/lib/modules/timing.js +0 -170
- package/lib/modules/userTesting/SignalManager.js +0 -80
- package/lib/modules/userTesting/dnd.js +0 -37
- package/lib/modules/userTesting/index.js +0 -435
- package/lib/modules/userTesting/recorder.js +0 -97
- package/lib/modules/userTesting/styles.js +0 -263
- package/lib/modules/userTesting/utils.js +0 -79
- package/lib/modules/viewport.js +0 -40
- package/lib/utils.js +0 -230
- package/rollup.config.js +0 -12
- package/scripts/checkver.cjs +0 -7
- package/tsconfig-base.json +0 -16
- /package/{cjs → dist/cjs}/common/interaction.d.ts +0 -0
- /package/{cjs → dist/cjs}/common/messages.gen.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/app/canvas.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/app/guards.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/app/logger.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/app/observer/iframe_observer.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/app/observer/shadow_root_observer.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/app/ticker.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/modules/axiosSpy.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/modules/connection.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/modules/console.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/modules/constructedStyleSheets.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/modules/cssrules.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/modules/exception.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/modules/featureFlags.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/modules/focus.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/modules/fonts.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/modules/img.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/modules/input.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/modules/mouse.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/modules/network.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/modules/performance.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/modules/scroll.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/modules/selection.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/modules/tabs.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/modules/timing.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/modules/userTesting/dnd.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/modules/userTesting/index.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/modules/userTesting/recorder.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/modules/userTesting/styles.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/modules/userTesting/utils.d.ts +0 -0
- /package/{cjs → dist/cjs/main}/modules/viewport.d.ts +0 -0
- /package/{lib → dist/lib}/common/interaction.d.ts +0 -0
- /package/{lib → dist/lib}/common/messages.gen.d.ts +0 -0
- /package/{lib → dist/lib/main}/app/canvas.d.ts +0 -0
- /package/{lib → dist/lib/main}/app/guards.d.ts +0 -0
- /package/{lib → dist/lib/main}/app/logger.d.ts +0 -0
- /package/{lib → dist/lib/main}/app/observer/iframe_observer.d.ts +0 -0
- /package/{lib → dist/lib/main}/app/observer/shadow_root_observer.d.ts +0 -0
- /package/{lib → dist/lib/main}/app/ticker.d.ts +0 -0
- /package/{lib → dist/lib/main}/modules/axiosSpy.d.ts +0 -0
- /package/{lib → dist/lib/main}/modules/connection.d.ts +0 -0
- /package/{lib → dist/lib/main}/modules/console.d.ts +0 -0
- /package/{lib → dist/lib/main}/modules/constructedStyleSheets.d.ts +0 -0
- /package/{lib → dist/lib/main}/modules/cssrules.d.ts +0 -0
- /package/{lib → dist/lib/main}/modules/exception.d.ts +0 -0
- /package/{lib → dist/lib/main}/modules/featureFlags.d.ts +0 -0
- /package/{lib → dist/lib/main}/modules/focus.d.ts +0 -0
- /package/{lib → dist/lib/main}/modules/fonts.d.ts +0 -0
- /package/{lib → dist/lib/main}/modules/img.d.ts +0 -0
- /package/{lib → dist/lib/main}/modules/input.d.ts +0 -0
- /package/{lib → dist/lib/main}/modules/mouse.d.ts +0 -0
- /package/{lib → dist/lib/main}/modules/network.d.ts +0 -0
- /package/{lib → dist/lib/main}/modules/performance.d.ts +0 -0
- /package/{lib → dist/lib/main}/modules/scroll.d.ts +0 -0
- /package/{lib → dist/lib/main}/modules/selection.d.ts +0 -0
- /package/{lib → dist/lib/main}/modules/tabs.d.ts +0 -0
- /package/{lib → dist/lib/main}/modules/timing.d.ts +0 -0
- /package/{lib → dist/lib/main}/modules/userTesting/dnd.d.ts +0 -0
- /package/{lib → dist/lib/main}/modules/userTesting/index.d.ts +0 -0
- /package/{lib → dist/lib/main}/modules/userTesting/recorder.d.ts +0 -0
- /package/{lib → dist/lib/main}/modules/userTesting/styles.d.ts +0 -0
- /package/{lib → dist/lib/main}/modules/userTesting/utils.d.ts +0 -0
- /package/{lib → dist/lib/main}/modules/viewport.d.ts +0 -0
package/cjs/app/index.js
DELETED
|
@@ -1,1397 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.DEFAULT_INGEST_POINT = void 0;
|
|
30
|
-
const fflate_1 = require("fflate");
|
|
31
|
-
const attributeSender_js_1 = __importDefault(require("../modules/attributeSender.js"));
|
|
32
|
-
const conditionsManager_js_1 = __importDefault(require("../modules/conditionsManager.js"));
|
|
33
|
-
const featureFlags_js_1 = __importDefault(require("../modules/featureFlags.js"));
|
|
34
|
-
const performance_js_1 = require("../modules/performance.js");
|
|
35
|
-
const tagWatcher_js_1 = __importDefault(require("../modules/tagWatcher.js"));
|
|
36
|
-
const index_js_1 = __importDefault(require("../modules/userTesting/index.js"));
|
|
37
|
-
const utils_js_1 = require("../utils.js");
|
|
38
|
-
const canvas_js_1 = __importDefault(require("./canvas.js"));
|
|
39
|
-
const logger_js_1 = __importStar(require("./logger.js"));
|
|
40
|
-
const messages_gen_js_1 = require("./messages.gen.js");
|
|
41
|
-
const nodes_js_1 = __importDefault(require("./nodes.js"));
|
|
42
|
-
const top_observer_js_1 = __importDefault(require("./observer/top_observer.js"));
|
|
43
|
-
const sanitizer_js_1 = __importDefault(require("./sanitizer.js"));
|
|
44
|
-
const session_js_1 = __importDefault(require("./session.js"));
|
|
45
|
-
const ticker_js_1 = __importDefault(require("./ticker.js"));
|
|
46
|
-
const CANCELED = 'canceled';
|
|
47
|
-
const uxtStorageKey = 'or_uxt_active';
|
|
48
|
-
const bufferStorageKey = 'or_buffer_1';
|
|
49
|
-
const UnsuccessfulStart = (reason) => ({ reason, success: false });
|
|
50
|
-
const SuccessfulStart = (body) => ({ ...body, success: true });
|
|
51
|
-
var ActivityState;
|
|
52
|
-
(function (ActivityState) {
|
|
53
|
-
ActivityState[ActivityState["NotActive"] = 0] = "NotActive";
|
|
54
|
-
ActivityState[ActivityState["Starting"] = 1] = "Starting";
|
|
55
|
-
ActivityState[ActivityState["Active"] = 2] = "Active";
|
|
56
|
-
ActivityState[ActivityState["ColdStart"] = 3] = "ColdStart";
|
|
57
|
-
})(ActivityState || (ActivityState = {}));
|
|
58
|
-
// TODO: use backendHost only
|
|
59
|
-
exports.DEFAULT_INGEST_POINT = 'https://api.openreplay.com/ingest';
|
|
60
|
-
function getTimezone() {
|
|
61
|
-
const offset = new Date().getTimezoneOffset() * -1;
|
|
62
|
-
const sign = offset >= 0 ? '+' : '-';
|
|
63
|
-
const hours = Math.floor(Math.abs(offset) / 60);
|
|
64
|
-
const minutes = Math.abs(offset) % 60;
|
|
65
|
-
return `UTC${sign}${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}`;
|
|
66
|
-
}
|
|
67
|
-
const delay = (ms) => new Promise((res) => setTimeout(res, ms));
|
|
68
|
-
const proto = {
|
|
69
|
-
// ask if there are any tabs alive
|
|
70
|
-
ask: 'never-gonna-give-you-up',
|
|
71
|
-
// response from another tab
|
|
72
|
-
resp: 'never-gonna-let-you-down',
|
|
73
|
-
// regenerating id (copied other tab)
|
|
74
|
-
reg: 'never-gonna-run-around-and-desert-you',
|
|
75
|
-
iframeSignal: 'tracker inside a child iframe',
|
|
76
|
-
iframeId: 'getting node id for child iframe',
|
|
77
|
-
iframeBatch: 'batch of messages from an iframe window',
|
|
78
|
-
parentAlive: 'signal that parent is live',
|
|
79
|
-
killIframe: 'stop tracker inside frame',
|
|
80
|
-
startIframe: 'start tracker inside frame',
|
|
81
|
-
// checking updates
|
|
82
|
-
polling: 'hello-how-are-you-im-under-the-water-please-help-me',
|
|
83
|
-
};
|
|
84
|
-
class App {
|
|
85
|
-
constructor(projectKey, sessionToken, options, signalError, insideIframe) {
|
|
86
|
-
this.signalError = signalError;
|
|
87
|
-
this.insideIframe = insideIframe;
|
|
88
|
-
this.messages = [];
|
|
89
|
-
/**
|
|
90
|
-
* we need 2 buffers, so we don't lose anything
|
|
91
|
-
* @read coldStart implementation
|
|
92
|
-
* */
|
|
93
|
-
this.bufferedMessages1 = [];
|
|
94
|
-
this.bufferedMessages2 = [];
|
|
95
|
-
this.startCallbacks = [];
|
|
96
|
-
this.stopCallbacks = [];
|
|
97
|
-
this.commitCallbacks = [];
|
|
98
|
-
this.activityState = ActivityState.NotActive;
|
|
99
|
-
this.version = '14.0.10-beta.2'; // TODO: version compatability check inside each plugin.
|
|
100
|
-
this.socketMode = false;
|
|
101
|
-
this.compressionThreshold = 24 * 1000;
|
|
102
|
-
this.bc = null;
|
|
103
|
-
this.canvasRecorder = null;
|
|
104
|
-
this.conditionsManager = null;
|
|
105
|
-
this.canStart = false;
|
|
106
|
-
this.rootId = null;
|
|
107
|
-
this.pageFrames = [];
|
|
108
|
-
this.frameOderNumber = 0;
|
|
109
|
-
this.features = {
|
|
110
|
-
'feature-flags': true,
|
|
111
|
-
'usability-test': true,
|
|
112
|
-
};
|
|
113
|
-
/** used by child iframes for crossdomain only */
|
|
114
|
-
this.parentActive = false;
|
|
115
|
-
this.checkStatus = () => {
|
|
116
|
-
return this.parentActive;
|
|
117
|
-
};
|
|
118
|
-
this.parentCrossDomainFrameListener = (event) => {
|
|
119
|
-
const { data } = event;
|
|
120
|
-
if (!data || event.source === window)
|
|
121
|
-
return;
|
|
122
|
-
if (data.line === proto.startIframe) {
|
|
123
|
-
if (this.active())
|
|
124
|
-
return;
|
|
125
|
-
try {
|
|
126
|
-
this.allowAppStart();
|
|
127
|
-
void this.start();
|
|
128
|
-
}
|
|
129
|
-
catch (e) {
|
|
130
|
-
console.error('children frame restart failed:', e);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (data.line === proto.parentAlive) {
|
|
134
|
-
this.parentActive = true;
|
|
135
|
-
}
|
|
136
|
-
if (data.line === proto.iframeId) {
|
|
137
|
-
this.parentActive = true;
|
|
138
|
-
this.rootId = data.id;
|
|
139
|
-
this.session.setSessionToken(data.token);
|
|
140
|
-
this.frameOderNumber = data.frameOrderNumber;
|
|
141
|
-
this.debug.log('starting iframe tracking', data);
|
|
142
|
-
this.allowAppStart();
|
|
143
|
-
}
|
|
144
|
-
if (data.line === proto.killIframe) {
|
|
145
|
-
if (this.active()) {
|
|
146
|
-
this.stop();
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
/**
|
|
151
|
-
* context ids for iframes,
|
|
152
|
-
* order is not so important as long as its consistent
|
|
153
|
-
* */
|
|
154
|
-
this.trackedFrames = [];
|
|
155
|
-
this.crossDomainIframeListener = (event) => {
|
|
156
|
-
if (!this.active() || event.source === window)
|
|
157
|
-
return;
|
|
158
|
-
const { data } = event;
|
|
159
|
-
if (!data)
|
|
160
|
-
return;
|
|
161
|
-
if (data.line === proto.iframeSignal) {
|
|
162
|
-
// @ts-ignore
|
|
163
|
-
event.source?.postMessage({ ping: true, line: proto.parentAlive }, '*');
|
|
164
|
-
const pageIframes = Array.from(document.querySelectorAll('iframe'));
|
|
165
|
-
this.pageFrames = pageIframes;
|
|
166
|
-
const signalId = async () => {
|
|
167
|
-
if (event.source === null) {
|
|
168
|
-
return console.error('Couldnt connect to event.source for child iframe tracking');
|
|
169
|
-
}
|
|
170
|
-
const id = await this.checkNodeId(pageIframes, event.source);
|
|
171
|
-
if (id && !this.trackedFrames.includes(data.context)) {
|
|
172
|
-
try {
|
|
173
|
-
this.trackedFrames.push(data.context);
|
|
174
|
-
await this.waitStarted();
|
|
175
|
-
const token = this.session.getSessionToken();
|
|
176
|
-
const order = this.trackedFrames.findIndex((f) => f === data.context) + 1;
|
|
177
|
-
if (order === 0) {
|
|
178
|
-
this.debug.error('Couldnt get order number for iframe', data.context, this.trackedFrames);
|
|
179
|
-
}
|
|
180
|
-
const iframeData = {
|
|
181
|
-
line: proto.iframeId,
|
|
182
|
-
id,
|
|
183
|
-
token,
|
|
184
|
-
// since indexes go from 0 we +1
|
|
185
|
-
frameOrderNumber: order,
|
|
186
|
-
};
|
|
187
|
-
this.debug.log('Got child frame signal; nodeId', id, event.source, iframeData);
|
|
188
|
-
// @ts-ignore
|
|
189
|
-
event.source?.postMessage(iframeData, '*');
|
|
190
|
-
}
|
|
191
|
-
catch (e) {
|
|
192
|
-
console.error(e);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
this.debug.log('Couldnt get node id for iframe', event.source, pageIframes);
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
void signalId();
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* proxying messages from iframe to main body, so they can be in one batch (same indexes, etc)
|
|
203
|
-
* plus we rewrite some of the messages to be relative to the main context/window
|
|
204
|
-
* */
|
|
205
|
-
if (data.line === proto.iframeBatch) {
|
|
206
|
-
const msgBatch = data.messages;
|
|
207
|
-
const mappedMessages = msgBatch.map((msg) => {
|
|
208
|
-
if (msg[0] === 20 /* MType.MouseMove */) {
|
|
209
|
-
let fixedMessage = msg;
|
|
210
|
-
this.pageFrames.forEach((frame) => {
|
|
211
|
-
if (frame.contentWindow === event.source) {
|
|
212
|
-
const [type, x, y] = msg;
|
|
213
|
-
const { left, top } = frame.getBoundingClientRect();
|
|
214
|
-
fixedMessage = [type, x + left, y + top];
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
return fixedMessage;
|
|
218
|
-
}
|
|
219
|
-
if (msg[0] === 68 /* MType.MouseClick */) {
|
|
220
|
-
let fixedMessage = msg;
|
|
221
|
-
this.pageFrames.forEach((frame) => {
|
|
222
|
-
if (frame.contentWindow === event.source) {
|
|
223
|
-
const [type, id, hesitationTime, label, selector, normX, normY] = msg;
|
|
224
|
-
const { left, top, width, height } = frame.getBoundingClientRect();
|
|
225
|
-
const contentWidth = document.documentElement.scrollWidth;
|
|
226
|
-
const contentHeight = document.documentElement.scrollHeight;
|
|
227
|
-
// (normalizedX * frameWidth + frameLeftOffset)/docSize
|
|
228
|
-
const fullX = (normX / 100) * width + left;
|
|
229
|
-
const fullY = (normY / 100) * height + top;
|
|
230
|
-
const fixedX = fullX / contentWidth;
|
|
231
|
-
const fixedY = fullY / contentHeight;
|
|
232
|
-
fixedMessage = [
|
|
233
|
-
type,
|
|
234
|
-
id,
|
|
235
|
-
hesitationTime,
|
|
236
|
-
label,
|
|
237
|
-
selector,
|
|
238
|
-
Math.round(fixedX * 1e3) / 1e1,
|
|
239
|
-
Math.round(fixedY * 1e3) / 1e1,
|
|
240
|
-
];
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
return fixedMessage;
|
|
244
|
-
}
|
|
245
|
-
return msg;
|
|
246
|
-
});
|
|
247
|
-
this.messages.push(...mappedMessages);
|
|
248
|
-
}
|
|
249
|
-
if (data.line === proto.polling) {
|
|
250
|
-
if (!this.pollingQueue.order.length) {
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
const nextCommand = this.pollingQueue.order[0];
|
|
254
|
-
if (this.pollingQueue[nextCommand].includes(data.context)) {
|
|
255
|
-
this.pollingQueue[nextCommand] = this.pollingQueue[nextCommand].filter((c) => c !== data.context);
|
|
256
|
-
// @ts-ignore
|
|
257
|
-
event.source?.postMessage({ line: nextCommand }, '*');
|
|
258
|
-
if (this.pollingQueue[nextCommand].length === 0) {
|
|
259
|
-
this.pollingQueue.order.shift();
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
/**
|
|
265
|
-
* { command : [remaining iframes] }
|
|
266
|
-
* + order of commands
|
|
267
|
-
**/
|
|
268
|
-
this.pollingQueue = {
|
|
269
|
-
order: [],
|
|
270
|
-
};
|
|
271
|
-
this.addCommand = (cmd) => {
|
|
272
|
-
this.pollingQueue.order.push(cmd);
|
|
273
|
-
this.pollingQueue[cmd] = [...this.trackedFrames];
|
|
274
|
-
};
|
|
275
|
-
this.bootChildrenFrames = async () => {
|
|
276
|
-
await this.waitStarted();
|
|
277
|
-
this.addCommand(proto.startIframe);
|
|
278
|
-
};
|
|
279
|
-
this.killChildrenFrames = () => {
|
|
280
|
-
this.addCommand(proto.killIframe);
|
|
281
|
-
};
|
|
282
|
-
this.signalIframeTracker = () => {
|
|
283
|
-
const thisTab = this.session.getTabId();
|
|
284
|
-
const signalToParent = (n) => {
|
|
285
|
-
window.parent.postMessage({
|
|
286
|
-
line: proto.iframeSignal,
|
|
287
|
-
source: thisTab,
|
|
288
|
-
context: this.contextId,
|
|
289
|
-
}, this.options.crossdomain?.parentDomain ?? '*');
|
|
290
|
-
console.log('trying to signal to parent', n);
|
|
291
|
-
setTimeout(() => {
|
|
292
|
-
if (!this.checkStatus() && n < 100) {
|
|
293
|
-
void signalToParent(n + 1);
|
|
294
|
-
}
|
|
295
|
-
}, 250);
|
|
296
|
-
};
|
|
297
|
-
void signalToParent(1);
|
|
298
|
-
};
|
|
299
|
-
this.startTimeout = null;
|
|
300
|
-
this.coldStartCommitN = 0;
|
|
301
|
-
this.delay = 0;
|
|
302
|
-
this.attachStartCallback = (cb, useSafe = false) => {
|
|
303
|
-
if (useSafe) {
|
|
304
|
-
cb = this.safe(cb);
|
|
305
|
-
}
|
|
306
|
-
this.startCallbacks.push(cb);
|
|
307
|
-
};
|
|
308
|
-
this.attachStopCallback = (cb, useSafe = false) => {
|
|
309
|
-
if (useSafe) {
|
|
310
|
-
cb = this.safe(cb);
|
|
311
|
-
}
|
|
312
|
-
this.stopCallbacks.push(cb);
|
|
313
|
-
};
|
|
314
|
-
this.attachEventListener = (target, type, listener, useSafe = true, useCapture = true) => {
|
|
315
|
-
if (useSafe) {
|
|
316
|
-
listener = this.safe(listener);
|
|
317
|
-
}
|
|
318
|
-
const createListener = () => target
|
|
319
|
-
? (0, utils_js_1.createEventListener)(target, type, listener, useCapture, this.options.angularMode)
|
|
320
|
-
: null;
|
|
321
|
-
const deleteListener = () => target
|
|
322
|
-
? (0, utils_js_1.deleteEventListener)(target, type, listener, useCapture, this.options.angularMode)
|
|
323
|
-
: null;
|
|
324
|
-
this.attachStartCallback(createListener, useSafe);
|
|
325
|
-
this.attachStopCallback(deleteListener, useSafe);
|
|
326
|
-
};
|
|
327
|
-
this.coldInterval = null;
|
|
328
|
-
this.orderNumber = 0;
|
|
329
|
-
this.coldStartTs = 0;
|
|
330
|
-
this.singleBuffer = false;
|
|
331
|
-
this.onSessionSent = () => {
|
|
332
|
-
return;
|
|
333
|
-
};
|
|
334
|
-
this.restartCanvasTracking = () => {
|
|
335
|
-
this.canvasRecorder?.restartTracking();
|
|
336
|
-
};
|
|
337
|
-
this.flushBuffer = async (buffer) => {
|
|
338
|
-
return new Promise((res) => {
|
|
339
|
-
let ended = false;
|
|
340
|
-
const messagesBatch = [buffer.shift()];
|
|
341
|
-
while (!ended) {
|
|
342
|
-
const nextMsg = buffer[0];
|
|
343
|
-
if (!nextMsg || nextMsg[0] === 0 /* MType.Timestamp */) {
|
|
344
|
-
ended = true;
|
|
345
|
-
}
|
|
346
|
-
else {
|
|
347
|
-
messagesBatch.push(buffer.shift());
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
this.postToWorker(messagesBatch);
|
|
351
|
-
res(null);
|
|
352
|
-
});
|
|
353
|
-
};
|
|
354
|
-
this.onUxtCb = [];
|
|
355
|
-
this.contextId = Math.random().toString(36).slice(2);
|
|
356
|
-
this.projectKey = projectKey;
|
|
357
|
-
if (Object.keys(options).findIndex((k) => ['fixedCanvasScaling', 'disableCanvas'].includes(k)) !==
|
|
358
|
-
-1) {
|
|
359
|
-
console.warn('Openreplay: canvas options are moving to separate key "canvas" in next update. Please update your configuration.');
|
|
360
|
-
options = {
|
|
361
|
-
...options,
|
|
362
|
-
canvas: {
|
|
363
|
-
__save_canvas_locally: options.__save_canvas_locally,
|
|
364
|
-
fixedCanvasScaling: options.fixedCanvasScaling,
|
|
365
|
-
disableCanvas: options.disableCanvas,
|
|
366
|
-
},
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
this.networkOptions = options.network;
|
|
370
|
-
const defaultOptions = {
|
|
371
|
-
revID: '',
|
|
372
|
-
node_id: '__openreplay_id',
|
|
373
|
-
session_token_key: '__openreplay_token',
|
|
374
|
-
session_pageno_key: '__openreplay_pageno',
|
|
375
|
-
session_reset_key: '__openreplay_reset',
|
|
376
|
-
session_tabid_key: '__openreplay_tabid',
|
|
377
|
-
local_uuid_key: '__openreplay_uuid',
|
|
378
|
-
ingestPoint: exports.DEFAULT_INGEST_POINT,
|
|
379
|
-
resourceBaseHref: null,
|
|
380
|
-
__is_snippet: false,
|
|
381
|
-
__debug_report_edp: null,
|
|
382
|
-
__debug__: logger_js_1.LogLevel.Silent,
|
|
383
|
-
__save_canvas_locally: false,
|
|
384
|
-
localStorage: null,
|
|
385
|
-
sessionStorage: null,
|
|
386
|
-
disableStringDict: false,
|
|
387
|
-
forceSingleTab: false,
|
|
388
|
-
assistSocketHost: '',
|
|
389
|
-
fixedCanvasScaling: false,
|
|
390
|
-
disableCanvas: false,
|
|
391
|
-
captureIFrames: true,
|
|
392
|
-
obscureTextEmails: true,
|
|
393
|
-
obscureTextNumbers: false,
|
|
394
|
-
crossdomain: {
|
|
395
|
-
parentDomain: '*',
|
|
396
|
-
},
|
|
397
|
-
canvas: {
|
|
398
|
-
disableCanvas: false,
|
|
399
|
-
fixedCanvasScaling: false,
|
|
400
|
-
__save_canvas_locally: false,
|
|
401
|
-
useAnimationFrame: false,
|
|
402
|
-
},
|
|
403
|
-
angularMode: false,
|
|
404
|
-
};
|
|
405
|
-
this.options = (0, utils_js_1.simpleMerge)(defaultOptions, options);
|
|
406
|
-
if (!this.insideIframe &&
|
|
407
|
-
!this.options.forceSingleTab &&
|
|
408
|
-
globalThis &&
|
|
409
|
-
'BroadcastChannel' in globalThis) {
|
|
410
|
-
const host = location.hostname.split('.').slice(-2).join('_');
|
|
411
|
-
this.bc = new BroadcastChannel(`rick_${host}`);
|
|
412
|
-
}
|
|
413
|
-
this.revID = this.options.revID;
|
|
414
|
-
this.localStorage = this.options.localStorage ?? window.localStorage;
|
|
415
|
-
this.sessionStorage = this.options.sessionStorage ?? window.sessionStorage;
|
|
416
|
-
this.sanitizer = new sanitizer_js_1.default(this, options);
|
|
417
|
-
this.nodes = new nodes_js_1.default(this.options.node_id, Boolean(options.angularMode));
|
|
418
|
-
this.observer = new top_observer_js_1.default(this, options);
|
|
419
|
-
this.ticker = new ticker_js_1.default(this);
|
|
420
|
-
this.ticker.attach(() => this.commit());
|
|
421
|
-
this.debug = new logger_js_1.default(this.options.__debug__);
|
|
422
|
-
this.session = new session_js_1.default(this, this.options);
|
|
423
|
-
this.attributeSender = new attributeSender_js_1.default(this, Boolean(this.options.disableStringDict));
|
|
424
|
-
this.featureFlags = new featureFlags_js_1.default(this);
|
|
425
|
-
this.tagWatcher = new tagWatcher_js_1.default(this.sessionStorage, this.debug.error, (tag) => {
|
|
426
|
-
this.send((0, messages_gen_js_1.TagTrigger)(tag));
|
|
427
|
-
});
|
|
428
|
-
this.session.attachUpdateCallback(({ userID, metadata }) => {
|
|
429
|
-
if (userID != null) {
|
|
430
|
-
// TODO: nullable userID
|
|
431
|
-
this.send((0, messages_gen_js_1.UserID)(userID));
|
|
432
|
-
}
|
|
433
|
-
if (metadata != null) {
|
|
434
|
-
Object.entries(metadata).forEach(([key, value]) => this.send((0, messages_gen_js_1.Metadata)(key, value)));
|
|
435
|
-
}
|
|
436
|
-
});
|
|
437
|
-
// @deprecated (use sessionHash on start instead)
|
|
438
|
-
if (sessionToken != null) {
|
|
439
|
-
this.session.applySessionHash(sessionToken);
|
|
440
|
-
}
|
|
441
|
-
const thisTab = this.session.getTabId();
|
|
442
|
-
if (this.insideIframe) {
|
|
443
|
-
/**
|
|
444
|
-
* listen for messages from parent window, so we can signal that we're alive
|
|
445
|
-
* */
|
|
446
|
-
window.addEventListener('message', this.parentCrossDomainFrameListener);
|
|
447
|
-
setInterval(() => {
|
|
448
|
-
window.parent.postMessage({
|
|
449
|
-
line: proto.polling,
|
|
450
|
-
context: this.contextId,
|
|
451
|
-
}, '*');
|
|
452
|
-
}, 250);
|
|
453
|
-
}
|
|
454
|
-
else {
|
|
455
|
-
this.initWorker();
|
|
456
|
-
/**
|
|
457
|
-
* if we get a signal from child iframes, we check for their node_id and send it back,
|
|
458
|
-
* so they can act as if it was just a same-domain iframe
|
|
459
|
-
* */
|
|
460
|
-
window.addEventListener('message', this.crossDomainIframeListener);
|
|
461
|
-
}
|
|
462
|
-
if (this.bc !== null) {
|
|
463
|
-
this.bc.postMessage({
|
|
464
|
-
line: proto.ask,
|
|
465
|
-
source: thisTab,
|
|
466
|
-
context: this.contextId,
|
|
467
|
-
});
|
|
468
|
-
this.startTimeout = setTimeout(() => {
|
|
469
|
-
this.allowAppStart();
|
|
470
|
-
}, 250);
|
|
471
|
-
this.bc.onmessage = (ev) => {
|
|
472
|
-
if (ev.data.context === this.contextId) {
|
|
473
|
-
return;
|
|
474
|
-
}
|
|
475
|
-
if (ev.data.line === proto.resp) {
|
|
476
|
-
const sessionToken = ev.data.token;
|
|
477
|
-
this.session.setSessionToken(sessionToken);
|
|
478
|
-
this.allowAppStart();
|
|
479
|
-
}
|
|
480
|
-
if (ev.data.line === proto.reg) {
|
|
481
|
-
const sessionToken = ev.data.token;
|
|
482
|
-
this.session.regenerateTabId();
|
|
483
|
-
this.session.setSessionToken(sessionToken);
|
|
484
|
-
this.allowAppStart();
|
|
485
|
-
}
|
|
486
|
-
if (ev.data.line === proto.ask) {
|
|
487
|
-
const token = this.session.getSessionToken();
|
|
488
|
-
if (token && this.bc) {
|
|
489
|
-
this.bc.postMessage({
|
|
490
|
-
line: ev.data.source === thisTab ? proto.reg : proto.resp,
|
|
491
|
-
token,
|
|
492
|
-
source: thisTab,
|
|
493
|
-
context: this.contextId,
|
|
494
|
-
});
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
allowAppStart() {
|
|
501
|
-
this.canStart = true;
|
|
502
|
-
if (this.startTimeout) {
|
|
503
|
-
clearTimeout(this.startTimeout);
|
|
504
|
-
this.startTimeout = null;
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
async checkNodeId(iframes, source) {
|
|
508
|
-
for (const iframe of iframes) {
|
|
509
|
-
if (iframe.contentWindow && iframe.contentWindow === source) {
|
|
510
|
-
/**
|
|
511
|
-
* Here we're trying to get node id from the iframe (which is kept in observer)
|
|
512
|
-
* because of async nature of dom initialization, we give 100 retries with 100ms delay each
|
|
513
|
-
* which equals to 10 seconds. This way we have a period where we give app some time to load
|
|
514
|
-
* and tracker some time to parse the initial DOM tree even on slower devices
|
|
515
|
-
* */
|
|
516
|
-
let tries = 0;
|
|
517
|
-
while (tries < 100) {
|
|
518
|
-
// @ts-ignore
|
|
519
|
-
const potentialId = iframe[this.options.node_id];
|
|
520
|
-
if (potentialId !== undefined) {
|
|
521
|
-
tries = 100;
|
|
522
|
-
return potentialId;
|
|
523
|
-
}
|
|
524
|
-
else {
|
|
525
|
-
tries++;
|
|
526
|
-
await delay(100);
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
return null;
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
return null;
|
|
533
|
-
}
|
|
534
|
-
initWorker() {
|
|
535
|
-
try {
|
|
536
|
-
this.worker = new Worker(URL.createObjectURL(new Blob(['"use strict";class t{constructor(t,s,i,e=10,n=250,h,r){this.onUnauthorised=s,this.onFailure=i,this.MAX_ATTEMPTS_COUNT=e,this.ATTEMPT_TIMEOUT=n,this.onCompress=h,this.pageNo=r,this.attemptsCount=0,this.busy=!1,this.queue=[],this.token=null,this.lastBatchNum=0,this.ingestURL=t+"/v1/web/i",this.isCompressing=void 0!==h}getQueueStatus(){return 0===this.queue.length&&!this.busy}authorise(t){this.token=t,this.busy||this.sendNext()}push(t){if(this.busy||!this.token)this.queue.push(t);else if(this.busy=!0,this.isCompressing&&this.onCompress)this.onCompress(t);else{const s=++this.lastBatchNum;this.sendBatch(t,!1,s)}}sendNext(){const t=this.queue.shift();if(t)if(this.busy=!0,this.isCompressing&&this.onCompress)this.onCompress(t);else{const s=++this.lastBatchNum;this.sendBatch(t,!1,s)}else this.busy=!1}retry(t,s,i){this.attemptsCount>=this.MAX_ATTEMPTS_COUNT?this.onFailure(`Failed to send batch after ${this.attemptsCount} attempts.`):(this.attemptsCount++,setTimeout((()=>this.sendBatch(t,s,i)),this.ATTEMPT_TIMEOUT*this.attemptsCount))}sendBatch(t,s,i){const e=i?.toString().replace(/^([^_]+)_([^_]+).*/,"$1_$2_$3");this.busy=!0;const n={Authorization:`Bearer ${this.token}`};s&&(n["Content-Encoding"]="gzip"),null!==this.token?fetch(`${this.ingestURL}?batch=${this.pageNo??"noPageNum"}_${e??"noBatchNum"}`,{body:t,method:"POST",headers:n,keepalive:t.length<65536}).then((e=>{if(401===e.status)return this.busy=!1,void this.onUnauthorised();e.status>=400?this.retry(t,s,`${i??"noBatchNum"}_network:${e.status}`):(this.attemptsCount=0,this.sendNext())})).catch((e=>{console.warn("OpenReplay:",e),this.retry(t,s,`${i??"noBatchNum"}_reject:${e.message}`)})):setTimeout((()=>{this.sendBatch(t,s,`${i??"noBatchNum"}_newToken`)}),500)}sendCompressed(t){const s=++this.lastBatchNum;this.sendBatch(t,!0,s)}sendUncompressed(t){const s=++this.lastBatchNum;this.sendBatch(t,!1,s)}clean(){this.sendNext(),setTimeout((()=>{this.token=null,this.queue.length=0}),10)}}const s="function"==typeof TextEncoder?new TextEncoder:{encode(t){const s=t.length,i=new Uint8Array(3*s);let e=-1;for(let n=0,h=0,r=0;r!==s;){if(n=t.charCodeAt(r),r+=1,n>=55296&&n<=56319){if(r===s){i[e+=1]=239,i[e+=1]=191,i[e+=1]=189;break}if(h=t.charCodeAt(r),!(h>=56320&&h<=57343)){i[e+=1]=239,i[e+=1]=191,i[e+=1]=189;continue}if(n=1024*(n-55296)+h-56320+65536,r+=1,n>65535){i[e+=1]=240|n>>>18,i[e+=1]=128|n>>>12&63,i[e+=1]=128|n>>>6&63,i[e+=1]=128|63&n;continue}}n<=127?i[e+=1]=0|n:n<=2047?(i[e+=1]=192|n>>>6,i[e+=1]=128|63&n):(i[e+=1]=224|n>>>12,i[e+=1]=128|n>>>6&63,i[e+=1]=128|63&n)}return i.subarray(0,e+1)}};class i{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,s){this.data.set(t,s)}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 i=s.encode(t),e=i.byteLength;return!(!this.uint(e)||this.offset+e>this.size)&&(this.data.set(i,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}}class e extends i{encode(t){switch(t[0]){case 0:case 11:case 114:case 115:return this.uint(t[1]);case 4:case 44:case 47:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3]);case 5:case 20:case 38:case 70:case 75:case 76:case 77:case 82: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:case 24:case 51:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3]);case 12:case 61:case 71:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3]);case 13:case 14:case 17:case 50:case 54: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 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 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:case 27:case 30:case 41:case 45:case 46:case 63:case 64:case 79: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 28:case 29:case 42:case 117:case 118:return this.string(t[1]);case 37:return this.uint(t[1])&&this.string(t[2])&&this.uint(t[3]);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 48:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.int(t[5]);case 49:return this.int(t[1])&&this.int(t[2])&&this.uint(t[3])&&this.uint(t[4]);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 55:return this.boolean(t[1]);case 57:case 60:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4]);case 58:case 120: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 67:case 73:return this.uint(t[1])&&this.string(t[2])&&this.uint(t[3])&&this.string(t[4]);case 68:return this.uint(t[1])&&this.uint(t[2])&&this.string(t[3])&&this.string(t[4])&&this.uint(t[5])&&this.uint(t[6]);case 69:return this.uint(t[1])&&this.uint(t[2])&&this.string(t[3])&&this.string(t[4]);case 78:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4]);case 81:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.int(t[4])&&this.string(t[5]);case 83: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])&&this.uint(t[9]);case 84:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.uint(t[4])&&this.string(t[5])&&this.string(t[6]);case 112:return this.uint(t[1])&&this.string(t[2])&&this.boolean(t[3])&&this.string(t[4])&&this.int(t[5])&&this.int(t[6]);case 113:return this.uint(t[1])&&this.uint(t[2])&&this.string(t[3]);case 116: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])&&this.uint(t[9])&&this.boolean(t[10]);case 119:return this.string(t[1])&&this.uint(t[2]);case 121:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3])&&this.uint(t[4]);case 122:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3])&&this.string(t[4]);case 123:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.uint(t[5])}}}class n{constructor(t,s,i,n,h,r){this.pageNo=t,this.timestamp=s,this.url=i,this.onBatch=n,this.tabId=h,this.onOfflineEnd=r,this.nextIndex=0,this.beaconSize=2e5,this.encoder=new e(this.beaconSize),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,s){for(let s=0;s<3;s++)this.sizeBuffer[s]=t>>8*s;this.encoder.set(this.sizeBuffer,s)}prepare(){if(!this.encoder.isEmpty)return;const t=[81,1,this.pageNo,this.nextIndex,this.timestamp,this.url],s=[118,this.tabId];this.writeType(t),this.writeFields(t),this.writeWithSize(s),this.isEmpty=!0}writeWithSize(t){const s=this.encoder;if(!this.writeType(t)||!s.skip(3))return!1;const i=s.getCurrentOffset(),e=this.writeFields(t);if(e){const e=s.getCurrentOffset()-i;if(e>16777215)return console.warn("OpenReplay: max message size overflow."),!1;this.writeSizeAt(e,i-3),s.checkpoint(),this.isEmpty=this.isEmpty&&0===t[0],this.nextIndex++}return e}setBeaconSizeLimit(t){this.beaconSizeLimit=t}writeMessage(t){if("q_end"===t[0])return this.finaliseBatch(),this.onOfflineEnd();0===t[0]&&(this.timestamp=t[1]),122===t[0]&&(this.url=t[1]),this.writeWithSize(t)||(this.finaliseBatch(),this.writeWithSize(t)||(this.encoder=new e(this.beaconSizeLimit),this.prepare(),this.writeWithSize(t)?this.finaliseBatch():console.warn("OpenReplay: beacon size overflow. Skipping large message.",t,this),this.encoder=new e(this.beaconSize),this.prepare()))}finaliseBatch(){if(this.isEmpty)return;const t=this.encoder.flush();this.onBatch(t),this.prepare()}clean(){this.encoder.reset()}}var h;!function(t){t[t.NotActive=0]="NotActive",t[t.Starting=1]="Starting",t[t.Stopping=2]="Stopping",t[t.Active=3]="Active",t[t.Stopped=4]="Stopped"}(h||(h={}));let r=null,a=null,u=h.NotActive;function o(){a&&a.finaliseBatch()}function c(){return new Promise((t=>{u=h.Stopping,null!==l&&(clearInterval(l),l=null),a&&(a.clean(),a=null),r&&(r.clean(),setTimeout((()=>{r=null}),20)),setTimeout((()=>{u=h.NotActive,t(null)}),100)}))}function g(){[h.Stopped,h.Stopping].includes(u)||(postMessage("a_stop"),c().then((()=>{postMessage("a_start")})))}let p,l=null;self.onmessage=({data:s})=>{if(null!=s){if("stop"===s)return o(),void c().then((()=>{u=h.Stopped}));if("forceFlushBatch"!==s){if(!Array.isArray(s)){if("compressed"===s.type){if(!r)return console.debug("OR WebWorker: sender not initialised. Compressed batch."),void g();s.batch&&r.sendCompressed(s.batch)}if("uncompressed"===s.type){if(!r)return console.debug("OR WebWorker: sender not initialised. Uncompressed batch."),void g();s.batch&&r.sendUncompressed(s.batch)}return"start"===s.type?(u=h.Starting,r=new t(s.ingestPoint,(()=>{g()}),(t=>{!function(t){postMessage({type:"failure",reason:t}),c()}(t)}),s.connAttemptCount,s.connAttemptGap,(t=>{postMessage({type:"compress",batch:t},[t.buffer])}),s.pageNo),a=new n(s.pageNo,s.timestamp,s.url,(t=>{r&&r.push(t)}),s.tabId,(()=>postMessage({type:"queue_empty"}))),null===l&&(l=setInterval(o,1e4)),u=h.Active):"auth"===s.type?r?a?(r.authorise(s.token),void(s.beaconSizeLimit&&a.setBeaconSizeLimit(s.beaconSizeLimit))):(console.debug("OR WebWorker: writer not initialised. Received auth."),void g()):(console.debug("OR WebWorker: sender not initialised. Received auth."),void g()):void 0}if(a){const t=a;s.forEach((s=>{55===s[0]&&(s[1]?p=setTimeout((()=>g()),18e5):clearTimeout(p)),t.writeMessage(s)}))}else postMessage("not_init"),g()}else o()}else o()};'], { type: 'text/javascript' })));
|
|
537
|
-
this.worker.onerror = (e) => {
|
|
538
|
-
this._debug('webworker_error', e);
|
|
539
|
-
};
|
|
540
|
-
this.worker.onmessage = ({ data }) => {
|
|
541
|
-
this.handleWorkerMsg(data);
|
|
542
|
-
};
|
|
543
|
-
const alertWorker = () => {
|
|
544
|
-
if (this.worker) {
|
|
545
|
-
this.worker.postMessage(null);
|
|
546
|
-
}
|
|
547
|
-
};
|
|
548
|
-
// keep better tactics, discard others?
|
|
549
|
-
this.attachEventListener(window, 'beforeunload', alertWorker, false);
|
|
550
|
-
this.attachEventListener(document.body, 'mouseleave', alertWorker, false, false);
|
|
551
|
-
// TODO: stop session after inactivity timeout (make configurable)
|
|
552
|
-
this.attachEventListener(document, 'visibilitychange', alertWorker, false);
|
|
553
|
-
}
|
|
554
|
-
catch (e) {
|
|
555
|
-
this._debug('worker_start', e);
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
handleWorkerMsg(data) {
|
|
559
|
-
// handling 401 auth restart (new token assignment)
|
|
560
|
-
if (data === 'a_stop') {
|
|
561
|
-
this.stop(false);
|
|
562
|
-
}
|
|
563
|
-
else if (data === 'a_start') {
|
|
564
|
-
void this.start({}, true);
|
|
565
|
-
}
|
|
566
|
-
else if (data === 'not_init') {
|
|
567
|
-
this.debug.warn('OR WebWorker: writer not initialised. Restarting tracker');
|
|
568
|
-
}
|
|
569
|
-
else if (data.type === 'failure') {
|
|
570
|
-
this.stop(false);
|
|
571
|
-
this.debug.error('worker_failed', data.reason);
|
|
572
|
-
this._debug('worker_failed', data.reason);
|
|
573
|
-
}
|
|
574
|
-
else if (data.type === 'compress') {
|
|
575
|
-
const batch = data.batch;
|
|
576
|
-
const batchSize = batch.byteLength;
|
|
577
|
-
if (batchSize > this.compressionThreshold) {
|
|
578
|
-
(0, fflate_1.gzip)(data.batch, { mtime: 0 }, (err, result) => {
|
|
579
|
-
if (err) {
|
|
580
|
-
this.debug.error('Openreplay compression error:', err);
|
|
581
|
-
this.worker?.postMessage({ type: 'uncompressed', batch: batch });
|
|
582
|
-
}
|
|
583
|
-
else {
|
|
584
|
-
this.worker?.postMessage({ type: 'compressed', batch: result });
|
|
585
|
-
}
|
|
586
|
-
});
|
|
587
|
-
}
|
|
588
|
-
else {
|
|
589
|
-
this.worker?.postMessage({ type: 'uncompressed', batch: batch });
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
else if (data.type === 'queue_empty') {
|
|
593
|
-
this.onSessionSent();
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
_debug(context, e) {
|
|
597
|
-
if (this.options.__debug_report_edp !== null) {
|
|
598
|
-
void fetch(this.options.__debug_report_edp, {
|
|
599
|
-
method: 'POST',
|
|
600
|
-
headers: { 'Content-Type': 'application/json' },
|
|
601
|
-
body: JSON.stringify({
|
|
602
|
-
context,
|
|
603
|
-
// @ts-ignore
|
|
604
|
-
error: `${e}`,
|
|
605
|
-
}),
|
|
606
|
-
});
|
|
607
|
-
}
|
|
608
|
-
this.debug.error('OpenReplay error: ', context, e);
|
|
609
|
-
}
|
|
610
|
-
send(message, urgent = false) {
|
|
611
|
-
if (this.activityState === ActivityState.NotActive) {
|
|
612
|
-
return;
|
|
613
|
-
}
|
|
614
|
-
// ====================================================
|
|
615
|
-
if (this.activityState === ActivityState.ColdStart) {
|
|
616
|
-
this.bufferedMessages1.push(message);
|
|
617
|
-
if (!this.singleBuffer) {
|
|
618
|
-
this.bufferedMessages2.push(message);
|
|
619
|
-
}
|
|
620
|
-
this.conditionsManager?.processMessage(message);
|
|
621
|
-
}
|
|
622
|
-
else {
|
|
623
|
-
this.messages.push(message);
|
|
624
|
-
}
|
|
625
|
-
// TODO: commit on start if there were `urgent` sends;
|
|
626
|
-
// Clarify where urgent can be used for;
|
|
627
|
-
// Clarify workflow for each type of message in case it was sent before start
|
|
628
|
-
// (like Fetch before start; maybe add an option "preCapture: boolean" or sth alike)
|
|
629
|
-
// Careful: `this.delay` is equal to zero before start so all Timestamp-s will have to be updated on start
|
|
630
|
-
if (this.activityState === ActivityState.Active && urgent) {
|
|
631
|
-
this.commit();
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
/**
|
|
635
|
-
* Normal workflow: add timestamp and tab data to batch, then commit it
|
|
636
|
-
* every ~30ms
|
|
637
|
-
* */
|
|
638
|
-
_nCommit() {
|
|
639
|
-
if (this.socketMode) {
|
|
640
|
-
this.messages.unshift((0, messages_gen_js_1.TabData)(this.session.getTabId()));
|
|
641
|
-
this.messages.unshift((0, messages_gen_js_1.Timestamp)(this.timestamp()));
|
|
642
|
-
this.commitCallbacks.forEach((cb) => cb(this.messages));
|
|
643
|
-
this.messages.length = 0;
|
|
644
|
-
return;
|
|
645
|
-
}
|
|
646
|
-
if (this.insideIframe) {
|
|
647
|
-
window.parent.postMessage({
|
|
648
|
-
line: proto.iframeBatch,
|
|
649
|
-
messages: this.messages,
|
|
650
|
-
}, this.options.crossdomain?.parentDomain ?? '*');
|
|
651
|
-
this.commitCallbacks.forEach((cb) => cb(this.messages));
|
|
652
|
-
this.messages.length = 0;
|
|
653
|
-
return;
|
|
654
|
-
}
|
|
655
|
-
if (this.worker === undefined || !this.messages.length) {
|
|
656
|
-
return;
|
|
657
|
-
}
|
|
658
|
-
try {
|
|
659
|
-
(0, utils_js_1.requestIdleCb)(() => {
|
|
660
|
-
this.messages.unshift((0, messages_gen_js_1.TabData)(this.session.getTabId()));
|
|
661
|
-
this.messages.unshift((0, messages_gen_js_1.Timestamp)(this.timestamp()));
|
|
662
|
-
this.worker?.postMessage(this.messages);
|
|
663
|
-
this.commitCallbacks.forEach((cb) => cb(this.messages));
|
|
664
|
-
this.messages.length = 0;
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
catch (e) {
|
|
668
|
-
this._debug('worker_commit', e);
|
|
669
|
-
this.stop(true);
|
|
670
|
-
setTimeout(() => {
|
|
671
|
-
void this.start();
|
|
672
|
-
}, 500);
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
/**
|
|
676
|
-
* Cold start: add timestamp and tab data to both batches
|
|
677
|
-
* every 2nd tick, ~60ms
|
|
678
|
-
* this will make batches a bit larger and replay will work with bigger jumps every frame
|
|
679
|
-
* but in turn we don't overload batch writer on session start with 1000 batches
|
|
680
|
-
* */
|
|
681
|
-
_cStartCommit() {
|
|
682
|
-
this.coldStartCommitN += 1;
|
|
683
|
-
if (this.coldStartCommitN === 2) {
|
|
684
|
-
this.bufferedMessages1.push((0, messages_gen_js_1.Timestamp)(this.timestamp()));
|
|
685
|
-
this.bufferedMessages1.push((0, messages_gen_js_1.TabData)(this.session.getTabId()));
|
|
686
|
-
this.bufferedMessages2.push((0, messages_gen_js_1.Timestamp)(this.timestamp()));
|
|
687
|
-
this.bufferedMessages2.push((0, messages_gen_js_1.TabData)(this.session.getTabId()));
|
|
688
|
-
this.coldStartCommitN = 0;
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
commit() {
|
|
692
|
-
if (this.activityState === ActivityState.ColdStart) {
|
|
693
|
-
this._cStartCommit();
|
|
694
|
-
}
|
|
695
|
-
else {
|
|
696
|
-
this._nCommit();
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
postToWorker(messages) {
|
|
700
|
-
this.worker?.postMessage(messages);
|
|
701
|
-
this.commitCallbacks.forEach((cb) => cb(messages));
|
|
702
|
-
messages.length = 0;
|
|
703
|
-
}
|
|
704
|
-
timestamp() {
|
|
705
|
-
return (0, utils_js_1.now)() + this.delay;
|
|
706
|
-
}
|
|
707
|
-
safe(fn) {
|
|
708
|
-
const app = this;
|
|
709
|
-
return function (...args) {
|
|
710
|
-
try {
|
|
711
|
-
fn.apply(this, args);
|
|
712
|
-
}
|
|
713
|
-
catch (e) {
|
|
714
|
-
app._debug('safe_fn_call', e);
|
|
715
|
-
// time: this.timestamp(),
|
|
716
|
-
// name: e.name,
|
|
717
|
-
// message: e.message,
|
|
718
|
-
// stack: e.stack
|
|
719
|
-
}
|
|
720
|
-
}; // TODO: correct typing
|
|
721
|
-
}
|
|
722
|
-
attachCommitCallback(cb) {
|
|
723
|
-
this.commitCallbacks.push(cb);
|
|
724
|
-
}
|
|
725
|
-
// TODO: full correct semantic
|
|
726
|
-
checkRequiredVersion(version) {
|
|
727
|
-
const reqVer = version.split(/[.-]/);
|
|
728
|
-
const ver = this.version.split(/[.-]/);
|
|
729
|
-
for (let i = 0; i < 3; i++) {
|
|
730
|
-
if (isNaN(Number(ver[i])) || isNaN(Number(reqVer[i]))) {
|
|
731
|
-
return false;
|
|
732
|
-
}
|
|
733
|
-
if (Number(ver[i]) > Number(reqVer[i])) {
|
|
734
|
-
return true;
|
|
735
|
-
}
|
|
736
|
-
if (Number(ver[i]) < Number(reqVer[i])) {
|
|
737
|
-
return false;
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
return true;
|
|
741
|
-
}
|
|
742
|
-
getTrackerInfo() {
|
|
743
|
-
return {
|
|
744
|
-
userUUID: this.localStorage.getItem(this.options.local_uuid_key),
|
|
745
|
-
projectKey: this.projectKey,
|
|
746
|
-
revID: this.revID,
|
|
747
|
-
trackerVersion: this.version,
|
|
748
|
-
isSnippet: this.options.__is_snippet,
|
|
749
|
-
};
|
|
750
|
-
}
|
|
751
|
-
getSessionInfo() {
|
|
752
|
-
return {
|
|
753
|
-
...this.session.getInfo(),
|
|
754
|
-
...this.getTrackerInfo(),
|
|
755
|
-
};
|
|
756
|
-
}
|
|
757
|
-
getSessionToken() {
|
|
758
|
-
return this.session.getSessionToken();
|
|
759
|
-
}
|
|
760
|
-
getSessionID() {
|
|
761
|
-
return this.session.getInfo().sessionID || undefined;
|
|
762
|
-
}
|
|
763
|
-
getSessionURL(options) {
|
|
764
|
-
const { projectID, sessionID, timestamp } = this.session.getInfo();
|
|
765
|
-
if (!projectID || !sessionID) {
|
|
766
|
-
this.debug.error('OpenReplay error: Unable to build session URL');
|
|
767
|
-
return undefined;
|
|
768
|
-
}
|
|
769
|
-
const ingest = this.options.ingestPoint;
|
|
770
|
-
const isSaas = /api\.openreplay\.com/.test(ingest);
|
|
771
|
-
const projectPath = isSaas ? 'https://app.openreplay.com/ingest' : ingest;
|
|
772
|
-
const url = projectPath.replace(/ingest$/, `${projectID}/session/${sessionID}`);
|
|
773
|
-
if (options?.withCurrentTime) {
|
|
774
|
-
const jumpTo = (0, utils_js_1.now)() - timestamp;
|
|
775
|
-
return `${url}?jumpto=${jumpTo}`;
|
|
776
|
-
}
|
|
777
|
-
return url;
|
|
778
|
-
}
|
|
779
|
-
getHost() {
|
|
780
|
-
return new URL(this.options.ingestPoint).host;
|
|
781
|
-
}
|
|
782
|
-
getProjectKey() {
|
|
783
|
-
return this.projectKey;
|
|
784
|
-
}
|
|
785
|
-
getBaseHref() {
|
|
786
|
-
if (typeof this.options.resourceBaseHref === 'string') {
|
|
787
|
-
return this.options.resourceBaseHref;
|
|
788
|
-
}
|
|
789
|
-
else if (typeof this.options.resourceBaseHref === 'object') {
|
|
790
|
-
//TODO: switch between types
|
|
791
|
-
}
|
|
792
|
-
if (document.baseURI) {
|
|
793
|
-
return document.baseURI;
|
|
794
|
-
}
|
|
795
|
-
// IE only
|
|
796
|
-
return (document.head?.getElementsByTagName('base')[0]?.getAttribute('href') ||
|
|
797
|
-
location.origin + location.pathname);
|
|
798
|
-
}
|
|
799
|
-
resolveResourceURL(resourceURL) {
|
|
800
|
-
const base = new URL(this.getBaseHref());
|
|
801
|
-
base.pathname += '/' + new URL(resourceURL).pathname;
|
|
802
|
-
base.pathname.replace(/\/+/g, '/');
|
|
803
|
-
return base.toString();
|
|
804
|
-
}
|
|
805
|
-
isServiceURL(url) {
|
|
806
|
-
return url.startsWith(this.options.ingestPoint);
|
|
807
|
-
}
|
|
808
|
-
active() {
|
|
809
|
-
return this.activityState === ActivityState.Active;
|
|
810
|
-
}
|
|
811
|
-
resetNextPageSession(flag) {
|
|
812
|
-
if (flag) {
|
|
813
|
-
this.sessionStorage.setItem(this.options.session_reset_key, 't');
|
|
814
|
-
}
|
|
815
|
-
else {
|
|
816
|
-
this.sessionStorage.removeItem(this.options.session_reset_key);
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
checkSessionToken(forceNew) {
|
|
820
|
-
const lsReset = this.sessionStorage.getItem(this.options.session_reset_key) !== null;
|
|
821
|
-
const needNewSessionID = forceNew || lsReset;
|
|
822
|
-
const sessionToken = this.session.getSessionToken();
|
|
823
|
-
return needNewSessionID || !sessionToken;
|
|
824
|
-
}
|
|
825
|
-
/**
|
|
826
|
-
* start buffering messages without starting the actual session, which gives
|
|
827
|
-
* user 30 seconds to "activate" and record session by calling `start()` on conditional trigger,
|
|
828
|
-
* and we will then send buffered batch, so it won't get lost
|
|
829
|
-
* */
|
|
830
|
-
async coldStart(startOpts = {}, conditional) {
|
|
831
|
-
this.singleBuffer = false;
|
|
832
|
-
const second = 1000;
|
|
833
|
-
const isNewSession = this.checkSessionToken(startOpts.forceNew);
|
|
834
|
-
if (conditional) {
|
|
835
|
-
await this.setupConditionalStart(startOpts);
|
|
836
|
-
}
|
|
837
|
-
const cycle = () => {
|
|
838
|
-
this.orderNumber += 1;
|
|
839
|
-
(0, utils_js_1.adjustTimeOrigin)();
|
|
840
|
-
this.coldStartTs = (0, utils_js_1.now)();
|
|
841
|
-
if (this.orderNumber % 2 === 0) {
|
|
842
|
-
this.bufferedMessages1.length = 0;
|
|
843
|
-
this.bufferedMessages1.push((0, messages_gen_js_1.Timestamp)(this.timestamp()));
|
|
844
|
-
this.bufferedMessages1.push((0, messages_gen_js_1.TabData)(this.session.getTabId()));
|
|
845
|
-
}
|
|
846
|
-
else {
|
|
847
|
-
this.bufferedMessages2.length = 0;
|
|
848
|
-
this.bufferedMessages2.push((0, messages_gen_js_1.Timestamp)(this.timestamp()));
|
|
849
|
-
this.bufferedMessages2.push((0, messages_gen_js_1.TabData)(this.session.getTabId()));
|
|
850
|
-
}
|
|
851
|
-
this.stop(false);
|
|
852
|
-
this.activityState = ActivityState.ColdStart;
|
|
853
|
-
if (startOpts.sessionHash) {
|
|
854
|
-
this.session.applySessionHash(startOpts.sessionHash);
|
|
855
|
-
}
|
|
856
|
-
if (startOpts.forceNew) {
|
|
857
|
-
this.session.reset();
|
|
858
|
-
}
|
|
859
|
-
this.session.assign({
|
|
860
|
-
userID: startOpts.userID,
|
|
861
|
-
metadata: startOpts.metadata,
|
|
862
|
-
});
|
|
863
|
-
if (!isNewSession) {
|
|
864
|
-
this.debug.log('continuing session on new tab', this.session.getTabId());
|
|
865
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
866
|
-
this.send((0, messages_gen_js_1.TabChange)(this.session.getTabId()));
|
|
867
|
-
}
|
|
868
|
-
this.observer.observe();
|
|
869
|
-
this.ticker.start();
|
|
870
|
-
};
|
|
871
|
-
this.coldInterval = setInterval(() => {
|
|
872
|
-
cycle();
|
|
873
|
-
}, 30 * second);
|
|
874
|
-
cycle();
|
|
875
|
-
}
|
|
876
|
-
async setupConditionalStart(startOpts) {
|
|
877
|
-
this.conditionsManager = new conditionsManager_js_1.default(this, startOpts);
|
|
878
|
-
const r = await fetch(this.options.ingestPoint + '/v1/web/start', {
|
|
879
|
-
method: 'POST',
|
|
880
|
-
headers: {
|
|
881
|
-
'Content-Type': 'application/json',
|
|
882
|
-
},
|
|
883
|
-
body: JSON.stringify({
|
|
884
|
-
...this.getTrackerInfo(),
|
|
885
|
-
timestamp: (0, utils_js_1.now)(),
|
|
886
|
-
doNotRecord: true,
|
|
887
|
-
bufferDiff: 0,
|
|
888
|
-
userID: this.session.getInfo().userID,
|
|
889
|
-
token: undefined,
|
|
890
|
-
deviceMemory: performance_js_1.deviceMemory,
|
|
891
|
-
jsHeapSizeLimit: performance_js_1.jsHeapSizeLimit,
|
|
892
|
-
timezone: getTimezone(),
|
|
893
|
-
width: window.screen.width,
|
|
894
|
-
height: window.screen.height,
|
|
895
|
-
}),
|
|
896
|
-
});
|
|
897
|
-
const {
|
|
898
|
-
// this token is needed to fetch conditions and flags,
|
|
899
|
-
// but it can't be used to record a session
|
|
900
|
-
token, userBrowser, userCity, userCountry, userDevice, userOS, userState, projectID, features, } = await r.json();
|
|
901
|
-
this.features = features ? features : this.features;
|
|
902
|
-
this.session.assign({ projectID });
|
|
903
|
-
this.session.setUserInfo({
|
|
904
|
-
userBrowser,
|
|
905
|
-
userCity,
|
|
906
|
-
userCountry,
|
|
907
|
-
userDevice,
|
|
908
|
-
userOS,
|
|
909
|
-
userState,
|
|
910
|
-
});
|
|
911
|
-
const onStartInfo = { sessionToken: token, userUUID: '', sessionID: '' };
|
|
912
|
-
this.startCallbacks.forEach((cb) => cb(onStartInfo));
|
|
913
|
-
await this.conditionsManager?.fetchConditions(projectID, token);
|
|
914
|
-
if (this.features['feature-flags']) {
|
|
915
|
-
await this.featureFlags.reloadFlags(token);
|
|
916
|
-
this.conditionsManager?.processFlags(this.featureFlags.flags);
|
|
917
|
-
}
|
|
918
|
-
await this.tagWatcher.fetchTags(this.options.ingestPoint, token);
|
|
919
|
-
}
|
|
920
|
-
/**
|
|
921
|
-
* Starts offline session recording
|
|
922
|
-
* @param {Object} startOpts - options for session start, same as .start()
|
|
923
|
-
* @param {Function} onSessionSent - callback that will be called once session is fully sent
|
|
924
|
-
* */
|
|
925
|
-
offlineRecording(startOpts = {}, onSessionSent) {
|
|
926
|
-
this.onSessionSent = onSessionSent;
|
|
927
|
-
this.singleBuffer = true;
|
|
928
|
-
const isNewSession = this.checkSessionToken(startOpts.forceNew);
|
|
929
|
-
(0, utils_js_1.adjustTimeOrigin)();
|
|
930
|
-
this.coldStartTs = (0, utils_js_1.now)();
|
|
931
|
-
const saverBuffer = this.localStorage.getItem(bufferStorageKey);
|
|
932
|
-
if (saverBuffer) {
|
|
933
|
-
const data = JSON.parse(saverBuffer);
|
|
934
|
-
this.bufferedMessages1 = Array.isArray(data) ? data : this.bufferedMessages1;
|
|
935
|
-
this.localStorage.removeItem(bufferStorageKey);
|
|
936
|
-
}
|
|
937
|
-
this.bufferedMessages1.push((0, messages_gen_js_1.Timestamp)(this.timestamp()));
|
|
938
|
-
this.bufferedMessages1.push((0, messages_gen_js_1.TabData)(this.session.getTabId()));
|
|
939
|
-
this.activityState = ActivityState.ColdStart;
|
|
940
|
-
if (startOpts.sessionHash) {
|
|
941
|
-
this.session.applySessionHash(startOpts.sessionHash);
|
|
942
|
-
}
|
|
943
|
-
if (startOpts.forceNew) {
|
|
944
|
-
this.session.reset();
|
|
945
|
-
}
|
|
946
|
-
this.session.assign({
|
|
947
|
-
userID: startOpts.userID,
|
|
948
|
-
metadata: startOpts.metadata,
|
|
949
|
-
});
|
|
950
|
-
const onStartInfo = { sessionToken: '', userUUID: '', sessionID: '' };
|
|
951
|
-
this.startCallbacks.forEach((cb) => cb(onStartInfo));
|
|
952
|
-
if (!isNewSession) {
|
|
953
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
954
|
-
this.send((0, messages_gen_js_1.TabChange)(this.session.getTabId()));
|
|
955
|
-
}
|
|
956
|
-
this.observer.observe();
|
|
957
|
-
this.ticker.start();
|
|
958
|
-
return {
|
|
959
|
-
saveBuffer: this.saveBuffer,
|
|
960
|
-
getBuffer: this.getBuffer,
|
|
961
|
-
setBuffer: this.setBuffer,
|
|
962
|
-
};
|
|
963
|
-
}
|
|
964
|
-
/**
|
|
965
|
-
* Saves the captured messages in localStorage (or whatever is used in its place)
|
|
966
|
-
*
|
|
967
|
-
* Then, when this.offlineRecording is called, it will preload this messages and clear the storage item
|
|
968
|
-
*
|
|
969
|
-
* Keeping the size of local storage reasonable is up to the end users of this library
|
|
970
|
-
* */
|
|
971
|
-
saveBuffer() {
|
|
972
|
-
this.localStorage.setItem(bufferStorageKey, JSON.stringify(this.bufferedMessages1));
|
|
973
|
-
}
|
|
974
|
-
/**
|
|
975
|
-
* @returns buffer with stored messages for offline recording
|
|
976
|
-
* */
|
|
977
|
-
getBuffer() {
|
|
978
|
-
return this.bufferedMessages1;
|
|
979
|
-
}
|
|
980
|
-
/**
|
|
981
|
-
* Used to set a buffer with messages array
|
|
982
|
-
* */
|
|
983
|
-
setBuffer(buffer) {
|
|
984
|
-
this.bufferedMessages1 = buffer;
|
|
985
|
-
}
|
|
986
|
-
/**
|
|
987
|
-
* Uploads the stored session buffer to backend
|
|
988
|
-
* @returns promise that resolves once messages are loaded, it has to be awaited
|
|
989
|
-
* so the session can be uploaded properly
|
|
990
|
-
* @resolve - if messages were loaded in service worker successfully
|
|
991
|
-
* @reject {string} - error message
|
|
992
|
-
* */
|
|
993
|
-
async uploadOfflineRecording() {
|
|
994
|
-
this.stop(false);
|
|
995
|
-
const timestamp = (0, utils_js_1.now)();
|
|
996
|
-
this.worker?.postMessage({
|
|
997
|
-
type: 'start',
|
|
998
|
-
pageNo: this.session.incPageNo(),
|
|
999
|
-
ingestPoint: this.options.ingestPoint,
|
|
1000
|
-
timestamp: this.coldStartTs,
|
|
1001
|
-
url: document.URL,
|
|
1002
|
-
connAttemptCount: this.options.connAttemptCount,
|
|
1003
|
-
connAttemptGap: this.options.connAttemptGap,
|
|
1004
|
-
tabId: this.session.getTabId(),
|
|
1005
|
-
});
|
|
1006
|
-
const r = await fetch(this.options.ingestPoint + '/v1/web/start', {
|
|
1007
|
-
method: 'POST',
|
|
1008
|
-
headers: {
|
|
1009
|
-
'Content-Type': 'application/json',
|
|
1010
|
-
},
|
|
1011
|
-
body: JSON.stringify({
|
|
1012
|
-
...this.getTrackerInfo(),
|
|
1013
|
-
timestamp: timestamp,
|
|
1014
|
-
doNotRecord: false,
|
|
1015
|
-
bufferDiff: timestamp - this.coldStartTs,
|
|
1016
|
-
userID: this.session.getInfo().userID,
|
|
1017
|
-
token: undefined,
|
|
1018
|
-
deviceMemory: performance_js_1.deviceMemory,
|
|
1019
|
-
jsHeapSizeLimit: performance_js_1.jsHeapSizeLimit,
|
|
1020
|
-
timezone: getTimezone(),
|
|
1021
|
-
}),
|
|
1022
|
-
});
|
|
1023
|
-
const { token, userBrowser, userCity, userCountry, userDevice, userOS, userState, beaconSizeLimit, projectID, } = await r.json();
|
|
1024
|
-
this.worker?.postMessage({
|
|
1025
|
-
type: 'auth',
|
|
1026
|
-
token,
|
|
1027
|
-
beaconSizeLimit,
|
|
1028
|
-
});
|
|
1029
|
-
this.session.assign({ projectID });
|
|
1030
|
-
this.session.setUserInfo({
|
|
1031
|
-
userBrowser,
|
|
1032
|
-
userCity,
|
|
1033
|
-
userCountry,
|
|
1034
|
-
userDevice,
|
|
1035
|
-
userOS,
|
|
1036
|
-
userState,
|
|
1037
|
-
});
|
|
1038
|
-
while (this.bufferedMessages1.length > 0) {
|
|
1039
|
-
await this.flushBuffer(this.bufferedMessages1);
|
|
1040
|
-
}
|
|
1041
|
-
this.postToWorker([['q_end']]);
|
|
1042
|
-
this.clearBuffers();
|
|
1043
|
-
}
|
|
1044
|
-
async _start(startOpts = {}, resetByWorker = false, conditionName) {
|
|
1045
|
-
const isColdStart = this.activityState === ActivityState.ColdStart;
|
|
1046
|
-
if (isColdStart && this.coldInterval) {
|
|
1047
|
-
clearInterval(this.coldInterval);
|
|
1048
|
-
}
|
|
1049
|
-
if (!this.worker && !this.insideIframe) {
|
|
1050
|
-
const reason = 'No worker found: perhaps, CSP is not set.';
|
|
1051
|
-
this.signalError(reason, []);
|
|
1052
|
-
return Promise.resolve(UnsuccessfulStart(reason));
|
|
1053
|
-
}
|
|
1054
|
-
if (this.activityState === ActivityState.Active ||
|
|
1055
|
-
this.activityState === ActivityState.Starting) {
|
|
1056
|
-
const reason = 'OpenReplay: trying to call `start()` on the instance that has been started already.';
|
|
1057
|
-
return Promise.resolve(UnsuccessfulStart(reason));
|
|
1058
|
-
}
|
|
1059
|
-
this.activityState = ActivityState.Starting;
|
|
1060
|
-
if (!isColdStart) {
|
|
1061
|
-
(0, utils_js_1.adjustTimeOrigin)();
|
|
1062
|
-
}
|
|
1063
|
-
if (startOpts.sessionHash) {
|
|
1064
|
-
this.session.applySessionHash(startOpts.sessionHash);
|
|
1065
|
-
}
|
|
1066
|
-
if (startOpts.forceNew) {
|
|
1067
|
-
// Reset session metadata only if requested directly
|
|
1068
|
-
this.session.reset();
|
|
1069
|
-
}
|
|
1070
|
-
this.session.assign({
|
|
1071
|
-
// MBTODO: maybe it would make sense to `forceNew` if the `userID` was changed
|
|
1072
|
-
userID: startOpts.userID,
|
|
1073
|
-
metadata: startOpts.metadata,
|
|
1074
|
-
});
|
|
1075
|
-
const timestamp = (0, utils_js_1.now)();
|
|
1076
|
-
this.worker?.postMessage({
|
|
1077
|
-
type: 'start',
|
|
1078
|
-
pageNo: this.session.incPageNo(),
|
|
1079
|
-
ingestPoint: this.options.ingestPoint,
|
|
1080
|
-
timestamp: isColdStart ? this.coldStartTs : timestamp,
|
|
1081
|
-
url: document.URL,
|
|
1082
|
-
connAttemptCount: this.options.connAttemptCount,
|
|
1083
|
-
connAttemptGap: this.options.connAttemptGap,
|
|
1084
|
-
tabId: this.session.getTabId(),
|
|
1085
|
-
});
|
|
1086
|
-
const sessionToken = this.session.getSessionToken();
|
|
1087
|
-
const isNewSession = this.checkSessionToken(startOpts.forceNew);
|
|
1088
|
-
this.sessionStorage.removeItem(this.options.session_reset_key);
|
|
1089
|
-
this.debug.log('OpenReplay: starting session; need new session id?', isNewSession, 'session token: ', sessionToken);
|
|
1090
|
-
try {
|
|
1091
|
-
const r = await window.fetch(this.options.ingestPoint + '/v1/web/start', {
|
|
1092
|
-
method: 'POST',
|
|
1093
|
-
headers: {
|
|
1094
|
-
'Content-Type': 'application/json',
|
|
1095
|
-
},
|
|
1096
|
-
body: JSON.stringify({
|
|
1097
|
-
...this.getTrackerInfo(),
|
|
1098
|
-
timestamp,
|
|
1099
|
-
doNotRecord: false,
|
|
1100
|
-
bufferDiff: timestamp - this.coldStartTs,
|
|
1101
|
-
userID: this.session.getInfo().userID,
|
|
1102
|
-
token: isNewSession ? undefined : sessionToken,
|
|
1103
|
-
deviceMemory: performance_js_1.deviceMemory,
|
|
1104
|
-
jsHeapSizeLimit: performance_js_1.jsHeapSizeLimit,
|
|
1105
|
-
timezone: getTimezone(),
|
|
1106
|
-
condition: conditionName,
|
|
1107
|
-
assistOnly: startOpts.assistOnly ?? this.socketMode,
|
|
1108
|
-
width: window.screen.width,
|
|
1109
|
-
height: window.screen.height,
|
|
1110
|
-
}),
|
|
1111
|
-
});
|
|
1112
|
-
if (r.status !== 200) {
|
|
1113
|
-
const error = await r.text();
|
|
1114
|
-
const reason = error === CANCELED ? CANCELED : `Server error: ${r.status}. ${error}`;
|
|
1115
|
-
return UnsuccessfulStart(reason);
|
|
1116
|
-
}
|
|
1117
|
-
if (!this.worker && !this.insideIframe) {
|
|
1118
|
-
const reason = 'no worker found after start request (this should not happen in real world)';
|
|
1119
|
-
this.signalError(reason, []);
|
|
1120
|
-
return UnsuccessfulStart(reason);
|
|
1121
|
-
}
|
|
1122
|
-
const { token, userUUID, projectID, beaconSizeLimit, compressionThreshold, // how big the batch should be before we decide to compress it
|
|
1123
|
-
delay, // derived from token
|
|
1124
|
-
sessionID, // derived from token
|
|
1125
|
-
startTimestamp, // real startTS (server time), derived from sessionID
|
|
1126
|
-
userBrowser, userCity, userCountry, userDevice, userOS, userState, canvasEnabled, canvasQuality, canvasFPS, assistOnly: socketOnly, features, } = await r.json();
|
|
1127
|
-
this.features = features ? features : this.features;
|
|
1128
|
-
if (typeof token !== 'string' ||
|
|
1129
|
-
typeof userUUID !== 'string' ||
|
|
1130
|
-
(typeof startTimestamp !== 'number' && typeof startTimestamp !== 'undefined') ||
|
|
1131
|
-
typeof sessionID !== 'string' ||
|
|
1132
|
-
typeof delay !== 'number' ||
|
|
1133
|
-
(typeof beaconSizeLimit !== 'number' && typeof beaconSizeLimit !== 'undefined')) {
|
|
1134
|
-
const reason = `Incorrect server response: ${JSON.stringify(r)}`;
|
|
1135
|
-
this.signalError(reason, []);
|
|
1136
|
-
return UnsuccessfulStart(reason);
|
|
1137
|
-
}
|
|
1138
|
-
this.delay = delay;
|
|
1139
|
-
this.session.setSessionToken(token);
|
|
1140
|
-
this.session.setUserInfo({
|
|
1141
|
-
userBrowser,
|
|
1142
|
-
userCity,
|
|
1143
|
-
userCountry,
|
|
1144
|
-
userDevice,
|
|
1145
|
-
userOS,
|
|
1146
|
-
userState,
|
|
1147
|
-
});
|
|
1148
|
-
this.session.assign({
|
|
1149
|
-
sessionID,
|
|
1150
|
-
timestamp: startTimestamp || timestamp,
|
|
1151
|
-
projectID,
|
|
1152
|
-
});
|
|
1153
|
-
if (socketOnly) {
|
|
1154
|
-
this.socketMode = true;
|
|
1155
|
-
this.worker?.postMessage('stop');
|
|
1156
|
-
}
|
|
1157
|
-
else {
|
|
1158
|
-
this.worker?.postMessage({
|
|
1159
|
-
type: 'auth',
|
|
1160
|
-
token,
|
|
1161
|
-
beaconSizeLimit,
|
|
1162
|
-
});
|
|
1163
|
-
}
|
|
1164
|
-
if (!isNewSession && token === sessionToken) {
|
|
1165
|
-
this.debug.log('continuing session on new tab', this.session.getTabId());
|
|
1166
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
1167
|
-
this.send((0, messages_gen_js_1.TabChange)(this.session.getTabId()));
|
|
1168
|
-
}
|
|
1169
|
-
// (Re)send Metadata for the case of a new session
|
|
1170
|
-
Object.entries(this.session.getInfo().metadata).forEach(([key, value]) => this.send((0, messages_gen_js_1.Metadata)(key, value)));
|
|
1171
|
-
this.localStorage.setItem(this.options.local_uuid_key, userUUID);
|
|
1172
|
-
this.compressionThreshold = compressionThreshold;
|
|
1173
|
-
const onStartInfo = { sessionToken: token, userUUID, sessionID };
|
|
1174
|
-
// TODO: start as early as possible (before receiving the token)
|
|
1175
|
-
/** after start */
|
|
1176
|
-
this.startCallbacks.forEach((cb) => cb(onStartInfo)); // MBTODO: callbacks after DOM "mounted" (observed)
|
|
1177
|
-
if (startOpts.startCallback) {
|
|
1178
|
-
startOpts.startCallback(SuccessfulStart(onStartInfo));
|
|
1179
|
-
}
|
|
1180
|
-
if (this.features['feature-flags']) {
|
|
1181
|
-
void this.featureFlags.reloadFlags();
|
|
1182
|
-
}
|
|
1183
|
-
await this.tagWatcher.fetchTags(this.options.ingestPoint, token);
|
|
1184
|
-
this.activityState = ActivityState.Active;
|
|
1185
|
-
if (this.options.crossdomain?.enabled && !this.insideIframe) {
|
|
1186
|
-
void this.bootChildrenFrames();
|
|
1187
|
-
}
|
|
1188
|
-
if (canvasEnabled && !this.options.canvas.disableCanvas) {
|
|
1189
|
-
this.canvasRecorder =
|
|
1190
|
-
this.canvasRecorder ??
|
|
1191
|
-
new canvas_js_1.default(this, {
|
|
1192
|
-
fps: canvasFPS,
|
|
1193
|
-
quality: canvasQuality,
|
|
1194
|
-
isDebug: this.options.canvas.__save_canvas_locally,
|
|
1195
|
-
fixedScaling: this.options.canvas.fixedCanvasScaling,
|
|
1196
|
-
useAnimationFrame: this.options.canvas.useAnimationFrame,
|
|
1197
|
-
});
|
|
1198
|
-
}
|
|
1199
|
-
/** --------------- COLD START BUFFER ------------------*/
|
|
1200
|
-
if (isColdStart) {
|
|
1201
|
-
const biggestBuffer = this.bufferedMessages1.length > this.bufferedMessages2.length
|
|
1202
|
-
? this.bufferedMessages1
|
|
1203
|
-
: this.bufferedMessages2;
|
|
1204
|
-
while (biggestBuffer.length > 0) {
|
|
1205
|
-
await this.flushBuffer(biggestBuffer);
|
|
1206
|
-
}
|
|
1207
|
-
this.clearBuffers();
|
|
1208
|
-
this.commit();
|
|
1209
|
-
/** --------------- COLD START BUFFER ------------------*/
|
|
1210
|
-
}
|
|
1211
|
-
else {
|
|
1212
|
-
if (this.insideIframe && this.rootId) {
|
|
1213
|
-
this.observer.crossdomainObserve(this.rootId, this.frameOderNumber);
|
|
1214
|
-
}
|
|
1215
|
-
else {
|
|
1216
|
-
this.observer.observe();
|
|
1217
|
-
}
|
|
1218
|
-
this.ticker.start();
|
|
1219
|
-
}
|
|
1220
|
-
this.canvasRecorder?.startTracking();
|
|
1221
|
-
if (this.features['usability-test']) {
|
|
1222
|
-
this.uxtManager = this.uxtManager
|
|
1223
|
-
? this.uxtManager
|
|
1224
|
-
: new index_js_1.default(this, uxtStorageKey);
|
|
1225
|
-
let uxtId;
|
|
1226
|
-
const savedUxtTag = this.localStorage.getItem(uxtStorageKey);
|
|
1227
|
-
if (savedUxtTag) {
|
|
1228
|
-
uxtId = parseInt(savedUxtTag, 10);
|
|
1229
|
-
}
|
|
1230
|
-
if (location?.search) {
|
|
1231
|
-
const query = new URLSearchParams(location.search);
|
|
1232
|
-
if (query.has('oruxt')) {
|
|
1233
|
-
const qId = query.get('oruxt');
|
|
1234
|
-
uxtId = qId ? parseInt(qId, 10) : undefined;
|
|
1235
|
-
}
|
|
1236
|
-
}
|
|
1237
|
-
if (uxtId) {
|
|
1238
|
-
if (!this.uxtManager.isActive) {
|
|
1239
|
-
// eslint-disable-next-line
|
|
1240
|
-
this.uxtManager.getTest(uxtId, token, Boolean(savedUxtTag)).then((id) => {
|
|
1241
|
-
if (id) {
|
|
1242
|
-
this.onUxtCb.forEach((cb) => cb(id));
|
|
1243
|
-
}
|
|
1244
|
-
});
|
|
1245
|
-
}
|
|
1246
|
-
else {
|
|
1247
|
-
// @ts-ignore
|
|
1248
|
-
this.onUxtCb.forEach((cb) => cb(uxtId));
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
return SuccessfulStart(onStartInfo);
|
|
1253
|
-
}
|
|
1254
|
-
catch (reason) {
|
|
1255
|
-
this.stop();
|
|
1256
|
-
this.session.reset();
|
|
1257
|
-
if (!reason) {
|
|
1258
|
-
console.error('Unknown error during start');
|
|
1259
|
-
this.signalError('Unknown error', []);
|
|
1260
|
-
return UnsuccessfulStart('Unknown error');
|
|
1261
|
-
}
|
|
1262
|
-
if (reason === CANCELED) {
|
|
1263
|
-
this.signalError(CANCELED, []);
|
|
1264
|
-
return UnsuccessfulStart(CANCELED);
|
|
1265
|
-
}
|
|
1266
|
-
this._debug('session_start', reason);
|
|
1267
|
-
const errorMessage = reason instanceof Error ? reason.message : reason.toString();
|
|
1268
|
-
this.signalError(errorMessage, []);
|
|
1269
|
-
return UnsuccessfulStart(errorMessage);
|
|
1270
|
-
}
|
|
1271
|
-
}
|
|
1272
|
-
addOnUxtCb(cb) {
|
|
1273
|
-
// @ts-ignore
|
|
1274
|
-
this.onUxtCb.push(cb);
|
|
1275
|
-
}
|
|
1276
|
-
getUxtId() {
|
|
1277
|
-
return this.uxtManager?.getTestId();
|
|
1278
|
-
}
|
|
1279
|
-
async waitStart() {
|
|
1280
|
-
return new Promise((resolve) => {
|
|
1281
|
-
const check = () => {
|
|
1282
|
-
if (this.canStart) {
|
|
1283
|
-
resolve(true);
|
|
1284
|
-
}
|
|
1285
|
-
else {
|
|
1286
|
-
setTimeout(check, 25);
|
|
1287
|
-
}
|
|
1288
|
-
};
|
|
1289
|
-
check();
|
|
1290
|
-
});
|
|
1291
|
-
}
|
|
1292
|
-
async waitStarted() {
|
|
1293
|
-
return this.waitStatus(ActivityState.Active);
|
|
1294
|
-
}
|
|
1295
|
-
async waitStatus(status) {
|
|
1296
|
-
return new Promise((resolve) => {
|
|
1297
|
-
const check = () => {
|
|
1298
|
-
if (this.activityState === status) {
|
|
1299
|
-
resolve(true);
|
|
1300
|
-
}
|
|
1301
|
-
else {
|
|
1302
|
-
setTimeout(check, 25);
|
|
1303
|
-
}
|
|
1304
|
-
};
|
|
1305
|
-
check();
|
|
1306
|
-
});
|
|
1307
|
-
}
|
|
1308
|
-
/**
|
|
1309
|
-
* basically we ask other tabs during constructor
|
|
1310
|
-
* and here we just apply 10ms delay just in case
|
|
1311
|
-
* */
|
|
1312
|
-
async start(...args) {
|
|
1313
|
-
if (this.activityState === ActivityState.Active ||
|
|
1314
|
-
this.activityState === ActivityState.Starting) {
|
|
1315
|
-
const reason = 'OpenReplay: trying to call `start()` on the instance that has been started already.';
|
|
1316
|
-
return Promise.resolve(UnsuccessfulStart(reason));
|
|
1317
|
-
}
|
|
1318
|
-
if (this.insideIframe) {
|
|
1319
|
-
this.signalIframeTracker();
|
|
1320
|
-
}
|
|
1321
|
-
if (!document.hidden) {
|
|
1322
|
-
await this.waitStart();
|
|
1323
|
-
return this._start(...args);
|
|
1324
|
-
}
|
|
1325
|
-
else {
|
|
1326
|
-
return new Promise((resolve) => {
|
|
1327
|
-
const onVisibilityChange = async () => {
|
|
1328
|
-
if (!document.hidden) {
|
|
1329
|
-
await this.waitStart();
|
|
1330
|
-
// eslint-disable-next-line
|
|
1331
|
-
document.removeEventListener('visibilitychange', onVisibilityChange);
|
|
1332
|
-
resolve(this._start(...args));
|
|
1333
|
-
}
|
|
1334
|
-
};
|
|
1335
|
-
// eslint-disable-next-line
|
|
1336
|
-
document.addEventListener('visibilitychange', onVisibilityChange);
|
|
1337
|
-
});
|
|
1338
|
-
}
|
|
1339
|
-
}
|
|
1340
|
-
forceFlushBatch() {
|
|
1341
|
-
this.worker?.postMessage('forceFlushBatch');
|
|
1342
|
-
}
|
|
1343
|
-
getTabId() {
|
|
1344
|
-
return this.session.getTabId();
|
|
1345
|
-
}
|
|
1346
|
-
clearBuffers() {
|
|
1347
|
-
this.bufferedMessages1.length = 0;
|
|
1348
|
-
this.bufferedMessages2.length = 0;
|
|
1349
|
-
}
|
|
1350
|
-
/**
|
|
1351
|
-
* Creates a named hook that expects event name, data string and msg direction (up/down),
|
|
1352
|
-
* it will skip any message bigger than 5 mb or event name bigger than 255 symbols
|
|
1353
|
-
* @returns {(msgType: string, data: string, dir: "up" | "down") => void}
|
|
1354
|
-
* */
|
|
1355
|
-
trackWs(channelName) {
|
|
1356
|
-
const channel = channelName;
|
|
1357
|
-
return (msgType, data, dir = 'down') => {
|
|
1358
|
-
if (typeof msgType !== 'string' ||
|
|
1359
|
-
typeof data !== 'string' ||
|
|
1360
|
-
data.length > 5 * 1024 * 1024 ||
|
|
1361
|
-
msgType.length > 255) {
|
|
1362
|
-
return;
|
|
1363
|
-
}
|
|
1364
|
-
this.send((0, messages_gen_js_1.WSChannel)('websocket', channel, data, this.timestamp(), dir, msgType));
|
|
1365
|
-
};
|
|
1366
|
-
}
|
|
1367
|
-
stop(stopWorker = true) {
|
|
1368
|
-
if (this.activityState !== ActivityState.NotActive) {
|
|
1369
|
-
console.trace('stopped');
|
|
1370
|
-
try {
|
|
1371
|
-
if (!this.insideIframe && this.options.crossdomain?.enabled) {
|
|
1372
|
-
this.killChildrenFrames();
|
|
1373
|
-
}
|
|
1374
|
-
this.attributeSender.clear();
|
|
1375
|
-
this.sanitizer.clear();
|
|
1376
|
-
this.observer.disconnect();
|
|
1377
|
-
this.nodes.clear();
|
|
1378
|
-
this.ticker.stop();
|
|
1379
|
-
this.stopCallbacks.forEach((cb) => cb());
|
|
1380
|
-
this.tagWatcher.clear();
|
|
1381
|
-
if (this.worker && stopWorker) {
|
|
1382
|
-
this.worker.postMessage('stop');
|
|
1383
|
-
}
|
|
1384
|
-
this.canvasRecorder?.clear();
|
|
1385
|
-
this.messages.length = 0;
|
|
1386
|
-
this.trackedFrames = [];
|
|
1387
|
-
this.parentActive = false;
|
|
1388
|
-
this.canStart = false;
|
|
1389
|
-
}
|
|
1390
|
-
finally {
|
|
1391
|
-
this.activityState = ActivityState.NotActive;
|
|
1392
|
-
this.debug.log('OpenReplay tracking stopped.');
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1395
|
-
}
|
|
1396
|
-
}
|
|
1397
|
-
exports.default = App;
|