@openreplay/tracker 17.2.5 → 18.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/common/interaction.d.ts +12 -1
- package/dist/cjs/common/messages.gen.d.ts +4 -7
- package/dist/cjs/entry.js +233 -25
- package/dist/cjs/entry.js.map +1 -1
- package/dist/cjs/index.js +233 -25
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/main/app/index.d.ts +3 -0
- package/dist/cjs/main/app/messages.gen.d.ts +0 -1
- package/dist/cjs/main/modules/tagMatcher.d.ts +28 -0
- package/dist/cjs/main/modules/tagWatcher.d.ts +4 -8
- package/dist/lib/common/interaction.d.ts +12 -1
- package/dist/lib/common/messages.gen.d.ts +4 -7
- package/dist/lib/entry.js +233 -25
- package/dist/lib/entry.js.map +1 -1
- package/dist/lib/index.js +233 -25
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/main/app/index.d.ts +3 -0
- package/dist/lib/main/app/messages.gen.d.ts +0 -1
- package/dist/lib/main/modules/tagMatcher.d.ts +28 -0
- package/dist/lib/main/modules/tagWatcher.d.ts +4 -8
- package/dist/types/common/interaction.d.ts +12 -1
- package/dist/types/common/messages.gen.d.ts +4 -7
- package/dist/types/main/app/index.d.ts +3 -0
- package/dist/types/main/app/messages.gen.d.ts +0 -1
- package/dist/types/main/modules/tagMatcher.d.ts +28 -0
- package/dist/types/main/modules/tagWatcher.d.ts +4 -8
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Message from './messages.gen.js';
|
|
2
|
+
export type DataType = 'player' | 'assets' | 'devtools' | 'analytics';
|
|
2
3
|
export interface Options {
|
|
3
4
|
connAttemptCount?: number;
|
|
4
5
|
connAttemptGap?: number;
|
|
@@ -10,18 +11,22 @@ type Start = {
|
|
|
10
11
|
timestamp: number;
|
|
11
12
|
url: string;
|
|
12
13
|
tabId: string;
|
|
14
|
+
localDebug?: boolean;
|
|
13
15
|
} & Options;
|
|
14
16
|
type Auth = {
|
|
15
17
|
type: 'auth';
|
|
16
18
|
token: string;
|
|
17
19
|
beaconSizeLimit?: number;
|
|
20
|
+
protocolVersion?: number;
|
|
18
21
|
};
|
|
19
22
|
export type ToWorkerData = null | 'stop' | Start | Auth | Array<Message> | {
|
|
20
23
|
type: 'compressed';
|
|
21
24
|
batch: Uint8Array;
|
|
25
|
+
dataType: DataType;
|
|
22
26
|
} | {
|
|
23
27
|
type: 'uncompressed';
|
|
24
28
|
batch: Uint8Array;
|
|
29
|
+
dataType: DataType;
|
|
25
30
|
} | 'forceFlushBatch' | 'closing' | 'check_queue';
|
|
26
31
|
type Failure = {
|
|
27
32
|
type: 'failure';
|
|
@@ -30,8 +35,14 @@ type Failure = {
|
|
|
30
35
|
type QEmpty = {
|
|
31
36
|
type: 'queue_empty';
|
|
32
37
|
};
|
|
38
|
+
type LocalSave = {
|
|
39
|
+
type: 'local_save';
|
|
40
|
+
name: string;
|
|
41
|
+
batch: Uint8Array;
|
|
42
|
+
};
|
|
33
43
|
export type FromWorkerData = 'a_stop' | 'a_start' | Failure | 'not_init' | {
|
|
34
44
|
type: 'compress';
|
|
35
45
|
batch: Uint8Array;
|
|
36
|
-
|
|
46
|
+
dataType: DataType;
|
|
47
|
+
} | QEmpty | LocalSave;
|
|
37
48
|
export {};
|
|
@@ -61,7 +61,6 @@ export declare const enum Type {
|
|
|
61
61
|
JSException = 78,
|
|
62
62
|
Zustand = 79,
|
|
63
63
|
BatchMetadata = 81,
|
|
64
|
-
PartitionedMessage = 82,
|
|
65
64
|
NetworkRequest = 83,
|
|
66
65
|
WSChannel = 84,
|
|
67
66
|
ResourceTiming = 85,
|
|
@@ -442,11 +441,6 @@ export type BatchMetadata = [
|
|
|
442
441
|
number,
|
|
443
442
|
string
|
|
444
443
|
];
|
|
445
|
-
export type PartitionedMessage = [
|
|
446
|
-
Type.PartitionedMessage,
|
|
447
|
-
number,
|
|
448
|
-
number
|
|
449
|
-
];
|
|
450
444
|
export type NetworkRequest = [
|
|
451
445
|
Type.NetworkRequest,
|
|
452
446
|
string,
|
|
@@ -583,5 +577,8 @@ export type WebVitals = [
|
|
|
583
577
|
string,
|
|
584
578
|
string
|
|
585
579
|
];
|
|
586
|
-
|
|
580
|
+
export declare const ASSET_MESSAGES: ReadonlySet<number>;
|
|
581
|
+
export declare const DEVTOOLS_MESSAGES: ReadonlySet<number>;
|
|
582
|
+
export declare const ANALYTICS_MESSAGES: ReadonlySet<number>;
|
|
583
|
+
type Message = Timestamp | SetPageLocationDeprecated | SetViewportSize | SetViewportScroll | CreateDocument | CreateElementNode | CreateTextNode | MoveNode | RemoveNode | SetNodeAttribute | RemoveNodeAttribute | SetNodeData | SetNodeScroll | SetInputTarget | SetInputValue | SetInputChecked | MouseMove | NetworkRequestDeprecated | ConsoleLog | PageLoadTiming | PageRenderTiming | CustomEvent | UserID | UserAnonymousID | Metadata | StringDictGlobal | SetNodeAttributeDictGlobal | NodeAnimationResult | Profiler | OTable | StateAction | ReduxDeprecated | Vuex | MobX | NgRx | GraphQLDeprecated | PerformanceTrack | StringDictDeprecated | SetNodeAttributeDictDeprecated | StringDict | SetNodeAttributeDict | ResourceTimingDeprecatedDeprecated | ConnectionInformation | SetPageVisibility | LoadFontFace | SetNodeFocus | SetNodeAttributeURLBased | SetCSSDataURLBased | TechnicalInfo | CustomIssue | SetNodeSlot | MouseClick | MouseClickDeprecated | CreateIFrameDocument | AdoptedSSReplaceURLBased | AdoptedSSInsertRuleURLBased | AdoptedSSDeleteRule | AdoptedSSAddOwner | AdoptedSSRemoveOwner | JSException | Zustand | BatchMetadata | NetworkRequest | WSChannel | ResourceTiming | Incident | LongAnimationTask | InputChange | SelectionChange | MouseThrashing | UnbindNodes | ResourceTimingDeprecated | TabChange | TabData | CanvasNode | TagTrigger | Redux | SetPageLocation | GraphQL | WebVitals;
|
|
587
584
|
export default Message;
|
package/dist/cjs/entry.js
CHANGED
|
@@ -1211,13 +1211,6 @@ function BatchMetadata(version, pageNo, firstIndex, timestamp, location) {
|
|
|
1211
1211
|
location,
|
|
1212
1212
|
];
|
|
1213
1213
|
}
|
|
1214
|
-
function PartitionedMessage(partNo, partTotal) {
|
|
1215
|
-
return [
|
|
1216
|
-
82 /* Messages.Type.PartitionedMessage */,
|
|
1217
|
-
partNo,
|
|
1218
|
-
partTotal,
|
|
1219
|
-
];
|
|
1220
|
-
}
|
|
1221
1214
|
function NetworkRequest(type, method, url, request, response, status, timestamp, duration, transferredBodySize) {
|
|
1222
1215
|
return [
|
|
1223
1216
|
83 /* Messages.Type.NetworkRequest */,
|
|
@@ -1429,7 +1422,6 @@ var _Messages = /*#__PURE__*/Object.freeze({
|
|
|
1429
1422
|
OTable: OTable,
|
|
1430
1423
|
PageLoadTiming: PageLoadTiming,
|
|
1431
1424
|
PageRenderTiming: PageRenderTiming,
|
|
1432
|
-
PartitionedMessage: PartitionedMessage,
|
|
1433
1425
|
PerformanceTrack: PerformanceTrack,
|
|
1434
1426
|
Profiler: Profiler,
|
|
1435
1427
|
Redux: Redux,
|
|
@@ -1524,11 +1516,157 @@ function Performance (app, opts) {
|
|
|
1524
1516
|
}
|
|
1525
1517
|
}
|
|
1526
1518
|
|
|
1519
|
+
/**
|
|
1520
|
+
* Two-tier tag matching:
|
|
1521
|
+
* 1. Fast fingerprint lookup by id, data-attr,
|
|
1522
|
+
* or class from the selector's last segment
|
|
1523
|
+
* 2. Fallback iteration using native element.matches()
|
|
1524
|
+
*/
|
|
1525
|
+
class TagMatcher {
|
|
1526
|
+
constructor() {
|
|
1527
|
+
this.tags = [];
|
|
1528
|
+
this.byId = new Map();
|
|
1529
|
+
this.byDataAttr = new Map();
|
|
1530
|
+
this.byClass = new Map();
|
|
1531
|
+
this.fallback = [];
|
|
1532
|
+
}
|
|
1533
|
+
setTags(tags) {
|
|
1534
|
+
this.tags = tags;
|
|
1535
|
+
this.byId.clear();
|
|
1536
|
+
this.byDataAttr.clear();
|
|
1537
|
+
this.byClass.clear();
|
|
1538
|
+
this.fallback = [];
|
|
1539
|
+
for (const tag of tags) {
|
|
1540
|
+
const last = lastSegment(tag.selector);
|
|
1541
|
+
if (!last) {
|
|
1542
|
+
this.fallback.push(tag);
|
|
1543
|
+
continue;
|
|
1544
|
+
}
|
|
1545
|
+
if (last.startsWith('#')) {
|
|
1546
|
+
this.byId.set(last.slice(1), tag);
|
|
1547
|
+
}
|
|
1548
|
+
else if (last.startsWith('[data-')) {
|
|
1549
|
+
this.byDataAttr.set(last, tag);
|
|
1550
|
+
}
|
|
1551
|
+
else {
|
|
1552
|
+
const cls = extractClass(last);
|
|
1553
|
+
if (cls) {
|
|
1554
|
+
this.byClass.set(cls, tag);
|
|
1555
|
+
}
|
|
1556
|
+
else {
|
|
1557
|
+
this.fallback.push(tag);
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
getTags() {
|
|
1563
|
+
return this.tags;
|
|
1564
|
+
}
|
|
1565
|
+
/** Match element, its parent, or direct children against known tag selectors */
|
|
1566
|
+
match(el) {
|
|
1567
|
+
const direct = this.matchExact(el);
|
|
1568
|
+
if (direct)
|
|
1569
|
+
return direct;
|
|
1570
|
+
if (el.parentElement) {
|
|
1571
|
+
const parent = this.matchExact(el.parentElement);
|
|
1572
|
+
if (parent)
|
|
1573
|
+
return parent;
|
|
1574
|
+
}
|
|
1575
|
+
const children = el.children;
|
|
1576
|
+
for (let i = 0; i < children.length; i++) {
|
|
1577
|
+
const child = this.matchExact(children[i]);
|
|
1578
|
+
if (child)
|
|
1579
|
+
return child;
|
|
1580
|
+
}
|
|
1581
|
+
return null;
|
|
1582
|
+
}
|
|
1583
|
+
matchExact(el) {
|
|
1584
|
+
if (el.id && this.byId.has(el.id)) {
|
|
1585
|
+
const tag = this.byId.get(el.id);
|
|
1586
|
+
if (safeMatches(el, tag.selector) && matchesLocation(tag))
|
|
1587
|
+
return tag;
|
|
1588
|
+
}
|
|
1589
|
+
if (this.byDataAttr.size > 0) {
|
|
1590
|
+
const attrs = el.attributes;
|
|
1591
|
+
for (let i = 0; i < attrs.length; i++) {
|
|
1592
|
+
const attr = attrs[i];
|
|
1593
|
+
if (attr.name.startsWith('data-')) {
|
|
1594
|
+
const key = `[${attr.name}="${attr.value}"]`;
|
|
1595
|
+
if (this.byDataAttr.has(key)) {
|
|
1596
|
+
const tag = this.byDataAttr.get(key);
|
|
1597
|
+
if (safeMatches(el, tag.selector) && matchesLocation(tag))
|
|
1598
|
+
return tag;
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
if (this.byClass.size > 0 && el.classList) {
|
|
1604
|
+
for (let i = 0; i < el.classList.length; i++) {
|
|
1605
|
+
const cls = el.classList[i];
|
|
1606
|
+
if (this.byClass.has(cls)) {
|
|
1607
|
+
const tag = this.byClass.get(cls);
|
|
1608
|
+
if (safeMatches(el, tag.selector) && matchesLocation(tag))
|
|
1609
|
+
return tag;
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
for (const tag of this.fallback) {
|
|
1614
|
+
if (safeMatches(el, tag.selector) && matchesLocation(tag))
|
|
1615
|
+
return tag;
|
|
1616
|
+
}
|
|
1617
|
+
return null;
|
|
1618
|
+
}
|
|
1619
|
+
clear() {
|
|
1620
|
+
this.tags = [];
|
|
1621
|
+
this.byId.clear();
|
|
1622
|
+
this.byDataAttr.clear();
|
|
1623
|
+
this.byClass.clear();
|
|
1624
|
+
this.fallback = [];
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
/** Last combinator-separated segment of a CSS selector */
|
|
1628
|
+
function lastSegment(selector) {
|
|
1629
|
+
const trimmed = selector.trim();
|
|
1630
|
+
if (!trimmed)
|
|
1631
|
+
return null;
|
|
1632
|
+
const parts = trimmed.split(/\s*[>+~ ]\s*/);
|
|
1633
|
+
const last = parts[parts.length - 1]?.trim();
|
|
1634
|
+
return last || null;
|
|
1635
|
+
}
|
|
1636
|
+
/** First class name from a selector segment, e.g. "div.my-class" -> "my-class" */
|
|
1637
|
+
function extractClass(segment) {
|
|
1638
|
+
const match = segment.match(/\.([a-zA-Z_-][\w-]*)/);
|
|
1639
|
+
return match ? match[1] : null;
|
|
1640
|
+
}
|
|
1641
|
+
function safeMatches(el, selector) {
|
|
1642
|
+
try {
|
|
1643
|
+
return el.matches(selector);
|
|
1644
|
+
}
|
|
1645
|
+
catch {
|
|
1646
|
+
return false;
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
function matchesLocation(tag) {
|
|
1650
|
+
if (!tag.location)
|
|
1651
|
+
return true;
|
|
1652
|
+
try {
|
|
1653
|
+
const loc = tag.location;
|
|
1654
|
+
if (loc.startsWith('/')) {
|
|
1655
|
+
return window.location.pathname === loc;
|
|
1656
|
+
}
|
|
1657
|
+
return window.location.href === loc;
|
|
1658
|
+
}
|
|
1659
|
+
catch {
|
|
1660
|
+
return true;
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1527
1664
|
const WATCHED_TAGS_KEY = '__or__watched_tags__';
|
|
1528
1665
|
class TagWatcher {
|
|
1529
1666
|
constructor(params) {
|
|
1530
1667
|
this.interval = null;
|
|
1531
1668
|
this.tags = [];
|
|
1669
|
+
this.matcher = new TagMatcher();
|
|
1532
1670
|
this.sessionStorage = params.sessionStorage;
|
|
1533
1671
|
this.errLog = params.errLog;
|
|
1534
1672
|
this.onTag = params.onTag;
|
|
@@ -1569,12 +1707,15 @@ class TagWatcher {
|
|
|
1569
1707
|
}
|
|
1570
1708
|
setTags(tags) {
|
|
1571
1709
|
this.tags = tags;
|
|
1710
|
+
this.matcher.setTags(tags);
|
|
1572
1711
|
if (this.interval) {
|
|
1573
1712
|
clearInterval(this.interval);
|
|
1574
1713
|
this.interval = null;
|
|
1575
1714
|
}
|
|
1576
1715
|
this.interval = setInterval(() => {
|
|
1577
1716
|
this.tags.forEach((tag) => {
|
|
1717
|
+
if (!matchesLocation(tag))
|
|
1718
|
+
return;
|
|
1578
1719
|
const possibleEls = document.querySelectorAll(tag.selector);
|
|
1579
1720
|
if (possibleEls.length > 0) {
|
|
1580
1721
|
const el = possibleEls[0];
|
|
@@ -1586,13 +1727,17 @@ class TagWatcher {
|
|
|
1586
1727
|
}, 500);
|
|
1587
1728
|
}
|
|
1588
1729
|
onTagRendered(tagId) {
|
|
1589
|
-
|
|
1590
|
-
|
|
1730
|
+
const tag = this.tags.find(t => t.id === tagId);
|
|
1731
|
+
if (tag) {
|
|
1732
|
+
this.tags = this.tags.filter((t) => t.id !== tagId);
|
|
1733
|
+
if (!matchesLocation(tag))
|
|
1734
|
+
return;
|
|
1591
1735
|
}
|
|
1592
1736
|
this.onTag(tagId);
|
|
1593
1737
|
}
|
|
1594
1738
|
clear() {
|
|
1595
1739
|
this.tags = [];
|
|
1740
|
+
this.matcher.clear();
|
|
1596
1741
|
if (this.interval) {
|
|
1597
1742
|
clearInterval(this.interval);
|
|
1598
1743
|
this.interval = null;
|
|
@@ -3758,7 +3903,7 @@ class Ticker {
|
|
|
3758
3903
|
* this value is injected during build time via rollup
|
|
3759
3904
|
* */
|
|
3760
3905
|
// @ts-ignore
|
|
3761
|
-
const workerBodyFn = "!function(){\"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){var e;const n=null==i?void 0:i.toString().replace(/^([^_]+)_([^_]+).*/,\"$1_$2_$3\");this.busy=!0;const h={Authorization:`Bearer ${this.token}`};s&&(h[\"Content-Encoding\"]=\"gzip\"),null!==this.token?fetch(`${this.ingestURL}?batch=${null!==(e=this.pageNo)&&void 0!==e?e:\"noPageNum\"}_${null!=n?n:\"noBatchNum\"}`,{body:t,method:\"POST\",headers:h,keepalive:t.length<65536}).then((e=>{if(401===e.status)return this.busy=!1,void this.onUnauthorised();e.status>=400?this.retry(t,s,`${null!=i?i:\"noBatchNum\"}_network:${e.status}`):(this.attemptsCount=0,this.sendNext())})).catch((e=>{console.warn(\"OpenReplay:\",e),this.retry(t,s,`${null!=i?i:\"noBatchNum\"}_reject:${e.message}`)})):setTimeout((()=>{this.sendBatch(t,s,`${null!=i?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 65: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 35:case 51:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3]);case 12:case 52:case 61:case 71:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3]);case 13:case 14:case 17:case 34:case 36: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 43:case 63:case 64:case 79:case 124: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 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 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 73:return this.uint(t[1])&&this.string(t[2])&&this.uint(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 85: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])&&this.uint(t[11])&&this.uint(t[12])&&this.uint(t[13])&&this.uint(t[14])&&this.uint(t[15])&&this.uint(t[16])&&this.uint(t[17]);case 87:return this.string(t[1])&&this.int(t[2])&&this.int(t[3]);case 89:return this.string(t[1])&&this.int(t[2])&&this.int(t[3])&&this.int(t[4])&&this.int(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.checkpoints=[],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;this.checkpoints.length=0;const t=[81,1,this.pageNo,this.nextIndex,this.timestamp,this.url],s=[0,this.timestamp],i=[118,this.tabId];this.writeType(t),this.writeFields(t),this.writeWithSize(s),this.writeWithSize(i),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.checkpoints.push(s.getCurrentOffset()),this.isEmpty=this.isEmpty&&0===t[0],this.nextIndex++}return e}setBeaconSizeLimit(t){this.beaconSizeLimit=t}writeMessage(t){if(-1===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(t=!1){if(this.isEmpty)return;const s=this.encoder.flush();this.onBatch(s,t),this.prepare()}clean(){this.encoder.reset(),this.checkpoints.length=0}}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,u=null,a=h.NotActive;function o(t){u&&u.finaliseBatch(t)}function c(){return new Promise((t=>{a=h.Stopping,null!==p&&(clearInterval(p),p=null),u&&(u.clean(),u=null),r&&(r.clean(),setTimeout((()=>{r=null}),20)),setTimeout((()=>{a=h.NotActive,t(null)}),100)}))}function g(){[h.Stopped,h.Stopping].includes(a)||(postMessage(\"a_stop\"),c().then((()=>{postMessage(\"a_start\")})))}let l,p=null;self.onmessage=({data:s})=>{if(\"stop\"===s)return o(),void c().then((()=>{a=h.Stopped}));if(\"forceFlushBatch\"!==s)if(\"closing\"!==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?(a=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),u=new n(s.pageNo,s.timestamp,s.url,((t,s)=>{r&&(s?r.sendUncompressed(t):r.push(t))}),s.tabId,(()=>postMessage({type:\"queue_empty\"}))),null===p&&(p=setInterval(o,3e4)),a=h.Active):\"auth\"===s.type?r?u?(r.authorise(s.token),void(s.beaconSizeLimit&&u.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(u){const t=u;s.forEach((s=>{55===s[0]&&(s[1]?l=setTimeout((()=>g()),18e5):clearTimeout(l)),t.writeMessage(s)}))}else postMessage(\"not_init\"),g()}else o(!0);else o()}}();\n";
|
|
3906
|
+
const workerBodyFn = "!function(){\"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,s=\"player\"){if(this.busy||!this.token)this.queue.push({batch:t,dataType:s});else if(this.busy=!0,this.isCompressing&&this.onCompress)this.onCompress(t,s);else{const i=++this.lastBatchNum;this.sendBatch(t,!1,i,s)}}sendNext(){const t=this.queue.shift();if(t)if(this.busy=!0,this.isCompressing&&this.onCompress)this.onCompress(t.batch,t.dataType);else{const s=++this.lastBatchNum;this.sendBatch(t.batch,!1,s,t.dataType)}else this.busy=!1}retry(t,s,i,e=\"player\"){this.attemptsCount>=this.MAX_ATTEMPTS_COUNT?this.onFailure(`Failed to send batch after ${this.attemptsCount} attempts.`):(this.attemptsCount++,setTimeout((()=>this.sendBatch(t,s,i,e)),this.ATTEMPT_TIMEOUT*this.attemptsCount))}sendBatch(t,s,i,e=\"player\"){var n;const h=null==i?void 0:i.toString().replace(/^([^_]+)_([^_]+).*/,\"$1_$2_$3\");this.busy=!0;const r={Authorization:`Bearer ${this.token}`,DataType:e};s&&(r[\"Content-Encoding\"]=\"gzip\"),null!==this.token?fetch(`${this.ingestURL}?batch=${null!==(n=this.pageNo)&&void 0!==n?n:\"noPageNum\"}_${null!=h?h:\"noBatchNum\"}`,{body:t,method:\"POST\",headers:r,keepalive:t.length<65536}).then((n=>{if(401===n.status)return this.busy=!1,void this.onUnauthorised();n.status>=400?this.retry(t,s,`${null!=i?i:\"noBatchNum\"}_network:${n.status}`,e):(this.attemptsCount=0,this.sendNext())})).catch((n=>{console.warn(\"OpenReplay:\",n),this.retry(t,s,`${null!=i?i:\"noBatchNum\"}_reject:${n.message}`,e)})):setTimeout((()=>{this.sendBatch(t,s,`${null!=i?i:\"noBatchNum\"}_newToken`,e)}),500)}sendCompressed(t,s=\"player\"){const i=++this.lastBatchNum;this.sendBatch(t,!0,i,s)}sendUncompressed(t,s=\"player\"){const i=++this.lastBatchNum;this.sendBatch(t,!1,i,s)}clean(){this.sendNext(),setTimeout((()=>{this.token=null,this.queue.length=0}),10)}}const s=new Set([60,61,71,73]),i=new Set([21,22,40,41,44,45,46,47,48,79,83,84,85,87,89,116,120,121,123]),e=new Set([17,23,24,27,28,29,30,42,63,64,78,112,115,124]),n=\"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 h{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 s=n.encode(t),i=s.byteLength;return!(!this.uint(i)||this.offset+i>this.size)&&(this.data.set(s,this.offset),this.offset+=i,!0)}reset(){this.offset=0,this.checkpointOffset=0}flush(){const t=this.data.slice(0,this.checkpointOffset);return this.reset(),t}}class r extends h{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 65:case 70:case 75:case 76:case 77: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 35:case 51:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3]);case 12:case 52:case 61:case 71:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3]);case 13:case 14:case 17:case 34:case 36: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 43:case 63:case 64:case 79:case 124: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 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 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 73:return this.uint(t[1])&&this.string(t[2])&&this.uint(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 85: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])&&this.uint(t[11])&&this.uint(t[12])&&this.uint(t[13])&&this.uint(t[14])&&this.uint(t[15])&&this.uint(t[16])&&this.uint(t[17]);case 87:return this.string(t[1])&&this.int(t[2])&&this.int(t[3]);case 89:return this.string(t[1])&&this.int(t[2])&&this.int(t[3])&&this.int(t[4])&&this.int(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 a{constructor(t,s,i,e,n,h,a=!1,o){this.pageNo=t,this.timestamp=s,this.url=i,this.onBatch=e,this.tabId=n,this.onOfflineEnd=h,this.localDebug=a,this.onLocalSave=o,this.nextIndex=0,this.beaconSize=2e5,this.encoder=new r(this.beaconSize),this.sizeBuffer=new Uint8Array(3),this.isEmpty=!0,this.prepared=!1,this.checkpoints=[],this.assetMessages=[],this.devtoolsMessages=[],this.analyticsMessages=[],this.firstAssetIndex=0,this.firstAssetTimestamp=0,this.firstDevtoolsIndex=0,this.firstDevtoolsTimestamp=0,this.firstAnalyticsIndex=0,this.firstAnalyticsTimestamp=0,this.protocolVersion=1,this.beaconSizeLimit=1e6}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.prepared)return;this.prepared=!0,this.checkpoints.length=0;const t=[81,2===this.protocolVersion?2:1,this.pageNo,this.nextIndex,this.timestamp,this.url];this.writeType(t),this.writeFields(t),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.checkpoints.push(s.getCurrentOffset()),this.isEmpty=this.isEmpty&&0===t[0],this.nextIndex++}return e}setBeaconSizeLimit(t){this.beaconSizeLimit=t}setProtocolVersion(t){this.protocolVersion=t}writeMessage(t){if(-1===t[0])return this.finaliseBatch(),this.onOfflineEnd();if(0===t[0]&&(this.timestamp=t[1]),122===t[0]&&(this.url=t[1]),2===this.protocolVersion){if(s.has(t[0]))return 0===this.assetMessages.length&&(this.firstAssetIndex=this.nextIndex,this.firstAssetTimestamp=this.timestamp),this.assetMessages.push(t),void this.nextIndex++;if(i.has(t[0]))return 0===this.devtoolsMessages.length&&(this.firstDevtoolsIndex=this.nextIndex,this.firstDevtoolsTimestamp=this.timestamp),this.devtoolsMessages.push(t),void this.nextIndex++;if(e.has(t[0]))return 0===this.analyticsMessages.length&&(this.firstAnalyticsIndex=this.nextIndex,this.firstAnalyticsTimestamp=this.timestamp),this.analyticsMessages.push(t),void this.nextIndex++}this.prepare(),this.writeWithSize(t)||(this.finaliseBatch(),this.prepare(),this.writeWithSize(t)||(this.encoder=new r(this.beaconSizeLimit),this.prepare(),this.writeWithSize(t)?this.finaliseBatch():console.warn(\"OpenReplay: beacon size overflow. Skipping large message.\",t,this),this.encoder=new r(this.beaconSize)))}finaliseBatch(t=!1){const s=this.prepared&&!this.isEmpty,i=this.assetMessages.length>0,e=this.devtoolsMessages.length>0,n=this.analyticsMessages.length>0;if(!(s||i||e||n))return;const h=this.url;if(s){const s=this.encoder.flush();this.localDebug&&this.onLocalSave&&this.onLocalSave(`${Date.now()}-mob`,s.slice()),this.onBatch(s,t,\"player\")}else this.encoder.reset();if(i){const s=this.buildSeparateBatch(3,this.firstAssetIndex,this.firstAssetTimestamp,h,this.assetMessages);this.localDebug&&this.onLocalSave&&this.onLocalSave(`assets-${Date.now()}`,s.slice()),this.onBatch(s,t,\"assets\"),this.assetMessages.length=0}if(e){const s=this.buildSeparateBatch(4,this.firstDevtoolsIndex,this.firstDevtoolsTimestamp,h,this.devtoolsMessages);this.localDebug&&this.onLocalSave&&this.onLocalSave(`devtools-${Date.now()}`,s.slice()),this.onBatch(s,t,\"devtools\"),this.devtoolsMessages.length=0}if(n){const s=this.buildSeparateBatch(5,this.firstAnalyticsIndex,this.firstAnalyticsTimestamp,h,this.analyticsMessages);this.localDebug&&this.onLocalSave&&this.onLocalSave(`analytics-${Date.now()}`,s.slice()),this.onBatch(s,t,\"analytics\"),this.analyticsMessages.length=0}this.prepared=!1}buildSeparateBatch(t,s,i,e,n){const h=new r(this.beaconSizeLimit),a=new Uint8Array(3),o=t=>{h.uint(t[0]),h.skip(3);const s=h.getCurrentOffset();h.encode(t);const i=h.getCurrentOffset()-s;for(let t=0;t<3;t++)a[t]=i>>8*t;h.set(a,s-3),h.checkpoint()},c=[81,t,this.pageNo,s,i,e];h.uint(c[0]),h.encode(c),o([0,i]),o([118,this.tabId]);for(const t of n)o(t);return h.flush()}clean(){this.encoder.reset(),this.checkpoints.length=0,this.assetMessages.length=0,this.devtoolsMessages.length=0,this.analyticsMessages.length=0,this.prepared=!1}}var o;!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\"}(o||(o={}));let c=null,u=null,l=o.NotActive;function p(t){u&&u.finaliseBatch(t)}function g(){return new Promise((t=>{l=o.Stopping,null!==m&&(clearInterval(m),m=null),u&&(u.clean(),u=null),c&&(c.clean(),setTimeout((()=>{c=null}),20)),setTimeout((()=>{l=o.NotActive,t(null)}),100)}))}function f(){[o.Stopped,o.Stopping].includes(l)||(postMessage(\"a_stop\"),g().then((()=>{postMessage(\"a_start\")})))}let d,m=null;self.onmessage=({data:s})=>{var i;if(\"stop\"===s)return p(),void g().then((()=>{l=o.Stopped}));if(\"forceFlushBatch\"!==s)if(\"closing\"!==s){if(!Array.isArray(s)){if(\"compressed\"===s.type){if(!c)return console.debug(\"OR WebWorker: sender not initialised. Compressed batch.\"),void f();s.batch&&c.sendCompressed(s.batch,s.dataType)}if(\"uncompressed\"===s.type){if(!c)return console.debug(\"OR WebWorker: sender not initialised. Uncompressed batch.\"),void f();s.batch&&c.sendUncompressed(s.batch,s.dataType)}return\"start\"===s.type?(l=o.Starting,c=new t(s.ingestPoint,(()=>{f()}),(t=>{!function(t){postMessage({type:\"failure\",reason:t}),g()}(t)}),s.connAttemptCount,s.connAttemptGap,((t,s)=>{postMessage({type:\"compress\",batch:t,dataType:s},[t.buffer])}),s.pageNo),u=new a(s.pageNo,s.timestamp,s.url,((t,s,i=\"player\")=>{if(!c)return;const e=function(t){const s=[];let i=0;const e=()=>{let s=0,e=0;for(;i<t.length;){const n=t[i++];if(s|=(127&n)<<e,!(128&n))return s;e+=7}return null},n=()=>{if(i+3>t.length)return null;const s=t[i]|t[i+1]<<8|t[i+2]<<16;return i+=3,s},h=new Set([80,81,82]);for(;i<t.length;){const t=e();if(null===t)break;if(s.push(t),h.has(t)){if(81===t){e(),e(),e(),e();const t=e();null!==t&&(i+=t)}else 82===t&&(e(),e());continue}const r=n();if(null===r)break;i+=r}return s}(t);console.debug(`[OR batch] dataType=${i} msgs=${e.length} types=`,e),s?c.sendUncompressed(t,i):c.push(t,i)}),s.tabId,(()=>postMessage({type:\"queue_empty\"})),null!==(i=s.localDebug)&&void 0!==i&&i,((t,s)=>{postMessage({type:\"local_save\",name:t,batch:s},[s.buffer])})),null===m&&(m=setInterval(p,3e4)),l=o.Active):\"auth\"===s.type?c?u?(c.authorise(s.token),s.beaconSizeLimit&&u.setBeaconSizeLimit(s.beaconSizeLimit),void(s.protocolVersion&&u.setProtocolVersion(s.protocolVersion))):(console.debug(\"OR WebWorker: writer not initialised. Received auth.\"),void f()):(console.debug(\"OR WebWorker: sender not initialised. Received auth.\"),void f()):void 0}if(u){const t=u;s.forEach((s=>{55===s[0]&&(s[1]?d=setTimeout((()=>f()),18e5):clearTimeout(d)),t.writeMessage(s)}))}else postMessage(\"not_init\"),f()}else p(!0);else p()}}();\n";
|
|
3762
3907
|
const CANCELED = 'canceled';
|
|
3763
3908
|
const bufferStorageKey = 'or_buffer_1';
|
|
3764
3909
|
const UnsuccessfulStart = (reason) => ({ reason, success: false });
|
|
@@ -3800,6 +3945,9 @@ const proto = {
|
|
|
3800
3945
|
reset: 'reset-your-session-please',
|
|
3801
3946
|
};
|
|
3802
3947
|
class App {
|
|
3948
|
+
get tagMatcher() {
|
|
3949
|
+
return this.tagWatcher.matcher;
|
|
3950
|
+
}
|
|
3803
3951
|
constructor(projectKey, sessionToken, options, signalError, insideIframe) {
|
|
3804
3952
|
this.signalError = signalError;
|
|
3805
3953
|
this.insideIframe = insideIframe;
|
|
@@ -3814,7 +3962,7 @@ class App {
|
|
|
3814
3962
|
this.stopCallbacks = [];
|
|
3815
3963
|
this.commitCallbacks = [];
|
|
3816
3964
|
this.activityState = ActivityState.NotActive;
|
|
3817
|
-
this.version = '
|
|
3965
|
+
this.version = '18.0.0'; // TODO: version compatability check inside each plugin.
|
|
3818
3966
|
this.socketMode = false;
|
|
3819
3967
|
this.compressionThreshold = 24 * 1000;
|
|
3820
3968
|
this.bc = null;
|
|
@@ -3839,6 +3987,9 @@ class App {
|
|
|
3839
3987
|
if (this.active())
|
|
3840
3988
|
return;
|
|
3841
3989
|
try {
|
|
3990
|
+
if (data.token) {
|
|
3991
|
+
this.session.setSessionToken(data.token, this.projectKey);
|
|
3992
|
+
}
|
|
3842
3993
|
this.allowAppStart();
|
|
3843
3994
|
void this.start();
|
|
3844
3995
|
}
|
|
@@ -3979,8 +4130,12 @@ class App {
|
|
|
3979
4130
|
}
|
|
3980
4131
|
if (this.pollingQueue[nextCommand].includes(data.context)) {
|
|
3981
4132
|
this.pollingQueue[nextCommand] = this.pollingQueue[nextCommand].filter((c) => c !== data.context);
|
|
4133
|
+
const message = { line: nextCommand };
|
|
4134
|
+
if (nextCommand === proto.startIframe) {
|
|
4135
|
+
message.token = this.session.getSessionToken(this.projectKey);
|
|
4136
|
+
}
|
|
3982
4137
|
// @ts-ignore
|
|
3983
|
-
event.source?.postMessage(
|
|
4138
|
+
event.source?.postMessage(message, '*');
|
|
3984
4139
|
if (this.pollingQueue[nextCommand].length === 0) {
|
|
3985
4140
|
this.pollingQueue.order.shift();
|
|
3986
4141
|
}
|
|
@@ -4164,6 +4319,7 @@ class App {
|
|
|
4164
4319
|
__is_snippet: false,
|
|
4165
4320
|
__debug_report_edp: null,
|
|
4166
4321
|
__debug__: LogLevel.Silent,
|
|
4322
|
+
__local_debug: false,
|
|
4167
4323
|
localStorage: null,
|
|
4168
4324
|
sessionStorage: null,
|
|
4169
4325
|
forceSingleTab: false,
|
|
@@ -4405,6 +4561,7 @@ class App {
|
|
|
4405
4561
|
}
|
|
4406
4562
|
else if (data.type === 'compress') {
|
|
4407
4563
|
const batch = data.batch;
|
|
4564
|
+
const dataType = data.dataType;
|
|
4408
4565
|
const batchSize = batch.byteLength;
|
|
4409
4566
|
const hasCompressionAPI = 'CompressionStream' in globalThis;
|
|
4410
4567
|
if (batchSize > this.compressionThreshold && hasCompressionAPI) {
|
|
@@ -4416,17 +4573,27 @@ class App {
|
|
|
4416
4573
|
this.worker?.postMessage({
|
|
4417
4574
|
type: 'compressed',
|
|
4418
4575
|
batch: new Uint8Array(compressedBuffer),
|
|
4576
|
+
dataType,
|
|
4419
4577
|
});
|
|
4420
4578
|
})
|
|
4421
4579
|
.catch((err) => {
|
|
4422
4580
|
this.debug.error('Openreplay compression error:', err);
|
|
4423
|
-
this.worker?.postMessage({ type: 'uncompressed', batch: batch });
|
|
4581
|
+
this.worker?.postMessage({ type: 'uncompressed', batch: batch, dataType });
|
|
4424
4582
|
});
|
|
4425
4583
|
}
|
|
4426
4584
|
else {
|
|
4427
|
-
this.worker?.postMessage({ type: 'uncompressed', batch: batch });
|
|
4585
|
+
this.worker?.postMessage({ type: 'uncompressed', batch: batch, dataType });
|
|
4428
4586
|
}
|
|
4429
4587
|
}
|
|
4588
|
+
else if (data.type === 'local_save') {
|
|
4589
|
+
const blob = new Blob([data.batch], { type: 'application/octet-stream' });
|
|
4590
|
+
const url = URL.createObjectURL(blob);
|
|
4591
|
+
const a = document.createElement('a');
|
|
4592
|
+
a.href = url;
|
|
4593
|
+
a.download = data.name;
|
|
4594
|
+
a.click();
|
|
4595
|
+
URL.revokeObjectURL(url);
|
|
4596
|
+
}
|
|
4430
4597
|
else if (data.type === 'queue_empty') {
|
|
4431
4598
|
this.onSessionSent();
|
|
4432
4599
|
}
|
|
@@ -4465,19 +4632,31 @@ class App {
|
|
|
4465
4632
|
this.messages.length = 0;
|
|
4466
4633
|
return;
|
|
4467
4634
|
}
|
|
4468
|
-
if (this.worker === undefined
|
|
4635
|
+
if (this.worker === undefined) {
|
|
4469
4636
|
return;
|
|
4470
4637
|
}
|
|
4471
4638
|
if (!this.messages.length) {
|
|
4472
|
-
//
|
|
4639
|
+
// Send a keepalive batch every ~30s (1000 * 30ms) to keep the session active
|
|
4473
4640
|
if (this.emptyBatchCounter < 1000) {
|
|
4474
4641
|
this.emptyBatchCounter++;
|
|
4475
4642
|
return;
|
|
4476
4643
|
}
|
|
4644
|
+
// Keepalive: send just Timestamp + TabData so the session stays alive
|
|
4645
|
+
this.emptyBatchCounter = 0;
|
|
4646
|
+
try {
|
|
4647
|
+
this.worker?.postMessage([Timestamp(this.timestamp()), TabData(this.session.getTabId())]);
|
|
4648
|
+
}
|
|
4649
|
+
catch (e) {
|
|
4650
|
+
this._debug('worker_keepalive', e);
|
|
4651
|
+
}
|
|
4652
|
+
return;
|
|
4477
4653
|
}
|
|
4478
4654
|
this.emptyBatchCounter = 0;
|
|
4479
4655
|
try {
|
|
4480
4656
|
requestIdleCb(() => {
|
|
4657
|
+
if (!this.messages.length) {
|
|
4658
|
+
return;
|
|
4659
|
+
}
|
|
4481
4660
|
this.messages.unshift(Timestamp(this.timestamp()), TabData(this.session.getTabId()));
|
|
4482
4661
|
this.worker?.postMessage(this.messages);
|
|
4483
4662
|
this.commitCallbacks.forEach((cb) => cb(this.messages));
|
|
@@ -4633,9 +4812,15 @@ class App {
|
|
|
4633
4812
|
}
|
|
4634
4813
|
}
|
|
4635
4814
|
checkSessionToken(forceNew) {
|
|
4636
|
-
const
|
|
4637
|
-
const
|
|
4815
|
+
const PROTO_VERSION = "2";
|
|
4816
|
+
const needReset = this.sessionStorage.getItem(this.options.session_reset_key) !== null;
|
|
4817
|
+
let needNewSessionID = forceNew || needReset;
|
|
4638
4818
|
const sessionToken = this.session.getSessionToken(this.projectKey);
|
|
4819
|
+
if (sessionToken) {
|
|
4820
|
+
const storedVersion = this.sessionStorage.getItem(`${this.options.session_token_key}_version`);
|
|
4821
|
+
needNewSessionID = !storedVersion || storedVersion !== PROTO_VERSION;
|
|
4822
|
+
this.sessionStorage.setItem(`${this.options.session_token_key}_version`, PROTO_VERSION);
|
|
4823
|
+
}
|
|
4639
4824
|
return needNewSessionID || !sessionToken;
|
|
4640
4825
|
}
|
|
4641
4826
|
/**
|
|
@@ -4813,6 +4998,7 @@ class App {
|
|
|
4813
4998
|
connAttemptCount: this.options.connAttemptCount,
|
|
4814
4999
|
connAttemptGap: this.options.connAttemptGap,
|
|
4815
5000
|
tabId: this.session.getTabId(),
|
|
5001
|
+
localDebug: this.options.__local_debug,
|
|
4816
5002
|
});
|
|
4817
5003
|
const r = await fetch(this.options.ingestPoint + '/v1/web/start', {
|
|
4818
5004
|
method: 'POST',
|
|
@@ -4831,11 +5017,12 @@ class App {
|
|
|
4831
5017
|
timezone: getTimezone(),
|
|
4832
5018
|
}),
|
|
4833
5019
|
});
|
|
4834
|
-
const { token, userBrowser, userCity, userCountry, userDevice, userOS, userState, beaconSizeLimit, projectID, } = await r.json();
|
|
5020
|
+
const { token, userBrowser, userCity, userCountry, userDevice, userOS, userState, beaconSizeLimit, projectID, protocolVersion: offlineProtocolVersion, } = await r.json();
|
|
4835
5021
|
this.worker?.postMessage({
|
|
4836
5022
|
type: 'auth',
|
|
4837
5023
|
token,
|
|
4838
5024
|
beaconSizeLimit,
|
|
5025
|
+
protocolVersion: offlineProtocolVersion,
|
|
4839
5026
|
});
|
|
4840
5027
|
this.session.assign({ projectID });
|
|
4841
5028
|
this.session.setUserInfo({
|
|
@@ -4897,6 +5084,7 @@ class App {
|
|
|
4897
5084
|
connAttemptCount: this.options.connAttemptCount,
|
|
4898
5085
|
connAttemptGap: this.options.connAttemptGap,
|
|
4899
5086
|
tabId: this.session.getTabId(),
|
|
5087
|
+
localDebug: this.options.__local_debug,
|
|
4900
5088
|
});
|
|
4901
5089
|
const sessionToken = this.session.getSessionToken(this.projectKey);
|
|
4902
5090
|
const isNewSession = this.checkSessionToken(startOpts.forceNew);
|
|
@@ -4939,7 +5127,7 @@ class App {
|
|
|
4939
5127
|
delay, // derived from token
|
|
4940
5128
|
sessionID, // derived from token
|
|
4941
5129
|
startTimestamp, // real startTS (server time), derived from sessionID
|
|
4942
|
-
userBrowser, userCity, userCountry, userDevice, userOS, userState, canvasEnabled, canvasQuality, canvasFPS, framesSupport, assistOnly: socketOnly, } = await r.json();
|
|
5130
|
+
userBrowser, userCity, userCountry, userDevice, userOS, userState, canvasEnabled, canvasQuality, canvasFPS, framesSupport, assistOnly: socketOnly, protocolVersion, } = await r.json();
|
|
4943
5131
|
if (typeof token !== 'string' ||
|
|
4944
5132
|
typeof userUUID !== 'string' ||
|
|
4945
5133
|
(typeof startTimestamp !== 'number' && typeof startTimestamp !== 'undefined') ||
|
|
@@ -4980,6 +5168,7 @@ class App {
|
|
|
4980
5168
|
type: 'auth',
|
|
4981
5169
|
token,
|
|
4982
5170
|
beaconSizeLimit,
|
|
5171
|
+
protocolVersion,
|
|
4983
5172
|
});
|
|
4984
5173
|
}
|
|
4985
5174
|
if (!isNewSession && token === sessionToken) {
|
|
@@ -5741,6 +5930,18 @@ function Input (app, opts) {
|
|
|
5741
5930
|
defaultInputMode: InputMode.Obscured,
|
|
5742
5931
|
obscureInputDates: false,
|
|
5743
5932
|
}, opts);
|
|
5933
|
+
const tagSelectorMap = new Map();
|
|
5934
|
+
function getTagSelector(id, node) {
|
|
5935
|
+
const cached = tagSelectorMap.get(id);
|
|
5936
|
+
if (cached !== undefined)
|
|
5937
|
+
return cached;
|
|
5938
|
+
const tagMatch = app.tagMatcher.match(node);
|
|
5939
|
+
if (tagMatch) {
|
|
5940
|
+
tagSelectorMap.set(id, tagMatch.selector);
|
|
5941
|
+
return tagMatch.selector;
|
|
5942
|
+
}
|
|
5943
|
+
return null;
|
|
5944
|
+
}
|
|
5744
5945
|
function getInputValue(id, node) {
|
|
5745
5946
|
let value = node.value;
|
|
5746
5947
|
let inputMode = options.defaultInputMode;
|
|
@@ -5776,6 +5977,7 @@ function Input (app, opts) {
|
|
|
5776
5977
|
app.attachStopCallback(() => {
|
|
5777
5978
|
inputValues.clear();
|
|
5778
5979
|
checkboxValues.clear();
|
|
5980
|
+
tagSelectorMap.clear();
|
|
5779
5981
|
});
|
|
5780
5982
|
function trackInputValue(id, node) {
|
|
5781
5983
|
if (inputValues.get(id) === node.value) {
|
|
@@ -5808,7 +6010,7 @@ function Input (app, opts) {
|
|
|
5808
6010
|
}, 3);
|
|
5809
6011
|
function sendInputChange(id, node, hesitationTime, inputTime) {
|
|
5810
6012
|
const { value, mask } = getInputValue(id, node);
|
|
5811
|
-
let label = getInputLabel(node, options.customAttributes);
|
|
6013
|
+
let label = getTagSelector(id, node) || getInputLabel(node, options.customAttributes);
|
|
5812
6014
|
if (app.sanitizer.privateMode) {
|
|
5813
6015
|
label = label.replaceAll(/./g, '*');
|
|
5814
6016
|
}
|
|
@@ -5991,7 +6193,13 @@ function Mouse (app, options) {
|
|
|
5991
6193
|
};
|
|
5992
6194
|
const patchDocument = (document, topframe = false) => {
|
|
5993
6195
|
function getSelector(id, target) {
|
|
5994
|
-
|
|
6196
|
+
if (selectorMap[id])
|
|
6197
|
+
return selectorMap[id];
|
|
6198
|
+
const tagMatch = app.tagMatcher.match(target);
|
|
6199
|
+
if (tagMatch) {
|
|
6200
|
+
return (selectorMap[id] = tagMatch.selector);
|
|
6201
|
+
}
|
|
6202
|
+
return (selectorMap[id] = _getSelector(target));
|
|
5995
6203
|
}
|
|
5996
6204
|
const attachListener = topframe
|
|
5997
6205
|
? app.attachEventListener.bind(app) // attached/removed on start/stop
|
|
@@ -8669,7 +8877,7 @@ class ConstantProperties {
|
|
|
8669
8877
|
user_id: this.user_id,
|
|
8670
8878
|
distinct_id: this.deviceId,
|
|
8671
8879
|
sdk_edition: 'web',
|
|
8672
|
-
sdk_version: '
|
|
8880
|
+
sdk_version: '18.0.0',
|
|
8673
8881
|
timezone: getUTCOffsetString(),
|
|
8674
8882
|
search_engine: this.searchEngine,
|
|
8675
8883
|
};
|
|
@@ -9371,7 +9579,7 @@ class API {
|
|
|
9371
9579
|
this.signalStartIssue = (reason, missingApi) => {
|
|
9372
9580
|
const doNotTrack = this.checkDoNotTrack();
|
|
9373
9581
|
console.log("Tracker couldn't start due to:", JSON.stringify({
|
|
9374
|
-
trackerVersion: '
|
|
9582
|
+
trackerVersion: '18.0.0',
|
|
9375
9583
|
projectKey: this.options.projectKey,
|
|
9376
9584
|
doNotTrack,
|
|
9377
9585
|
reason: missingApi.length ? `missing api: ${missingApi.join(',')}` : reason,
|