@usesequential/browser 1.0.3 → 1.0.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.4
4
+
5
+ - The person's own pointerup, touchend or keydown is noted on the window, before any handler of the page runs. So a click
6
+ that a page's own key or tap handler makes at once (for example on a `role="button"`) is recorded, also on a browser
7
+ without `navigator.userActivation`, when that handler was added before the SDK.
8
+ - On-screen messages (`$ui_message`), off unless the project is switched on by Sequential: for 3 seconds after a click,
9
+ a submit or an Enter, and once 1.5 seconds after a page load or route change, an announced message (`role="alert"`,
10
+ `role="status"`, `aria-live`), a control marked `aria-invalid`, or an error-styled line in a form is sorted into a class
11
+ from the project's patterns. Only the class and structure are sent (kind, tone, the form or section it is near, the
12
+ window, a length band), never the text or any hash of it. Nothing under `data-sq-private` or `data-sq-mask`. At most
13
+ one per message per 10 seconds, 10 per page view and 30 per minute.
14
+ - An element id is sent only when it is a plain token (letters, digits, `_` and `-`, at most 128 characters), in
15
+ `$el_id`, the form's `form` and every selector. An id that holds text (a name, an order number, spaces), a generated
16
+ `:r1:` id, or a longer one counts as no id, so the selector is the id-less path. Dead-click and rage-click cases on such
17
+ controls start a new case once, from this release.
18
+
3
19
  ## 1.0.3
4
20
 
5
21
  - A click that a script makes (`el.click()`, `dispatchEvent`; the browser marks it `isTrusted: false`) is recorded only
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- /* @usesequential/browser 1.0.3: the Sequential browser SDK. MIT. https://www.usesequential.com/docs/browser-npm
1
+ /* @usesequential/browser 1.0.4: the Sequential browser SDK. MIT. https://www.usesequential.com/docs/browser-npm
2
2
  * `boot` below is sequential.js, the file the script tag loads, unchanged. */
3
3
  'use strict';
4
4
  var boot = (function (injectedTag) {
@@ -1260,6 +1260,12 @@ var boot = (function (injectedTag) {
1260
1260
  var EL_DATA_VALUE_MAX = 128;
1261
1261
 
1262
1262
  var EL_ID_MAX = 128;
1263
+ // An id is sent only as a token (letters, digits, '_', '-'; at most 128): an id holding text (a name, an order number,
1264
+ // spaces) or a generated ':r1:' counts as no id, here and in every selector (design gate/mgr/ux-detection-2026-11-18/
1265
+ // click-id-shape.md; the ingest gate holds old copies to the same rule).
1266
+ function idToken(id) {
1267
+ return typeof id === 'string' && /^[A-Za-z0-9_-]{1,128}$/.test(id) ? id : '';
1268
+ }
1263
1269
  var EL_SELECTOR_MAX = 256;
1264
1270
 
1265
1271
  var URL_MAX = 512;
@@ -1316,7 +1322,8 @@ var boot = (function (injectedTag) {
1316
1322
  return !!closestMatching(el, '[data-sq-mask], [data-sq-private]');
1317
1323
  }
1318
1324
 
1319
- function subtreeText(el) {
1325
+ // skip (the message detector's MSG_TYPED): also leave out what matches it, or what the browser says is editable.
1326
+ function subtreeText(el, skip) {
1320
1327
  var out = '';
1321
1328
  function visit(node) {
1322
1329
  for (var child = node.firstChild; child !== null; child = child.nextSibling) {
@@ -1329,6 +1336,7 @@ var boot = (function (injectedTag) {
1329
1336
  if (inList(TEXT_OPAQUE_TAGS, tagNameOf(child))) continue;
1330
1337
  if (isEditable(child)) continue;
1331
1338
  if (child.hasAttribute && (child.hasAttribute('data-sq-mask') || child.hasAttribute('data-sq-private'))) continue;
1339
+ if (skip && (child.isContentEditable === true || matchesSelector(child, skip))) continue;
1332
1340
  visit(child);
1333
1341
  }
1334
1342
  }
@@ -1402,7 +1410,7 @@ var boot = (function (injectedTag) {
1402
1410
  var node = el;
1403
1411
  var root = document.documentElement;
1404
1412
  while (node && node !== root && node.nodeType === 1) {
1405
- if (node.id && !noIds) {
1413
+ if (!noIds && idToken(node.id)) {
1406
1414
  parts.unshift('#' + node.id);
1407
1415
  break;
1408
1416
  }
@@ -1452,6 +1460,12 @@ var boot = (function (injectedTag) {
1452
1460
  }
1453
1461
 
1454
1462
  var autocaptureStarted = false;
1463
+ var MSG_SEL = '[role=alert], [role=status], [aria-live=assertive], [aria-live=polite], [aria-invalid=true]';
1464
+ var MSG_STYLED = /(^|[-_\s])(error|danger|invalid|alert|warning)([-_\s]|$)/i;
1465
+ var MSG_CLASSES = /^(sign_in_again|already_exists|required|invalid_format|not_allowed|not_found|network|try_again|limit_reached|payment)$/;
1466
+ // A control, or anything inside an editable region: what the visitor types, never read as a message.
1467
+ var MSG_TYPED = 'input, textarea, select, [contenteditable]:not([contenteditable="false"]), [role=textbox], [role=searchbox], [role=combobox], .ace_editor, .monaco-editor, .CodeMirror';
1468
+ var uiMessages = null;
1455
1469
  // Set by startAutocapture: sends an open rage burst before the unload path drains the queue.
1456
1470
  var flushOpenSignals = noop;
1457
1471
 
@@ -1575,6 +1589,20 @@ var boot = (function (injectedTag) {
1575
1589
  $nav: nav,
1576
1590
  $load_type: nav === 'load' ? loadTypeOf() : undefined
1577
1591
  });
1592
+ if (msgRules) {
1593
+ msgView = 0;
1594
+ msgCapped = false;
1595
+ msgSeen = {};
1596
+ clearTimeout(msgScanTimer);
1597
+ msgScanTimer = setTimeout(function () {
1598
+ try {
1599
+ msgBudget = 300;
1600
+ msgExamined = typeof WeakMap === 'function' ? new WeakMap() : null;
1601
+ var list = document.querySelectorAll(MSG_SEL);
1602
+ for (var i = 0; i < list.length && msgBudget > 0; i++) msgFound(list[i], nav === 'load' ? 'load' : 'route');
1603
+ } catch (e) {}
1604
+ }, 1500);
1605
+ }
1578
1606
  }
1579
1607
 
1580
1608
  // One page key for every trigger, as sequential.autocapture.ts pageKey.
@@ -1647,7 +1675,7 @@ var boot = (function (injectedTag) {
1647
1675
  return {
1648
1676
  $el_tag_name: tagNameOf(matched),
1649
1677
  $el_selector: cap(selector, EL_SELECTOR_MAX),
1650
- $el_id: matched.id && !noIds ? cap(String(matched.id), EL_ID_MAX) : undefined,
1678
+ $el_id: !noIds && idToken(matched.id) || undefined,
1651
1679
  $el_data: masked || identity ? undefined : dataAttrs(matched, redactor),
1652
1680
  $el_text: raw !== undefined && !identity ? redactor.boundedRedact(raw, CLICK_TEXT_MAX) : undefined,
1653
1681
  $el_label: label && !labelOrHrefIdentity ? redactor.boundedRedact(label, CLICK_TEXT_MAX) : undefined,
@@ -1663,7 +1691,10 @@ var boot = (function (injectedTag) {
1663
1691
  var gestureAt = -1e9;
1664
1692
 
1665
1693
  function onGesture(ev) {
1666
- if (ev.isTrusted) gestureAt = now();
1694
+ if (ev.isTrusted) {
1695
+ gestureAt = now();
1696
+ if (ev.key === 'Enter') openMsg('submit');
1697
+ }
1667
1698
  }
1668
1699
 
1669
1700
  function onClick(ev) {
@@ -1675,6 +1706,7 @@ var boot = (function (injectedTag) {
1675
1706
  var ua = window.navigator.userActivation;
1676
1707
  if (!(ua && ua.isActive) && now() - gestureAt >= 1000) return;
1677
1708
  }
1709
+ openMsg('click');
1678
1710
  var matched = closestMatching(target, INTERACTIVE_SELECTOR);
1679
1711
  if (!matched) return;
1680
1712
  var props = elementProps(matched);
@@ -1697,10 +1729,10 @@ var boot = (function (injectedTag) {
1697
1729
 
1698
1730
  function syncObserver() {
1699
1731
  try {
1700
- if ((rage || dead) && !observer && Observer) {
1732
+ if ((rage || dead || now() < msgUntil) && !observer && Observer) {
1701
1733
  observer = new Observer(onMutations);
1702
1734
  observer.observe(document, { subtree: true, childList: true, attributes: true, attributeOldValue: true, characterData: true });
1703
- } else if (!rage && !dead && observer) {
1735
+ } else if (!rage && !dead && now() >= msgUntil && observer) {
1704
1736
  observer.disconnect();
1705
1737
  observer = null;
1706
1738
  }
@@ -1728,6 +1760,20 @@ var boot = (function (injectedTag) {
1728
1760
 
1729
1761
  function onMutations(records) {
1730
1762
  var own = true;
1763
+ if (now() < msgUntil) {
1764
+ for (var j = 0; j < records.length && j < 100 && msgBudget > 0; j++) {
1765
+ var r = records[j];
1766
+ msgFound(r.target.nodeType === 1 ? r.target : r.target.parentNode, msgAfter);
1767
+ for (var k = 0; k < r.addedNodes.length; k++) {
1768
+ var n = r.addedNodes[k];
1769
+ if (n.nodeType !== 1) continue;
1770
+ msgFound(n, msgAfter);
1771
+ var inner = n.querySelectorAll(MSG_SEL);
1772
+ for (var m = 0; m < inner.length && m < 20 && msgBudget > 0; m++) msgFound(inner[m], msgAfter);
1773
+ }
1774
+ }
1775
+ }
1776
+ if (!rage && !dead) return syncObserver();
1731
1777
  for (var i = 0; i < records.length; i++) {
1732
1778
  if (records[i].type !== 'attributes' || !rage || records[i].target !== rage.el || stateChanged(records[i])) own = false;
1733
1779
  }
@@ -1829,6 +1875,103 @@ var boot = (function (injectedTag) {
1829
1875
  if ((dead || rage) && hasSelection()) effect(false);
1830
1876
  }
1831
1877
 
1878
+ // ── on-screen messages: $ui_message (D1). Rule zero: the text is matched here against the project's patterns (from the
1879
+ // config, off without them) and only the CLASS is sent; no text, no part of it, no hash of it.
1880
+ var msgRules = null;
1881
+ try {
1882
+ if (uiMessages && uiMessages.patterns) {
1883
+ msgRules = [];
1884
+ for (var pi = 0; pi < uiMessages.patterns.length && pi < 50; pi++) {
1885
+ try {
1886
+ msgRules.push([String(uiMessages.patterns[pi][0]), new RegExp(String(uiMessages.patterns[pi][1]).slice(0, 300), 'i')]);
1887
+ } catch (e) {}
1888
+ }
1889
+ }
1890
+ } catch (e) {}
1891
+ var msgUntil = 0;
1892
+ var msgAfter;
1893
+ var msgSeen = {};
1894
+ var msgView = 0;
1895
+ var msgTimes = [];
1896
+ var msgCapped = false;
1897
+ var msgBudget = 0;
1898
+ var msgExamined = null;
1899
+ var msgScanTimer;
1900
+
1901
+ // 3 s after a click, a submit or an Enter, what appears is read.
1902
+ function openMsg(after) {
1903
+ if (!msgRules) return;
1904
+ msgUntil = now() + 3000;
1905
+ msgAfter = after;
1906
+ msgBudget = 300;
1907
+ msgExamined = typeof WeakMap === 'function' ? new WeakMap() : null;
1908
+ syncObserver();
1909
+ setTimeout(syncObserver, 3001);
1910
+ }
1911
+
1912
+ // The click selector's rules (an id only as a token: idToken).
1913
+ function msgNear(el, noIds) {
1914
+ var sel = stableSelector(el, noIds);
1915
+ return DETECT_IDENTITY && namesPerson(sel) ? stableSelector(el, true) : sel;
1916
+ }
1917
+
1918
+ function msgFound(el, after) {
1919
+ try {
1920
+ if (!msgRules || !el || el.nodeType !== 1 || msgBudget-- <= 0) return;
1921
+ var m = closestMatching(el, MSG_SEL);
1922
+ if (!m && MSG_STYLED.test(el.getAttribute('class') || '') && closestMatching(el, 'form')) m = el;
1923
+ if (!m || isMasked(m) || m.isContentEditable || document.designMode === 'on') return;
1924
+ var cls = String(m.getAttribute('class') || '');
1925
+ var role = m.getAttribute('role');
1926
+ var live = m.getAttribute('aria-live');
1927
+ var invalid = m.getAttribute('aria-invalid') === 'true';
1928
+ // A control is never the message (its own text is what was typed); one marked invalid points to its message.
1929
+ if (!invalid && closestMatching(m, MSG_TYPED)) return;
1930
+ var kind = invalid ? 'field_error' : role === 'alert' || live === 'assertive' ? 'alert' : role === 'status' || live === 'polite' ? 'status' : 'field_error';
1931
+ var shown = invalid ? document.getElementById((m.getAttribute('aria-errormessage') || m.getAttribute('aria-describedby') || '').split(' ')[0]) : m;
1932
+ if (!shown || isMasked(shown) || shown.isContentEditable || closestMatching(shown, MSG_TYPED) || shown.querySelector('[data-sq-mask], [data-sq-private]')) return;
1933
+ // The bounded walk of click text: no textarea/select content, no editable or masked part; cut before any rewrite.
1934
+ var text = subtreeText(shown, MSG_TYPED).slice(0, 500).replace(/\s+/g, ' ').replace(/^ | $/g, '').toLowerCase();
1935
+ // Read again only when its text changed ("Saving…" → "Network error" in one window is two messages).
1936
+ if (!text || (msgExamined && msgExamined.get(m) === text)) return;
1937
+ if (msgExamined) msgExamined.set(m, text);
1938
+ var cl = 'other';
1939
+ var t0 = now();
1940
+ for (var i = 0; i < msgRules.length; i++) {
1941
+ if (msgRules[i][1].test(text)) {
1942
+ cl = msgRules[i][0];
1943
+ break;
1944
+ }
1945
+ }
1946
+ // A pattern this slow on this page: no detector for the rest of the page.
1947
+ if (now() - t0 > 5) msgRules = null;
1948
+ if (!MSG_CLASSES.test(cl)) cl = 'other';
1949
+ var near = closestMatching(m, 'form') || (invalid ? m : closestMatching(m, 'dialog, section, main') || m);
1950
+ var props = {
1951
+ $msg_kind: kind,
1952
+ $msg_tone: /error|danger|invalid/i.test(cls) ? 'error' : /warn/i.test(cls) ? 'warning' : /success/i.test(cls) ? 'success' : kind === 'status' ? 'info' : 'error',
1953
+ $msg_class: cl,
1954
+ $msg_near: cap(msgNear(near, near === m), EL_SELECTOR_MAX),
1955
+ $msg_after: after,
1956
+ $msg_len: text.length <= 40 ? 'short' : text.length <= 160 ? 'medium' : 'long'
1957
+ };
1958
+ var t = now();
1959
+ var key = kind + ' ' + props.$msg_near + ' ' + cl;
1960
+ if (msgSeen[key] > t - 10000) return;
1961
+ msgSeen[key] = t;
1962
+ while (msgTimes.length && msgTimes[0] <= t - 60000) msgTimes.shift();
1963
+ // 10 per page view, 30 per minute; past either, one 'capped'.
1964
+ if (msgView >= 10 || msgTimes.length >= 30) {
1965
+ if (msgCapped) return;
1966
+ msgCapped = true;
1967
+ props.$msg_class = 'capped';
1968
+ }
1969
+ msgView++;
1970
+ msgTimes.push(t);
1971
+ captureInternal('$ui_message', props);
1972
+ } catch (e) {}
1973
+ }
1974
+
1832
1975
  function onScroll() {
1833
1976
  if (dead || rage) effect(false);
1834
1977
  }
@@ -1850,10 +1993,11 @@ var boot = (function (injectedTag) {
1850
1993
  try {
1851
1994
  var target = ev && ev.target;
1852
1995
  if (!target || tagNameOf(target) !== 'form') return;
1996
+ openMsg('submit');
1853
1997
 
1854
1998
  captureInternal('$form_submit', {
1855
1999
  $form_selector: cap(stableSelector(target), EL_SELECTOR_MAX),
1856
- form: target.id ? cap(String(target.id), EL_ID_MAX) : undefined
2000
+ form: idToken(target.id) || undefined
1857
2001
  });
1858
2002
  } catch (e) {}
1859
2003
  }
@@ -1862,9 +2006,10 @@ var boot = (function (injectedTag) {
1862
2006
  document.addEventListener('submit', onSubmit, true);
1863
2007
  document.addEventListener('pointerdown', onPointerDown, true);
1864
2008
  document.addEventListener('pointerup', onPointerUp, true);
1865
- document.addEventListener('pointerup', onGesture, true);
1866
- document.addEventListener('touchend', onGesture, true);
1867
- document.addEventListener('keydown', onGesture, true);
2009
+ // Window capture: the first stop of every event, so the gesture is marked before a page handler that clicks (#1173).
2010
+ window.addEventListener('pointerup', onGesture, true);
2011
+ window.addEventListener('touchend', onGesture, true);
2012
+ window.addEventListener('keydown', onGesture, true);
1868
2013
  document.addEventListener('focusin', onFocusIn, true);
1869
2014
  document.addEventListener('selectionchange', onSelectionChange, true);
1870
2015
  document.addEventListener('scroll', onScroll, true);
@@ -2037,6 +2182,7 @@ var boot = (function (injectedTag) {
2037
2182
  syncContextCookie();
2038
2183
  if (config && config.redaction) installRedactor(config.redaction);
2039
2184
 
2185
+ uiMessages = config && config.ui_messages;
2040
2186
  if (AUTOCAPTURE_ENABLED) startAutocapture(attachUrl);
2041
2187
  bootRecorder(config);
2042
2188
  } catch (e) {}
@@ -2071,7 +2217,7 @@ var boot = (function (injectedTag) {
2071
2217
  }
2072
2218
  });
2073
2219
 
2074
- var VERSION = '1.0.3';
2220
+ var VERSION = '1.0.4';
2075
2221
  var running = null;
2076
2222
 
2077
2223
  function logLine(level, message) {
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /* @usesequential/browser 1.0.3: the Sequential browser SDK. MIT. https://www.usesequential.com/docs/browser-npm
1
+ /* @usesequential/browser 1.0.4: the Sequential browser SDK. MIT. https://www.usesequential.com/docs/browser-npm
2
2
  * `boot` below is sequential.js, the file the script tag loads, unchanged. */
3
3
  var boot = (function (injectedTag) {
4
4
  'use strict';
@@ -1259,6 +1259,12 @@ var boot = (function (injectedTag) {
1259
1259
  var EL_DATA_VALUE_MAX = 128;
1260
1260
 
1261
1261
  var EL_ID_MAX = 128;
1262
+ // An id is sent only as a token (letters, digits, '_', '-'; at most 128): an id holding text (a name, an order number,
1263
+ // spaces) or a generated ':r1:' counts as no id, here and in every selector (design gate/mgr/ux-detection-2026-11-18/
1264
+ // click-id-shape.md; the ingest gate holds old copies to the same rule).
1265
+ function idToken(id) {
1266
+ return typeof id === 'string' && /^[A-Za-z0-9_-]{1,128}$/.test(id) ? id : '';
1267
+ }
1262
1268
  var EL_SELECTOR_MAX = 256;
1263
1269
 
1264
1270
  var URL_MAX = 512;
@@ -1315,7 +1321,8 @@ var boot = (function (injectedTag) {
1315
1321
  return !!closestMatching(el, '[data-sq-mask], [data-sq-private]');
1316
1322
  }
1317
1323
 
1318
- function subtreeText(el) {
1324
+ // skip (the message detector's MSG_TYPED): also leave out what matches it, or what the browser says is editable.
1325
+ function subtreeText(el, skip) {
1319
1326
  var out = '';
1320
1327
  function visit(node) {
1321
1328
  for (var child = node.firstChild; child !== null; child = child.nextSibling) {
@@ -1328,6 +1335,7 @@ var boot = (function (injectedTag) {
1328
1335
  if (inList(TEXT_OPAQUE_TAGS, tagNameOf(child))) continue;
1329
1336
  if (isEditable(child)) continue;
1330
1337
  if (child.hasAttribute && (child.hasAttribute('data-sq-mask') || child.hasAttribute('data-sq-private'))) continue;
1338
+ if (skip && (child.isContentEditable === true || matchesSelector(child, skip))) continue;
1331
1339
  visit(child);
1332
1340
  }
1333
1341
  }
@@ -1401,7 +1409,7 @@ var boot = (function (injectedTag) {
1401
1409
  var node = el;
1402
1410
  var root = document.documentElement;
1403
1411
  while (node && node !== root && node.nodeType === 1) {
1404
- if (node.id && !noIds) {
1412
+ if (!noIds && idToken(node.id)) {
1405
1413
  parts.unshift('#' + node.id);
1406
1414
  break;
1407
1415
  }
@@ -1451,6 +1459,12 @@ var boot = (function (injectedTag) {
1451
1459
  }
1452
1460
 
1453
1461
  var autocaptureStarted = false;
1462
+ var MSG_SEL = '[role=alert], [role=status], [aria-live=assertive], [aria-live=polite], [aria-invalid=true]';
1463
+ var MSG_STYLED = /(^|[-_\s])(error|danger|invalid|alert|warning)([-_\s]|$)/i;
1464
+ var MSG_CLASSES = /^(sign_in_again|already_exists|required|invalid_format|not_allowed|not_found|network|try_again|limit_reached|payment)$/;
1465
+ // A control, or anything inside an editable region: what the visitor types, never read as a message.
1466
+ var MSG_TYPED = 'input, textarea, select, [contenteditable]:not([contenteditable="false"]), [role=textbox], [role=searchbox], [role=combobox], .ace_editor, .monaco-editor, .CodeMirror';
1467
+ var uiMessages = null;
1454
1468
  // Set by startAutocapture: sends an open rage burst before the unload path drains the queue.
1455
1469
  var flushOpenSignals = noop;
1456
1470
 
@@ -1574,6 +1588,20 @@ var boot = (function (injectedTag) {
1574
1588
  $nav: nav,
1575
1589
  $load_type: nav === 'load' ? loadTypeOf() : undefined
1576
1590
  });
1591
+ if (msgRules) {
1592
+ msgView = 0;
1593
+ msgCapped = false;
1594
+ msgSeen = {};
1595
+ clearTimeout(msgScanTimer);
1596
+ msgScanTimer = setTimeout(function () {
1597
+ try {
1598
+ msgBudget = 300;
1599
+ msgExamined = typeof WeakMap === 'function' ? new WeakMap() : null;
1600
+ var list = document.querySelectorAll(MSG_SEL);
1601
+ for (var i = 0; i < list.length && msgBudget > 0; i++) msgFound(list[i], nav === 'load' ? 'load' : 'route');
1602
+ } catch (e) {}
1603
+ }, 1500);
1604
+ }
1577
1605
  }
1578
1606
 
1579
1607
  // One page key for every trigger, as sequential.autocapture.ts pageKey.
@@ -1646,7 +1674,7 @@ var boot = (function (injectedTag) {
1646
1674
  return {
1647
1675
  $el_tag_name: tagNameOf(matched),
1648
1676
  $el_selector: cap(selector, EL_SELECTOR_MAX),
1649
- $el_id: matched.id && !noIds ? cap(String(matched.id), EL_ID_MAX) : undefined,
1677
+ $el_id: !noIds && idToken(matched.id) || undefined,
1650
1678
  $el_data: masked || identity ? undefined : dataAttrs(matched, redactor),
1651
1679
  $el_text: raw !== undefined && !identity ? redactor.boundedRedact(raw, CLICK_TEXT_MAX) : undefined,
1652
1680
  $el_label: label && !labelOrHrefIdentity ? redactor.boundedRedact(label, CLICK_TEXT_MAX) : undefined,
@@ -1662,7 +1690,10 @@ var boot = (function (injectedTag) {
1662
1690
  var gestureAt = -1e9;
1663
1691
 
1664
1692
  function onGesture(ev) {
1665
- if (ev.isTrusted) gestureAt = now();
1693
+ if (ev.isTrusted) {
1694
+ gestureAt = now();
1695
+ if (ev.key === 'Enter') openMsg('submit');
1696
+ }
1666
1697
  }
1667
1698
 
1668
1699
  function onClick(ev) {
@@ -1674,6 +1705,7 @@ var boot = (function (injectedTag) {
1674
1705
  var ua = window.navigator.userActivation;
1675
1706
  if (!(ua && ua.isActive) && now() - gestureAt >= 1000) return;
1676
1707
  }
1708
+ openMsg('click');
1677
1709
  var matched = closestMatching(target, INTERACTIVE_SELECTOR);
1678
1710
  if (!matched) return;
1679
1711
  var props = elementProps(matched);
@@ -1696,10 +1728,10 @@ var boot = (function (injectedTag) {
1696
1728
 
1697
1729
  function syncObserver() {
1698
1730
  try {
1699
- if ((rage || dead) && !observer && Observer) {
1731
+ if ((rage || dead || now() < msgUntil) && !observer && Observer) {
1700
1732
  observer = new Observer(onMutations);
1701
1733
  observer.observe(document, { subtree: true, childList: true, attributes: true, attributeOldValue: true, characterData: true });
1702
- } else if (!rage && !dead && observer) {
1734
+ } else if (!rage && !dead && now() >= msgUntil && observer) {
1703
1735
  observer.disconnect();
1704
1736
  observer = null;
1705
1737
  }
@@ -1727,6 +1759,20 @@ var boot = (function (injectedTag) {
1727
1759
 
1728
1760
  function onMutations(records) {
1729
1761
  var own = true;
1762
+ if (now() < msgUntil) {
1763
+ for (var j = 0; j < records.length && j < 100 && msgBudget > 0; j++) {
1764
+ var r = records[j];
1765
+ msgFound(r.target.nodeType === 1 ? r.target : r.target.parentNode, msgAfter);
1766
+ for (var k = 0; k < r.addedNodes.length; k++) {
1767
+ var n = r.addedNodes[k];
1768
+ if (n.nodeType !== 1) continue;
1769
+ msgFound(n, msgAfter);
1770
+ var inner = n.querySelectorAll(MSG_SEL);
1771
+ for (var m = 0; m < inner.length && m < 20 && msgBudget > 0; m++) msgFound(inner[m], msgAfter);
1772
+ }
1773
+ }
1774
+ }
1775
+ if (!rage && !dead) return syncObserver();
1730
1776
  for (var i = 0; i < records.length; i++) {
1731
1777
  if (records[i].type !== 'attributes' || !rage || records[i].target !== rage.el || stateChanged(records[i])) own = false;
1732
1778
  }
@@ -1828,6 +1874,103 @@ var boot = (function (injectedTag) {
1828
1874
  if ((dead || rage) && hasSelection()) effect(false);
1829
1875
  }
1830
1876
 
1877
+ // ── on-screen messages: $ui_message (D1). Rule zero: the text is matched here against the project's patterns (from the
1878
+ // config, off without them) and only the CLASS is sent; no text, no part of it, no hash of it.
1879
+ var msgRules = null;
1880
+ try {
1881
+ if (uiMessages && uiMessages.patterns) {
1882
+ msgRules = [];
1883
+ for (var pi = 0; pi < uiMessages.patterns.length && pi < 50; pi++) {
1884
+ try {
1885
+ msgRules.push([String(uiMessages.patterns[pi][0]), new RegExp(String(uiMessages.patterns[pi][1]).slice(0, 300), 'i')]);
1886
+ } catch (e) {}
1887
+ }
1888
+ }
1889
+ } catch (e) {}
1890
+ var msgUntil = 0;
1891
+ var msgAfter;
1892
+ var msgSeen = {};
1893
+ var msgView = 0;
1894
+ var msgTimes = [];
1895
+ var msgCapped = false;
1896
+ var msgBudget = 0;
1897
+ var msgExamined = null;
1898
+ var msgScanTimer;
1899
+
1900
+ // 3 s after a click, a submit or an Enter, what appears is read.
1901
+ function openMsg(after) {
1902
+ if (!msgRules) return;
1903
+ msgUntil = now() + 3000;
1904
+ msgAfter = after;
1905
+ msgBudget = 300;
1906
+ msgExamined = typeof WeakMap === 'function' ? new WeakMap() : null;
1907
+ syncObserver();
1908
+ setTimeout(syncObserver, 3001);
1909
+ }
1910
+
1911
+ // The click selector's rules (an id only as a token: idToken).
1912
+ function msgNear(el, noIds) {
1913
+ var sel = stableSelector(el, noIds);
1914
+ return DETECT_IDENTITY && namesPerson(sel) ? stableSelector(el, true) : sel;
1915
+ }
1916
+
1917
+ function msgFound(el, after) {
1918
+ try {
1919
+ if (!msgRules || !el || el.nodeType !== 1 || msgBudget-- <= 0) return;
1920
+ var m = closestMatching(el, MSG_SEL);
1921
+ if (!m && MSG_STYLED.test(el.getAttribute('class') || '') && closestMatching(el, 'form')) m = el;
1922
+ if (!m || isMasked(m) || m.isContentEditable || document.designMode === 'on') return;
1923
+ var cls = String(m.getAttribute('class') || '');
1924
+ var role = m.getAttribute('role');
1925
+ var live = m.getAttribute('aria-live');
1926
+ var invalid = m.getAttribute('aria-invalid') === 'true';
1927
+ // A control is never the message (its own text is what was typed); one marked invalid points to its message.
1928
+ if (!invalid && closestMatching(m, MSG_TYPED)) return;
1929
+ var kind = invalid ? 'field_error' : role === 'alert' || live === 'assertive' ? 'alert' : role === 'status' || live === 'polite' ? 'status' : 'field_error';
1930
+ var shown = invalid ? document.getElementById((m.getAttribute('aria-errormessage') || m.getAttribute('aria-describedby') || '').split(' ')[0]) : m;
1931
+ if (!shown || isMasked(shown) || shown.isContentEditable || closestMatching(shown, MSG_TYPED) || shown.querySelector('[data-sq-mask], [data-sq-private]')) return;
1932
+ // The bounded walk of click text: no textarea/select content, no editable or masked part; cut before any rewrite.
1933
+ var text = subtreeText(shown, MSG_TYPED).slice(0, 500).replace(/\s+/g, ' ').replace(/^ | $/g, '').toLowerCase();
1934
+ // Read again only when its text changed ("Saving…" → "Network error" in one window is two messages).
1935
+ if (!text || (msgExamined && msgExamined.get(m) === text)) return;
1936
+ if (msgExamined) msgExamined.set(m, text);
1937
+ var cl = 'other';
1938
+ var t0 = now();
1939
+ for (var i = 0; i < msgRules.length; i++) {
1940
+ if (msgRules[i][1].test(text)) {
1941
+ cl = msgRules[i][0];
1942
+ break;
1943
+ }
1944
+ }
1945
+ // A pattern this slow on this page: no detector for the rest of the page.
1946
+ if (now() - t0 > 5) msgRules = null;
1947
+ if (!MSG_CLASSES.test(cl)) cl = 'other';
1948
+ var near = closestMatching(m, 'form') || (invalid ? m : closestMatching(m, 'dialog, section, main') || m);
1949
+ var props = {
1950
+ $msg_kind: kind,
1951
+ $msg_tone: /error|danger|invalid/i.test(cls) ? 'error' : /warn/i.test(cls) ? 'warning' : /success/i.test(cls) ? 'success' : kind === 'status' ? 'info' : 'error',
1952
+ $msg_class: cl,
1953
+ $msg_near: cap(msgNear(near, near === m), EL_SELECTOR_MAX),
1954
+ $msg_after: after,
1955
+ $msg_len: text.length <= 40 ? 'short' : text.length <= 160 ? 'medium' : 'long'
1956
+ };
1957
+ var t = now();
1958
+ var key = kind + ' ' + props.$msg_near + ' ' + cl;
1959
+ if (msgSeen[key] > t - 10000) return;
1960
+ msgSeen[key] = t;
1961
+ while (msgTimes.length && msgTimes[0] <= t - 60000) msgTimes.shift();
1962
+ // 10 per page view, 30 per minute; past either, one 'capped'.
1963
+ if (msgView >= 10 || msgTimes.length >= 30) {
1964
+ if (msgCapped) return;
1965
+ msgCapped = true;
1966
+ props.$msg_class = 'capped';
1967
+ }
1968
+ msgView++;
1969
+ msgTimes.push(t);
1970
+ captureInternal('$ui_message', props);
1971
+ } catch (e) {}
1972
+ }
1973
+
1831
1974
  function onScroll() {
1832
1975
  if (dead || rage) effect(false);
1833
1976
  }
@@ -1849,10 +1992,11 @@ var boot = (function (injectedTag) {
1849
1992
  try {
1850
1993
  var target = ev && ev.target;
1851
1994
  if (!target || tagNameOf(target) !== 'form') return;
1995
+ openMsg('submit');
1852
1996
 
1853
1997
  captureInternal('$form_submit', {
1854
1998
  $form_selector: cap(stableSelector(target), EL_SELECTOR_MAX),
1855
- form: target.id ? cap(String(target.id), EL_ID_MAX) : undefined
1999
+ form: idToken(target.id) || undefined
1856
2000
  });
1857
2001
  } catch (e) {}
1858
2002
  }
@@ -1861,9 +2005,10 @@ var boot = (function (injectedTag) {
1861
2005
  document.addEventListener('submit', onSubmit, true);
1862
2006
  document.addEventListener('pointerdown', onPointerDown, true);
1863
2007
  document.addEventListener('pointerup', onPointerUp, true);
1864
- document.addEventListener('pointerup', onGesture, true);
1865
- document.addEventListener('touchend', onGesture, true);
1866
- document.addEventListener('keydown', onGesture, true);
2008
+ // Window capture: the first stop of every event, so the gesture is marked before a page handler that clicks (#1173).
2009
+ window.addEventListener('pointerup', onGesture, true);
2010
+ window.addEventListener('touchend', onGesture, true);
2011
+ window.addEventListener('keydown', onGesture, true);
1867
2012
  document.addEventListener('focusin', onFocusIn, true);
1868
2013
  document.addEventListener('selectionchange', onSelectionChange, true);
1869
2014
  document.addEventListener('scroll', onScroll, true);
@@ -2036,6 +2181,7 @@ var boot = (function (injectedTag) {
2036
2181
  syncContextCookie();
2037
2182
  if (config && config.redaction) installRedactor(config.redaction);
2038
2183
 
2184
+ uiMessages = config && config.ui_messages;
2039
2185
  if (AUTOCAPTURE_ENABLED) startAutocapture(attachUrl);
2040
2186
  bootRecorder(config);
2041
2187
  } catch (e) {}
@@ -2070,7 +2216,7 @@ var boot = (function (injectedTag) {
2070
2216
  }
2071
2217
  });
2072
2218
 
2073
- var VERSION = '1.0.3';
2219
+ var VERSION = '1.0.4';
2074
2220
  var running = null;
2075
2221
 
2076
2222
  function logLine(level, message) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usesequential/browser",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "The Sequential browser SDK as an npm package: analytics and session replay, the same code as the script tag.",
5
5
  "keywords": [
6
6
  "sequential",