@openreplay/tracker 17.2.6 → 17.2.9

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/lib/entry.js CHANGED
@@ -1207,13 +1207,6 @@ function BatchMetadata(version, pageNo, firstIndex, timestamp, location) {
1207
1207
  location,
1208
1208
  ];
1209
1209
  }
1210
- function PartitionedMessage(partNo, partTotal) {
1211
- return [
1212
- 82 /* Messages.Type.PartitionedMessage */,
1213
- partNo,
1214
- partTotal,
1215
- ];
1216
- }
1217
1210
  function NetworkRequest(type, method, url, request, response, status, timestamp, duration, transferredBodySize) {
1218
1211
  return [
1219
1212
  83 /* Messages.Type.NetworkRequest */,
@@ -1425,7 +1418,6 @@ var _Messages = /*#__PURE__*/Object.freeze({
1425
1418
  OTable: OTable,
1426
1419
  PageLoadTiming: PageLoadTiming,
1427
1420
  PageRenderTiming: PageRenderTiming,
1428
- PartitionedMessage: PartitionedMessage,
1429
1421
  PerformanceTrack: PerformanceTrack,
1430
1422
  Profiler: Profiler,
1431
1423
  Redux: Redux,
@@ -1520,11 +1512,157 @@ function Performance (app, opts) {
1520
1512
  }
1521
1513
  }
1522
1514
 
1515
+ /**
1516
+ * Two-tier tag matching:
1517
+ * 1. Fast fingerprint lookup by id, data-attr,
1518
+ * or class from the selector's last segment
1519
+ * 2. Fallback iteration using native element.matches()
1520
+ */
1521
+ class TagMatcher {
1522
+ constructor() {
1523
+ this.tags = [];
1524
+ this.byId = new Map();
1525
+ this.byDataAttr = new Map();
1526
+ this.byClass = new Map();
1527
+ this.fallback = [];
1528
+ }
1529
+ setTags(tags) {
1530
+ this.tags = tags;
1531
+ this.byId.clear();
1532
+ this.byDataAttr.clear();
1533
+ this.byClass.clear();
1534
+ this.fallback = [];
1535
+ for (const tag of tags) {
1536
+ const last = lastSegment(tag.selector);
1537
+ if (!last) {
1538
+ this.fallback.push(tag);
1539
+ continue;
1540
+ }
1541
+ if (last.startsWith('#')) {
1542
+ this.byId.set(last.slice(1), tag);
1543
+ }
1544
+ else if (last.startsWith('[data-')) {
1545
+ this.byDataAttr.set(last, tag);
1546
+ }
1547
+ else {
1548
+ const cls = extractClass(last);
1549
+ if (cls) {
1550
+ this.byClass.set(cls, tag);
1551
+ }
1552
+ else {
1553
+ this.fallback.push(tag);
1554
+ }
1555
+ }
1556
+ }
1557
+ }
1558
+ getTags() {
1559
+ return this.tags;
1560
+ }
1561
+ /** Match element, its parent, or direct children against known tag selectors */
1562
+ match(el) {
1563
+ const direct = this.matchExact(el);
1564
+ if (direct)
1565
+ return direct;
1566
+ if (el.parentElement) {
1567
+ const parent = this.matchExact(el.parentElement);
1568
+ if (parent)
1569
+ return parent;
1570
+ }
1571
+ const children = el.children;
1572
+ for (let i = 0; i < children.length; i++) {
1573
+ const child = this.matchExact(children[i]);
1574
+ if (child)
1575
+ return child;
1576
+ }
1577
+ return null;
1578
+ }
1579
+ matchExact(el) {
1580
+ if (el.id && this.byId.has(el.id)) {
1581
+ const tag = this.byId.get(el.id);
1582
+ if (safeMatches(el, tag.selector) && matchesLocation(tag))
1583
+ return tag;
1584
+ }
1585
+ if (this.byDataAttr.size > 0) {
1586
+ const attrs = el.attributes;
1587
+ for (let i = 0; i < attrs.length; i++) {
1588
+ const attr = attrs[i];
1589
+ if (attr.name.startsWith('data-')) {
1590
+ const key = `[${attr.name}="${attr.value}"]`;
1591
+ if (this.byDataAttr.has(key)) {
1592
+ const tag = this.byDataAttr.get(key);
1593
+ if (safeMatches(el, tag.selector) && matchesLocation(tag))
1594
+ return tag;
1595
+ }
1596
+ }
1597
+ }
1598
+ }
1599
+ if (this.byClass.size > 0 && el.classList) {
1600
+ for (let i = 0; i < el.classList.length; i++) {
1601
+ const cls = el.classList[i];
1602
+ if (this.byClass.has(cls)) {
1603
+ const tag = this.byClass.get(cls);
1604
+ if (safeMatches(el, tag.selector) && matchesLocation(tag))
1605
+ return tag;
1606
+ }
1607
+ }
1608
+ }
1609
+ for (const tag of this.fallback) {
1610
+ if (safeMatches(el, tag.selector) && matchesLocation(tag))
1611
+ return tag;
1612
+ }
1613
+ return null;
1614
+ }
1615
+ clear() {
1616
+ this.tags = [];
1617
+ this.byId.clear();
1618
+ this.byDataAttr.clear();
1619
+ this.byClass.clear();
1620
+ this.fallback = [];
1621
+ }
1622
+ }
1623
+ /** Last combinator-separated segment of a CSS selector */
1624
+ function lastSegment(selector) {
1625
+ const trimmed = selector.trim();
1626
+ if (!trimmed)
1627
+ return null;
1628
+ const parts = trimmed.split(/\s*[>+~ ]\s*/);
1629
+ const last = parts[parts.length - 1]?.trim();
1630
+ return last || null;
1631
+ }
1632
+ /** First class name from a selector segment, e.g. "div.my-class" -> "my-class" */
1633
+ function extractClass(segment) {
1634
+ const match = segment.match(/\.([a-zA-Z_-][\w-]*)/);
1635
+ return match ? match[1] : null;
1636
+ }
1637
+ function safeMatches(el, selector) {
1638
+ try {
1639
+ return el.matches(selector);
1640
+ }
1641
+ catch {
1642
+ return false;
1643
+ }
1644
+ }
1645
+ function matchesLocation(tag) {
1646
+ if (!tag.location)
1647
+ return true;
1648
+ try {
1649
+ const loc = tag.location;
1650
+ if (loc.startsWith('/')) {
1651
+ return window.location.pathname === loc;
1652
+ }
1653
+ return window.location.href === loc;
1654
+ }
1655
+ catch {
1656
+ return true;
1657
+ }
1658
+ }
1659
+
1523
1660
  const WATCHED_TAGS_KEY = '__or__watched_tags__';
1524
1661
  class TagWatcher {
1525
1662
  constructor(params) {
1526
1663
  this.interval = null;
1527
1664
  this.tags = [];
1665
+ this.matcher = new TagMatcher();
1528
1666
  this.sessionStorage = params.sessionStorage;
1529
1667
  this.errLog = params.errLog;
1530
1668
  this.onTag = params.onTag;
@@ -1565,12 +1703,15 @@ class TagWatcher {
1565
1703
  }
1566
1704
  setTags(tags) {
1567
1705
  this.tags = tags;
1706
+ this.matcher.setTags(tags);
1568
1707
  if (this.interval) {
1569
1708
  clearInterval(this.interval);
1570
1709
  this.interval = null;
1571
1710
  }
1572
1711
  this.interval = setInterval(() => {
1573
1712
  this.tags.forEach((tag) => {
1713
+ if (!matchesLocation(tag))
1714
+ return;
1574
1715
  const possibleEls = document.querySelectorAll(tag.selector);
1575
1716
  if (possibleEls.length > 0) {
1576
1717
  const el = possibleEls[0];
@@ -1582,13 +1723,17 @@ class TagWatcher {
1582
1723
  }, 500);
1583
1724
  }
1584
1725
  onTagRendered(tagId) {
1585
- if (this.tags.findIndex(t => t.id === tagId)) {
1586
- this.tags = this.tags.filter((tag) => tag.id !== tagId);
1726
+ const tag = this.tags.find(t => t.id === tagId);
1727
+ if (tag) {
1728
+ this.tags = this.tags.filter((t) => t.id !== tagId);
1729
+ if (!matchesLocation(tag))
1730
+ return;
1587
1731
  }
1588
1732
  this.onTag(tagId);
1589
1733
  }
1590
1734
  clear() {
1591
1735
  this.tags = [];
1736
+ this.matcher.clear();
1592
1737
  if (this.interval) {
1593
1738
  clearInterval(this.interval);
1594
1739
  this.interval = null;
@@ -2241,8 +2386,44 @@ function inlineRemoteCss(node, id, baseHref, getNextID, insertRule, addOwner, fo
2241
2386
  })
2242
2387
  .catch(error => {
2243
2388
  console.error(`OpenReplay: Failed to fetch CSS from ${node.href}:`, error);
2389
+ // Fetch failed (likely CORS) — retry via load event + sheet access
2390
+ retryViaLoadEvent();
2244
2391
  });
2245
2392
  }
2393
+ else {
2394
+ retryViaLoadEvent();
2395
+ }
2396
+ function retryViaLoadEvent() {
2397
+ const trySheet = () => {
2398
+ const loadedSheet = node.sheet;
2399
+ if (loadedSheet) {
2400
+ try {
2401
+ const cssText = stringifyStylesheet(loadedSheet);
2402
+ if (cssText) {
2403
+ if (sendPlain && onPlain) {
2404
+ onPlain(cssText, fakeIdHolder++);
2405
+ }
2406
+ else {
2407
+ processCssText(cssText);
2408
+ }
2409
+ return;
2410
+ }
2411
+ }
2412
+ catch (e) {
2413
+ // cross-origin sheet — nothing more we can do
2414
+ }
2415
+ }
2416
+ };
2417
+ if (node.sheet) {
2418
+ trySheet();
2419
+ }
2420
+ else {
2421
+ node.addEventListener('load', function onLoad() {
2422
+ node.removeEventListener('load', onLoad);
2423
+ trySheet();
2424
+ });
2425
+ }
2426
+ }
2246
2427
  function processCssText(cssText) {
2247
2428
  // Remove comments
2248
2429
  cssText = cssText.replace(/\/\*[\s\S]*?\*\//g, '');
@@ -2464,7 +2645,6 @@ function ConstructedStyleSheets (app) {
2464
2645
  if (!hasAdoptedSS(document)) {
2465
2646
  return;
2466
2647
  }
2467
- const styleSheetIDMap = new Map();
2468
2648
  const adoptedStyleSheetsOwnings = new Map();
2469
2649
  const sendAdoptedStyleSheetsUpdate = (root) => setTimeout(() => {
2470
2650
  let nodeID = app.nodes.getID(root);
@@ -2729,6 +2909,12 @@ class Observer {
2729
2909
  this.inlineRemoteCss = false;
2730
2910
  this.inlinerOptions = undefined;
2731
2911
  this.domParser = new DOMParser();
2912
+ /**
2913
+ * Bumped on every disconnect(). Stale async CSS-inlining callbacks from a
2914
+ * previous session (e.g. agent reload → tracker restart) compare against
2915
+ * this and bail instead of sending messages that reference vanished node ids.
2916
+ */
2917
+ this.generation = 0;
2732
2918
  this.throttling = true;
2733
2919
  this.throttledSetNodeData = throttleWithTrailing((id, parentElement, data) => this.sendNodeData(id, parentElement, data), 30);
2734
2920
  this.throttling = !Boolean(options.disableThrottling);
@@ -2875,18 +3061,23 @@ class Observer {
2875
3061
  }
2876
3062
  if (name === 'style' || (name === 'href' && hasTag(node, 'link'))) {
2877
3063
  if ('rel' in node && node.rel === 'stylesheet' && this.inlineRemoteCss) {
3064
+ const gen = this.generation;
2878
3065
  setTimeout(() => {
2879
3066
  inlineRemoteCss(
2880
3067
  // @ts-ignore
2881
3068
  node, id, this.app.getBaseHref(), nextID, (id, cssText, index, baseHref) => {
3069
+ if (this.generation !== gen)
3070
+ return;
2882
3071
  this.app.send(AdoptedSSInsertRuleURLBased(id, cssText, index, baseHref));
2883
3072
  }, (sheetId, ownerId) => {
3073
+ if (this.generation !== gen)
3074
+ return;
2884
3075
  this.app.send(AdoptedSSAddOwner(sheetId, ownerId));
2885
3076
  }, this.inlinerOptions?.forceFetch, this.inlinerOptions?.forcePlain, (cssText, fakeTextId) => {
3077
+ if (this.generation !== gen)
3078
+ return;
2886
3079
  this.app.send(CreateTextNode(fakeTextId, id, 0));
2887
- setTimeout(() => {
2888
- this.app.send(SetCSSDataURLBased(fakeTextId, cssText, this.app.getBaseHref()));
2889
- }, 10);
3080
+ this.app.send(SetCSSDataURLBased(fakeTextId, cssText, this.app.getBaseHref()));
2890
3081
  });
2891
3082
  }, 0);
2892
3083
  return;
@@ -3150,6 +3341,7 @@ class Observer {
3150
3341
  this.observer.disconnect();
3151
3342
  this.clear();
3152
3343
  this.throttledSetNodeData.clear();
3344
+ this.generation++;
3153
3345
  }
3154
3346
  }
3155
3347
 
@@ -3754,7 +3946,7 @@ class Ticker {
3754
3946
  * this value is injected during build time via rollup
3755
3947
  * */
3756
3948
  // @ts-ignore
3757
- 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";
3949
+ 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: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";
3758
3950
  const CANCELED = 'canceled';
3759
3951
  const bufferStorageKey = 'or_buffer_1';
3760
3952
  const UnsuccessfulStart = (reason) => ({ reason, success: false });
@@ -3796,6 +3988,9 @@ const proto = {
3796
3988
  reset: 'reset-your-session-please',
3797
3989
  };
3798
3990
  class App {
3991
+ get tagMatcher() {
3992
+ return this.tagWatcher.matcher;
3993
+ }
3799
3994
  constructor(projectKey, sessionToken, options, signalError, insideIframe) {
3800
3995
  this.signalError = signalError;
3801
3996
  this.insideIframe = insideIframe;
@@ -3810,7 +4005,7 @@ class App {
3810
4005
  this.stopCallbacks = [];
3811
4006
  this.commitCallbacks = [];
3812
4007
  this.activityState = ActivityState.NotActive;
3813
- this.version = '17.2.6'; // TODO: version compatability check inside each plugin.
4008
+ this.version = '17.2.9'; // TODO: version compatability check inside each plugin.
3814
4009
  this.socketMode = false;
3815
4010
  this.compressionThreshold = 24 * 1000;
3816
4011
  this.bc = null;
@@ -3832,12 +4027,19 @@ class App {
3832
4027
  if (!data || event.source === window)
3833
4028
  return;
3834
4029
  if (data.line === proto.startIframe) {
3835
- if (this.active())
4030
+ // Avoid corrupting an in-flight start; let it complete.
4031
+ if (this.activityState === ActivityState.Starting)
3836
4032
  return;
3837
4033
  try {
4034
+ if (this.active()) {
4035
+ this.stop();
4036
+ }
3838
4037
  if (data.token) {
3839
4038
  this.session.setSessionToken(data.token, this.projectKey);
3840
4039
  }
4040
+ if (data.id !== undefined) {
4041
+ this.rootId = data.id;
4042
+ }
3841
4043
  this.allowAppStart();
3842
4044
  void this.start();
3843
4045
  }
@@ -3863,17 +4065,22 @@ class App {
3863
4065
  }
3864
4066
  }
3865
4067
  };
3866
- /**
3867
- * context ids for iframes,
3868
- * order is not so important as long as its consistent
3869
- * */
3870
4068
  this.trackedFrames = [];
4069
+ this.frameLastSeen = new Map();
4070
+ this.FRAME_STALE_MS = 1500;
3871
4071
  this.crossDomainIframeListener = (event) => {
3872
- if (!this.active() || event.source === window)
4072
+ if (event.source === window)
3873
4073
  return;
3874
4074
  const { data } = event;
3875
4075
  if (!data)
3876
4076
  return;
4077
+ // Record liveness regardless of our own active state so the queue can prune
4078
+ // stale contexts reliably once we resume dispatching commands after a cycle.
4079
+ if ((data.line === proto.polling || data.line === proto.iframeSignal) && data.context) {
4080
+ this.frameLastSeen.set(data.context, Date.now());
4081
+ }
4082
+ if (!this.active())
4083
+ return;
3877
4084
  if (data.line === proto.iframeSignal) {
3878
4085
  // @ts-ignore
3879
4086
  event.source?.postMessage({ ping: true, line: proto.parentAlive }, '*');
@@ -3971,20 +4178,41 @@ class App {
3971
4178
  if (!this.pollingQueue.order.length) {
3972
4179
  return;
3973
4180
  }
3974
- const nextCommand = this.pollingQueue.order[0];
3975
- if (nextCommand && this.pollingQueue[nextCommand].length === 0) {
3976
- this.pollingQueue.order = this.pollingQueue.order.filter((c) => c !== nextCommand);
4181
+ this.pruneStaleFrames();
4182
+ const liveSet = new Set(this.trackedFrames);
4183
+ while (this.pollingQueue.order.length > 0) {
4184
+ const head = this.pollingQueue.order[0];
4185
+ this.pollingQueue[head] = this.pollingQueue[head].filter((ctx) => liveSet.has(ctx));
4186
+ if (this.pollingQueue[head].length === 0) {
4187
+ delete this.pollingQueue[head];
4188
+ this.pollingQueue.order.shift();
4189
+ }
4190
+ else {
4191
+ break;
4192
+ }
4193
+ }
4194
+ if (!this.pollingQueue.order.length) {
3977
4195
  return;
3978
4196
  }
4197
+ const nextCommand = this.pollingQueue.order[0];
3979
4198
  if (this.pollingQueue[nextCommand].includes(data.context)) {
3980
4199
  this.pollingQueue[nextCommand] = this.pollingQueue[nextCommand].filter((c) => c !== data.context);
3981
4200
  const message = { line: nextCommand };
3982
4201
  if (nextCommand === proto.startIframe) {
3983
4202
  message.token = this.session.getSessionToken(this.projectKey);
4203
+ const targetFrame = this.pageFrames.find((f) => f.contentWindow === event.source)
4204
+ || Array.from(document.querySelectorAll('iframe')).find((f) => f.contentWindow === event.source);
4205
+ if (targetFrame) {
4206
+ const nodeId = targetFrame[this.options.node_id];
4207
+ if (nodeId !== undefined) {
4208
+ message.id = nodeId;
4209
+ }
4210
+ }
3984
4211
  }
3985
4212
  // @ts-ignore
3986
4213
  event.source?.postMessage(message, '*');
3987
4214
  if (this.pollingQueue[nextCommand].length === 0) {
4215
+ delete this.pollingQueue[nextCommand];
3988
4216
  this.pollingQueue.order.shift();
3989
4217
  }
3990
4218
  }
@@ -3998,6 +4226,11 @@ class App {
3998
4226
  order: [],
3999
4227
  };
4000
4228
  this.addCommand = (cmd) => {
4229
+ this.pruneStaleFrames();
4230
+ if (this.pollingQueue[cmd]) {
4231
+ this.pollingQueue[cmd] = Array.from(new Set([...this.pollingQueue[cmd], ...this.trackedFrames]));
4232
+ return;
4233
+ }
4001
4234
  this.pollingQueue.order.push(cmd);
4002
4235
  this.pollingQueue[cmd] = [...this.trackedFrames];
4003
4236
  };
@@ -4309,6 +4542,16 @@ class App {
4309
4542
  };
4310
4543
  }
4311
4544
  }
4545
+ pruneStaleFrames() {
4546
+ const staleAfter = Date.now() - this.FRAME_STALE_MS;
4547
+ this.trackedFrames = this.trackedFrames.filter((ctx) => {
4548
+ const last = this.frameLastSeen.get(ctx);
4549
+ if (last !== undefined && last >= staleAfter)
4550
+ return true;
4551
+ this.frameLastSeen.delete(ctx);
4552
+ return false;
4553
+ });
4554
+ }
4312
4555
  allowAppStart() {
4313
4556
  this.canStart = true;
4314
4557
  if (this.startTimeout) {
@@ -4859,6 +5102,9 @@ class App {
4859
5102
  if (Object.keys(startOpts).length !== 0) {
4860
5103
  this.prevOpts = startOpts;
4861
5104
  }
5105
+ if (startOpts.startCallback) {
5106
+ this.userStartCallback = startOpts.startCallback;
5107
+ }
4862
5108
  const isColdStart = this.activityState === ActivityState.ColdStart;
4863
5109
  if (isColdStart && this.coldInterval) {
4864
5110
  clearInterval(this.coldInterval);
@@ -4998,8 +5244,8 @@ class App {
4998
5244
  // TODO: start as early as possible (before receiving the token)
4999
5245
  /** after start */
5000
5246
  this.startCallbacks.forEach((cb) => cb(onStartInfo)); // MBTODO: callbacks after DOM "mounted" (observed)
5001
- if (startOpts.startCallback) {
5002
- startOpts.startCallback(SuccessfulStart(onStartInfo));
5247
+ if (this.userStartCallback) {
5248
+ this.userStartCallback(SuccessfulStart(onStartInfo));
5003
5249
  }
5004
5250
  this.activityState = ActivityState.Active;
5005
5251
  if (this.options.crossdomain?.enabled) {
@@ -5162,6 +5408,7 @@ class App {
5162
5408
  this.canvasRecorder?.clear();
5163
5409
  this.messages.length = 0;
5164
5410
  this.parentActive = false;
5411
+ this.pageFrames = [];
5165
5412
  }
5166
5413
  finally {
5167
5414
  this.activityState = ActivityState.NotActive;
@@ -5744,6 +5991,18 @@ function Input (app, opts) {
5744
5991
  defaultInputMode: InputMode.Obscured,
5745
5992
  obscureInputDates: false,
5746
5993
  }, opts);
5994
+ const tagSelectorMap = new Map();
5995
+ function getTagSelector(id, node) {
5996
+ const cached = tagSelectorMap.get(id);
5997
+ if (cached !== undefined)
5998
+ return cached;
5999
+ const tagMatch = app.tagMatcher.match(node);
6000
+ if (tagMatch) {
6001
+ tagSelectorMap.set(id, tagMatch.selector);
6002
+ return tagMatch.selector;
6003
+ }
6004
+ return null;
6005
+ }
5747
6006
  function getInputValue(id, node) {
5748
6007
  let value = node.value;
5749
6008
  let inputMode = options.defaultInputMode;
@@ -5779,6 +6038,7 @@ function Input (app, opts) {
5779
6038
  app.attachStopCallback(() => {
5780
6039
  inputValues.clear();
5781
6040
  checkboxValues.clear();
6041
+ tagSelectorMap.clear();
5782
6042
  });
5783
6043
  function trackInputValue(id, node) {
5784
6044
  if (inputValues.get(id) === node.value) {
@@ -5811,7 +6071,7 @@ function Input (app, opts) {
5811
6071
  }, 3);
5812
6072
  function sendInputChange(id, node, hesitationTime, inputTime) {
5813
6073
  const { value, mask } = getInputValue(id, node);
5814
- let label = getInputLabel(node, options.customAttributes);
6074
+ let label = getTagSelector(id, node) || getInputLabel(node, options.customAttributes);
5815
6075
  if (app.sanitizer.privateMode) {
5816
6076
  label = label.replaceAll(/./g, '*');
5817
6077
  }
@@ -5994,7 +6254,13 @@ function Mouse (app, options) {
5994
6254
  };
5995
6255
  const patchDocument = (document, topframe = false) => {
5996
6256
  function getSelector(id, target) {
5997
- return (selectorMap[id] = selectorMap[id] || _getSelector(target));
6257
+ if (selectorMap[id])
6258
+ return selectorMap[id];
6259
+ const tagMatch = app.tagMatcher.match(target);
6260
+ if (tagMatch) {
6261
+ return (selectorMap[id] = tagMatch.selector);
6262
+ }
6263
+ return (selectorMap[id] = _getSelector(target));
5998
6264
  }
5999
6265
  const attachListener = topframe
6000
6266
  ? app.attachEventListener.bind(app) // attached/removed on start/stop
@@ -8672,7 +8938,7 @@ class ConstantProperties {
8672
8938
  user_id: this.user_id,
8673
8939
  distinct_id: this.deviceId,
8674
8940
  sdk_edition: 'web',
8675
- sdk_version: '17.2.6',
8941
+ sdk_version: '17.2.9',
8676
8942
  timezone: getUTCOffsetString(),
8677
8943
  search_engine: this.searchEngine,
8678
8944
  };
@@ -9374,7 +9640,7 @@ class API {
9374
9640
  this.signalStartIssue = (reason, missingApi) => {
9375
9641
  const doNotTrack = this.checkDoNotTrack();
9376
9642
  console.log("Tracker couldn't start due to:", JSON.stringify({
9377
- trackerVersion: '17.2.6',
9643
+ trackerVersion: '17.2.9',
9378
9644
  projectKey: this.options.projectKey,
9379
9645
  doNotTrack,
9380
9646
  reason: missingApi.length ? `missing api: ${missingApi.join(',')}` : reason,