@usesequential/browser 1.0.3 → 1.0.5
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 +24 -0
- package/dist/index.cjs +169 -12
- package/dist/index.mjs +169 -12
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.5
|
|
4
|
+
|
|
5
|
+
- On-screen messages (`$ui_message`) count only what the person can see. A region that is `display:none`,
|
|
6
|
+
`visibility:hidden` or `collapse`, marked `aria-busy="true"` (still loading), or visually hidden (positioned absolutely or
|
|
7
|
+
fixed and at most 1 pixel wide or high, as `.sr-only` classes do) sends nothing, and text inside such a part of a region is
|
|
8
|
+
not read. A loading skeleton announced to screen readers is no longer sent as a message. Styles are read only for a region
|
|
9
|
+
whose text just changed, never for every element on the page.
|
|
10
|
+
|
|
11
|
+
## 1.0.4
|
|
12
|
+
|
|
13
|
+
- The person's own pointerup, touchend or keydown is noted on the window, before any handler of the page runs. So a click
|
|
14
|
+
that a page's own key or tap handler makes at once (for example on a `role="button"`) is recorded, also on a browser
|
|
15
|
+
without `navigator.userActivation`, when that handler was added before the SDK.
|
|
16
|
+
- On-screen messages (`$ui_message`), off unless the project is switched on by Sequential: for 3 seconds after a click,
|
|
17
|
+
a submit or an Enter, and once 1.5 seconds after a page load or route change, an announced message (`role="alert"`,
|
|
18
|
+
`role="status"`, `aria-live`), a control marked `aria-invalid`, or an error-styled line in a form is sorted into a class
|
|
19
|
+
from the project's patterns. Only the class and structure are sent (kind, tone, the form or section it is near, the
|
|
20
|
+
window, a length band), never the text or any hash of it. Nothing under `data-sq-private` or `data-sq-mask`. At most
|
|
21
|
+
one per message per 10 seconds, 10 per page view and 30 per minute.
|
|
22
|
+
- An element id is sent only when it is a plain token (letters, digits, `_` and `-`, at most 128 characters), in
|
|
23
|
+
`$el_id`, the form's `form` and every selector. An id that holds text (a name, an order number, spaces), a generated
|
|
24
|
+
`: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
|
|
25
|
+
controls start a new case once, from this release.
|
|
26
|
+
|
|
3
27
|
## 1.0.3
|
|
4
28
|
|
|
5
29
|
- 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.
|
|
1
|
+
/* @usesequential/browser 1.0.5: 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,17 @@ var boot = (function (injectedTag) {
|
|
|
1316
1322
|
return !!closestMatching(el, '[data-sq-mask], [data-sq-private]');
|
|
1317
1323
|
}
|
|
1318
1324
|
|
|
1319
|
-
|
|
1325
|
+
// D1 is a message the person SEES: display:none, visibility hidden, aria-busy (still loading), or visually hidden
|
|
1326
|
+
// (absolute/fixed and <= 1px wide or high: .sr-only) is unseen; up: the ancestors too. A loading skeleton is no message.
|
|
1327
|
+
function unseen(el, up) {
|
|
1328
|
+
for (; el && el.nodeType === 1; el = up ? el.parentNode : null) {
|
|
1329
|
+
var s = window.getComputedStyle(el);
|
|
1330
|
+
if (s.display == 'none' || /hid|col/.test(s.visibility) || el.getAttribute('aria-busy') == 'true' || (/^(abs|fix)/.test(s.position) && (parseFloat(s.width) <= 1 || parseFloat(s.height) <= 1))) return 1;
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
// skip (the message detector's MSG_TYPED): also leave out what matches it, what the browser says is editable, or unseen.
|
|
1335
|
+
function subtreeText(el, skip) {
|
|
1320
1336
|
var out = '';
|
|
1321
1337
|
function visit(node) {
|
|
1322
1338
|
for (var child = node.firstChild; child !== null; child = child.nextSibling) {
|
|
@@ -1329,6 +1345,7 @@ var boot = (function (injectedTag) {
|
|
|
1329
1345
|
if (inList(TEXT_OPAQUE_TAGS, tagNameOf(child))) continue;
|
|
1330
1346
|
if (isEditable(child)) continue;
|
|
1331
1347
|
if (child.hasAttribute && (child.hasAttribute('data-sq-mask') || child.hasAttribute('data-sq-private'))) continue;
|
|
1348
|
+
if (skip && (child.isContentEditable === true || matchesSelector(child, skip) || unseen(child))) continue;
|
|
1332
1349
|
visit(child);
|
|
1333
1350
|
}
|
|
1334
1351
|
}
|
|
@@ -1402,7 +1419,7 @@ var boot = (function (injectedTag) {
|
|
|
1402
1419
|
var node = el;
|
|
1403
1420
|
var root = document.documentElement;
|
|
1404
1421
|
while (node && node !== root && node.nodeType === 1) {
|
|
1405
|
-
if (node.id
|
|
1422
|
+
if (!noIds && idToken(node.id)) {
|
|
1406
1423
|
parts.unshift('#' + node.id);
|
|
1407
1424
|
break;
|
|
1408
1425
|
}
|
|
@@ -1452,6 +1469,12 @@ var boot = (function (injectedTag) {
|
|
|
1452
1469
|
}
|
|
1453
1470
|
|
|
1454
1471
|
var autocaptureStarted = false;
|
|
1472
|
+
var MSG_SEL = '[role=alert], [role=status], [aria-live=assertive], [aria-live=polite], [aria-invalid=true]';
|
|
1473
|
+
var MSG_STYLED = /(^|[-_\s])(error|danger|invalid|alert|warning)([-_\s]|$)/i;
|
|
1474
|
+
var MSG_CLASSES = /^(sign_in_again|already_exists|required|invalid_format|not_allowed|not_found|network|try_again|limit_reached|payment)$/;
|
|
1475
|
+
// A control, or anything inside an editable region: what the visitor types, never read as a message.
|
|
1476
|
+
var MSG_TYPED = 'input, textarea, select, [contenteditable]:not([contenteditable="false"]), [role=textbox], [role=searchbox], [role=combobox], .ace_editor, .monaco-editor, .CodeMirror';
|
|
1477
|
+
var uiMessages = null;
|
|
1455
1478
|
// Set by startAutocapture: sends an open rage burst before the unload path drains the queue.
|
|
1456
1479
|
var flushOpenSignals = noop;
|
|
1457
1480
|
|
|
@@ -1575,6 +1598,20 @@ var boot = (function (injectedTag) {
|
|
|
1575
1598
|
$nav: nav,
|
|
1576
1599
|
$load_type: nav === 'load' ? loadTypeOf() : undefined
|
|
1577
1600
|
});
|
|
1601
|
+
if (msgRules) {
|
|
1602
|
+
msgView = 0;
|
|
1603
|
+
msgCapped = false;
|
|
1604
|
+
msgSeen = {};
|
|
1605
|
+
clearTimeout(msgScanTimer);
|
|
1606
|
+
msgScanTimer = setTimeout(function () {
|
|
1607
|
+
try {
|
|
1608
|
+
msgBudget = 300;
|
|
1609
|
+
msgExamined = typeof WeakMap === 'function' ? new WeakMap() : null;
|
|
1610
|
+
var list = document.querySelectorAll(MSG_SEL);
|
|
1611
|
+
for (var i = 0; i < list.length && msgBudget > 0; i++) msgFound(list[i], nav === 'load' ? 'load' : 'route');
|
|
1612
|
+
} catch (e) {}
|
|
1613
|
+
}, 1500);
|
|
1614
|
+
}
|
|
1578
1615
|
}
|
|
1579
1616
|
|
|
1580
1617
|
// One page key for every trigger, as sequential.autocapture.ts pageKey.
|
|
@@ -1647,7 +1684,7 @@ var boot = (function (injectedTag) {
|
|
|
1647
1684
|
return {
|
|
1648
1685
|
$el_tag_name: tagNameOf(matched),
|
|
1649
1686
|
$el_selector: cap(selector, EL_SELECTOR_MAX),
|
|
1650
|
-
$el_id:
|
|
1687
|
+
$el_id: !noIds && idToken(matched.id) || undefined,
|
|
1651
1688
|
$el_data: masked || identity ? undefined : dataAttrs(matched, redactor),
|
|
1652
1689
|
$el_text: raw !== undefined && !identity ? redactor.boundedRedact(raw, CLICK_TEXT_MAX) : undefined,
|
|
1653
1690
|
$el_label: label && !labelOrHrefIdentity ? redactor.boundedRedact(label, CLICK_TEXT_MAX) : undefined,
|
|
@@ -1663,7 +1700,10 @@ var boot = (function (injectedTag) {
|
|
|
1663
1700
|
var gestureAt = -1e9;
|
|
1664
1701
|
|
|
1665
1702
|
function onGesture(ev) {
|
|
1666
|
-
if (ev.isTrusted)
|
|
1703
|
+
if (ev.isTrusted) {
|
|
1704
|
+
gestureAt = now();
|
|
1705
|
+
if (ev.key === 'Enter') openMsg('submit');
|
|
1706
|
+
}
|
|
1667
1707
|
}
|
|
1668
1708
|
|
|
1669
1709
|
function onClick(ev) {
|
|
@@ -1675,6 +1715,7 @@ var boot = (function (injectedTag) {
|
|
|
1675
1715
|
var ua = window.navigator.userActivation;
|
|
1676
1716
|
if (!(ua && ua.isActive) && now() - gestureAt >= 1000) return;
|
|
1677
1717
|
}
|
|
1718
|
+
openMsg('click');
|
|
1678
1719
|
var matched = closestMatching(target, INTERACTIVE_SELECTOR);
|
|
1679
1720
|
if (!matched) return;
|
|
1680
1721
|
var props = elementProps(matched);
|
|
@@ -1697,10 +1738,10 @@ var boot = (function (injectedTag) {
|
|
|
1697
1738
|
|
|
1698
1739
|
function syncObserver() {
|
|
1699
1740
|
try {
|
|
1700
|
-
if ((rage || dead) && !observer && Observer) {
|
|
1741
|
+
if ((rage || dead || now() < msgUntil) && !observer && Observer) {
|
|
1701
1742
|
observer = new Observer(onMutations);
|
|
1702
1743
|
observer.observe(document, { subtree: true, childList: true, attributes: true, attributeOldValue: true, characterData: true });
|
|
1703
|
-
} else if (!rage && !dead && observer) {
|
|
1744
|
+
} else if (!rage && !dead && now() >= msgUntil && observer) {
|
|
1704
1745
|
observer.disconnect();
|
|
1705
1746
|
observer = null;
|
|
1706
1747
|
}
|
|
@@ -1728,6 +1769,20 @@ var boot = (function (injectedTag) {
|
|
|
1728
1769
|
|
|
1729
1770
|
function onMutations(records) {
|
|
1730
1771
|
var own = true;
|
|
1772
|
+
if (now() < msgUntil) {
|
|
1773
|
+
for (var j = 0; j < records.length && j < 100 && msgBudget > 0; j++) {
|
|
1774
|
+
var r = records[j];
|
|
1775
|
+
msgFound(r.target.nodeType === 1 ? r.target : r.target.parentNode, msgAfter);
|
|
1776
|
+
for (var k = 0; k < r.addedNodes.length; k++) {
|
|
1777
|
+
var n = r.addedNodes[k];
|
|
1778
|
+
if (n.nodeType !== 1) continue;
|
|
1779
|
+
msgFound(n, msgAfter);
|
|
1780
|
+
var inner = n.querySelectorAll(MSG_SEL);
|
|
1781
|
+
for (var m = 0; m < inner.length && m < 20 && msgBudget > 0; m++) msgFound(inner[m], msgAfter);
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
if (!rage && !dead) return syncObserver();
|
|
1731
1786
|
for (var i = 0; i < records.length; i++) {
|
|
1732
1787
|
if (records[i].type !== 'attributes' || !rage || records[i].target !== rage.el || stateChanged(records[i])) own = false;
|
|
1733
1788
|
}
|
|
@@ -1829,6 +1884,105 @@ var boot = (function (injectedTag) {
|
|
|
1829
1884
|
if ((dead || rage) && hasSelection()) effect(false);
|
|
1830
1885
|
}
|
|
1831
1886
|
|
|
1887
|
+
// ── on-screen messages: $ui_message (D1). Rule zero: the text is matched here against the project's patterns (from the
|
|
1888
|
+
// config, off without them) and only the CLASS is sent; no text, no part of it, no hash of it.
|
|
1889
|
+
var msgRules = null;
|
|
1890
|
+
try {
|
|
1891
|
+
if (uiMessages && uiMessages.patterns) {
|
|
1892
|
+
msgRules = [];
|
|
1893
|
+
for (var pi = 0; pi < uiMessages.patterns.length && pi < 50; pi++) {
|
|
1894
|
+
try {
|
|
1895
|
+
msgRules.push([String(uiMessages.patterns[pi][0]), new RegExp(String(uiMessages.patterns[pi][1]).slice(0, 300), 'i')]);
|
|
1896
|
+
} catch (e) {}
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
} catch (e) {}
|
|
1900
|
+
var msgUntil = 0;
|
|
1901
|
+
var msgAfter;
|
|
1902
|
+
var msgSeen = {};
|
|
1903
|
+
var msgView = 0;
|
|
1904
|
+
var msgTimes = [];
|
|
1905
|
+
var msgCapped = false;
|
|
1906
|
+
var msgBudget = 0;
|
|
1907
|
+
var msgExamined = null;
|
|
1908
|
+
var msgScanTimer;
|
|
1909
|
+
|
|
1910
|
+
// 3 s after a click, a submit or an Enter, what appears is read.
|
|
1911
|
+
function openMsg(after) {
|
|
1912
|
+
if (!msgRules) return;
|
|
1913
|
+
msgUntil = now() + 3000;
|
|
1914
|
+
msgAfter = after;
|
|
1915
|
+
msgBudget = 300;
|
|
1916
|
+
msgExamined = typeof WeakMap === 'function' ? new WeakMap() : null;
|
|
1917
|
+
syncObserver();
|
|
1918
|
+
setTimeout(syncObserver, 3001);
|
|
1919
|
+
}
|
|
1920
|
+
|
|
1921
|
+
// The click selector's rules (an id only as a token: idToken).
|
|
1922
|
+
function msgNear(el, noIds) {
|
|
1923
|
+
var sel = stableSelector(el, noIds);
|
|
1924
|
+
return DETECT_IDENTITY && namesPerson(sel) ? stableSelector(el, true) : sel;
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1927
|
+
function msgFound(el, after) {
|
|
1928
|
+
try {
|
|
1929
|
+
if (!msgRules || !el || el.nodeType !== 1 || msgBudget-- <= 0) return;
|
|
1930
|
+
var m = closestMatching(el, MSG_SEL);
|
|
1931
|
+
if (!m && MSG_STYLED.test(el.getAttribute('class') || '') && closestMatching(el, 'form')) m = el;
|
|
1932
|
+
if (!m || isMasked(m) || m.isContentEditable || document.designMode === 'on') return;
|
|
1933
|
+
var cls = String(m.getAttribute('class') || '');
|
|
1934
|
+
var role = m.getAttribute('role');
|
|
1935
|
+
var live = m.getAttribute('aria-live');
|
|
1936
|
+
var invalid = m.getAttribute('aria-invalid') === 'true';
|
|
1937
|
+
// A control is never the message (its own text is what was typed); one marked invalid points to its message.
|
|
1938
|
+
if (!invalid && closestMatching(m, MSG_TYPED)) return;
|
|
1939
|
+
var kind = invalid ? 'field_error' : role === 'alert' || live === 'assertive' ? 'alert' : role === 'status' || live === 'polite' ? 'status' : 'field_error';
|
|
1940
|
+
var shown = invalid ? document.getElementById((m.getAttribute('aria-errormessage') || m.getAttribute('aria-describedby') || '').split(' ')[0]) : m;
|
|
1941
|
+
if (!shown || isMasked(shown) || shown.isContentEditable || closestMatching(shown, MSG_TYPED) || shown.querySelector('[data-sq-mask], [data-sq-private]')) return;
|
|
1942
|
+
// The bounded walk of click text: no textarea/select content, no editable or masked part; cut before any rewrite.
|
|
1943
|
+
var text = subtreeText(shown, MSG_TYPED).slice(0, 500).replace(/\s+/g, ' ').replace(/^ | $/g, '').toLowerCase();
|
|
1944
|
+
// Read again only when its text changed ("Saving…" → "Network error" in one window is two messages).
|
|
1945
|
+
if (!text || (msgExamined && msgExamined.get(m) === text)) return;
|
|
1946
|
+
if (msgExamined) msgExamined.set(m, text);
|
|
1947
|
+
// Only now, for a candidate with new text: is the region itself seen (its ancestors' styles, once per new text)?
|
|
1948
|
+
if (unseen(shown, 1)) return;
|
|
1949
|
+
var cl = 'other';
|
|
1950
|
+
var t0 = now();
|
|
1951
|
+
for (var i = 0; i < msgRules.length; i++) {
|
|
1952
|
+
if (msgRules[i][1].test(text)) {
|
|
1953
|
+
cl = msgRules[i][0];
|
|
1954
|
+
break;
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
// A pattern this slow on this page: no detector for the rest of the page.
|
|
1958
|
+
if (now() - t0 > 5) msgRules = null;
|
|
1959
|
+
if (!MSG_CLASSES.test(cl)) cl = 'other';
|
|
1960
|
+
var near = closestMatching(m, 'form') || (invalid ? m : closestMatching(m, 'dialog, section, main') || m);
|
|
1961
|
+
var props = {
|
|
1962
|
+
$msg_kind: kind,
|
|
1963
|
+
$msg_tone: /error|danger|invalid/i.test(cls) ? 'error' : /warn/i.test(cls) ? 'warning' : /success/i.test(cls) ? 'success' : kind === 'status' ? 'info' : 'error',
|
|
1964
|
+
$msg_class: cl,
|
|
1965
|
+
$msg_near: cap(msgNear(near, near === m), EL_SELECTOR_MAX),
|
|
1966
|
+
$msg_after: after,
|
|
1967
|
+
$msg_len: text.length <= 40 ? 'short' : text.length <= 160 ? 'medium' : 'long'
|
|
1968
|
+
};
|
|
1969
|
+
var t = now();
|
|
1970
|
+
var key = kind + ' ' + props.$msg_near + ' ' + cl;
|
|
1971
|
+
if (msgSeen[key] > t - 10000) return;
|
|
1972
|
+
msgSeen[key] = t;
|
|
1973
|
+
while (msgTimes.length && msgTimes[0] <= t - 60000) msgTimes.shift();
|
|
1974
|
+
// 10 per page view, 30 per minute; past either, one 'capped'.
|
|
1975
|
+
if (msgView >= 10 || msgTimes.length >= 30) {
|
|
1976
|
+
if (msgCapped) return;
|
|
1977
|
+
msgCapped = true;
|
|
1978
|
+
props.$msg_class = 'capped';
|
|
1979
|
+
}
|
|
1980
|
+
msgView++;
|
|
1981
|
+
msgTimes.push(t);
|
|
1982
|
+
captureInternal('$ui_message', props);
|
|
1983
|
+
} catch (e) {}
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1832
1986
|
function onScroll() {
|
|
1833
1987
|
if (dead || rage) effect(false);
|
|
1834
1988
|
}
|
|
@@ -1850,10 +2004,11 @@ var boot = (function (injectedTag) {
|
|
|
1850
2004
|
try {
|
|
1851
2005
|
var target = ev && ev.target;
|
|
1852
2006
|
if (!target || tagNameOf(target) !== 'form') return;
|
|
2007
|
+
openMsg('submit');
|
|
1853
2008
|
|
|
1854
2009
|
captureInternal('$form_submit', {
|
|
1855
2010
|
$form_selector: cap(stableSelector(target), EL_SELECTOR_MAX),
|
|
1856
|
-
form:
|
|
2011
|
+
form: idToken(target.id) || undefined
|
|
1857
2012
|
});
|
|
1858
2013
|
} catch (e) {}
|
|
1859
2014
|
}
|
|
@@ -1862,9 +2017,10 @@ var boot = (function (injectedTag) {
|
|
|
1862
2017
|
document.addEventListener('submit', onSubmit, true);
|
|
1863
2018
|
document.addEventListener('pointerdown', onPointerDown, true);
|
|
1864
2019
|
document.addEventListener('pointerup', onPointerUp, true);
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
2020
|
+
// Window capture: the first stop of every event, so the gesture is marked before a page handler that clicks (#1173).
|
|
2021
|
+
window.addEventListener('pointerup', onGesture, true);
|
|
2022
|
+
window.addEventListener('touchend', onGesture, true);
|
|
2023
|
+
window.addEventListener('keydown', onGesture, true);
|
|
1868
2024
|
document.addEventListener('focusin', onFocusIn, true);
|
|
1869
2025
|
document.addEventListener('selectionchange', onSelectionChange, true);
|
|
1870
2026
|
document.addEventListener('scroll', onScroll, true);
|
|
@@ -2037,6 +2193,7 @@ var boot = (function (injectedTag) {
|
|
|
2037
2193
|
syncContextCookie();
|
|
2038
2194
|
if (config && config.redaction) installRedactor(config.redaction);
|
|
2039
2195
|
|
|
2196
|
+
uiMessages = config && config.ui_messages;
|
|
2040
2197
|
if (AUTOCAPTURE_ENABLED) startAutocapture(attachUrl);
|
|
2041
2198
|
bootRecorder(config);
|
|
2042
2199
|
} catch (e) {}
|
|
@@ -2071,7 +2228,7 @@ var boot = (function (injectedTag) {
|
|
|
2071
2228
|
}
|
|
2072
2229
|
});
|
|
2073
2230
|
|
|
2074
|
-
var VERSION = '1.0.
|
|
2231
|
+
var VERSION = '1.0.5';
|
|
2075
2232
|
var running = null;
|
|
2076
2233
|
|
|
2077
2234
|
function logLine(level, message) {
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @usesequential/browser 1.0.
|
|
1
|
+
/* @usesequential/browser 1.0.5: 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,17 @@ var boot = (function (injectedTag) {
|
|
|
1315
1321
|
return !!closestMatching(el, '[data-sq-mask], [data-sq-private]');
|
|
1316
1322
|
}
|
|
1317
1323
|
|
|
1318
|
-
|
|
1324
|
+
// D1 is a message the person SEES: display:none, visibility hidden, aria-busy (still loading), or visually hidden
|
|
1325
|
+
// (absolute/fixed and <= 1px wide or high: .sr-only) is unseen; up: the ancestors too. A loading skeleton is no message.
|
|
1326
|
+
function unseen(el, up) {
|
|
1327
|
+
for (; el && el.nodeType === 1; el = up ? el.parentNode : null) {
|
|
1328
|
+
var s = window.getComputedStyle(el);
|
|
1329
|
+
if (s.display == 'none' || /hid|col/.test(s.visibility) || el.getAttribute('aria-busy') == 'true' || (/^(abs|fix)/.test(s.position) && (parseFloat(s.width) <= 1 || parseFloat(s.height) <= 1))) return 1;
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
// skip (the message detector's MSG_TYPED): also leave out what matches it, what the browser says is editable, or unseen.
|
|
1334
|
+
function subtreeText(el, skip) {
|
|
1319
1335
|
var out = '';
|
|
1320
1336
|
function visit(node) {
|
|
1321
1337
|
for (var child = node.firstChild; child !== null; child = child.nextSibling) {
|
|
@@ -1328,6 +1344,7 @@ var boot = (function (injectedTag) {
|
|
|
1328
1344
|
if (inList(TEXT_OPAQUE_TAGS, tagNameOf(child))) continue;
|
|
1329
1345
|
if (isEditable(child)) continue;
|
|
1330
1346
|
if (child.hasAttribute && (child.hasAttribute('data-sq-mask') || child.hasAttribute('data-sq-private'))) continue;
|
|
1347
|
+
if (skip && (child.isContentEditable === true || matchesSelector(child, skip) || unseen(child))) continue;
|
|
1331
1348
|
visit(child);
|
|
1332
1349
|
}
|
|
1333
1350
|
}
|
|
@@ -1401,7 +1418,7 @@ var boot = (function (injectedTag) {
|
|
|
1401
1418
|
var node = el;
|
|
1402
1419
|
var root = document.documentElement;
|
|
1403
1420
|
while (node && node !== root && node.nodeType === 1) {
|
|
1404
|
-
if (node.id
|
|
1421
|
+
if (!noIds && idToken(node.id)) {
|
|
1405
1422
|
parts.unshift('#' + node.id);
|
|
1406
1423
|
break;
|
|
1407
1424
|
}
|
|
@@ -1451,6 +1468,12 @@ var boot = (function (injectedTag) {
|
|
|
1451
1468
|
}
|
|
1452
1469
|
|
|
1453
1470
|
var autocaptureStarted = false;
|
|
1471
|
+
var MSG_SEL = '[role=alert], [role=status], [aria-live=assertive], [aria-live=polite], [aria-invalid=true]';
|
|
1472
|
+
var MSG_STYLED = /(^|[-_\s])(error|danger|invalid|alert|warning)([-_\s]|$)/i;
|
|
1473
|
+
var MSG_CLASSES = /^(sign_in_again|already_exists|required|invalid_format|not_allowed|not_found|network|try_again|limit_reached|payment)$/;
|
|
1474
|
+
// A control, or anything inside an editable region: what the visitor types, never read as a message.
|
|
1475
|
+
var MSG_TYPED = 'input, textarea, select, [contenteditable]:not([contenteditable="false"]), [role=textbox], [role=searchbox], [role=combobox], .ace_editor, .monaco-editor, .CodeMirror';
|
|
1476
|
+
var uiMessages = null;
|
|
1454
1477
|
// Set by startAutocapture: sends an open rage burst before the unload path drains the queue.
|
|
1455
1478
|
var flushOpenSignals = noop;
|
|
1456
1479
|
|
|
@@ -1574,6 +1597,20 @@ var boot = (function (injectedTag) {
|
|
|
1574
1597
|
$nav: nav,
|
|
1575
1598
|
$load_type: nav === 'load' ? loadTypeOf() : undefined
|
|
1576
1599
|
});
|
|
1600
|
+
if (msgRules) {
|
|
1601
|
+
msgView = 0;
|
|
1602
|
+
msgCapped = false;
|
|
1603
|
+
msgSeen = {};
|
|
1604
|
+
clearTimeout(msgScanTimer);
|
|
1605
|
+
msgScanTimer = setTimeout(function () {
|
|
1606
|
+
try {
|
|
1607
|
+
msgBudget = 300;
|
|
1608
|
+
msgExamined = typeof WeakMap === 'function' ? new WeakMap() : null;
|
|
1609
|
+
var list = document.querySelectorAll(MSG_SEL);
|
|
1610
|
+
for (var i = 0; i < list.length && msgBudget > 0; i++) msgFound(list[i], nav === 'load' ? 'load' : 'route');
|
|
1611
|
+
} catch (e) {}
|
|
1612
|
+
}, 1500);
|
|
1613
|
+
}
|
|
1577
1614
|
}
|
|
1578
1615
|
|
|
1579
1616
|
// One page key for every trigger, as sequential.autocapture.ts pageKey.
|
|
@@ -1646,7 +1683,7 @@ var boot = (function (injectedTag) {
|
|
|
1646
1683
|
return {
|
|
1647
1684
|
$el_tag_name: tagNameOf(matched),
|
|
1648
1685
|
$el_selector: cap(selector, EL_SELECTOR_MAX),
|
|
1649
|
-
$el_id:
|
|
1686
|
+
$el_id: !noIds && idToken(matched.id) || undefined,
|
|
1650
1687
|
$el_data: masked || identity ? undefined : dataAttrs(matched, redactor),
|
|
1651
1688
|
$el_text: raw !== undefined && !identity ? redactor.boundedRedact(raw, CLICK_TEXT_MAX) : undefined,
|
|
1652
1689
|
$el_label: label && !labelOrHrefIdentity ? redactor.boundedRedact(label, CLICK_TEXT_MAX) : undefined,
|
|
@@ -1662,7 +1699,10 @@ var boot = (function (injectedTag) {
|
|
|
1662
1699
|
var gestureAt = -1e9;
|
|
1663
1700
|
|
|
1664
1701
|
function onGesture(ev) {
|
|
1665
|
-
if (ev.isTrusted)
|
|
1702
|
+
if (ev.isTrusted) {
|
|
1703
|
+
gestureAt = now();
|
|
1704
|
+
if (ev.key === 'Enter') openMsg('submit');
|
|
1705
|
+
}
|
|
1666
1706
|
}
|
|
1667
1707
|
|
|
1668
1708
|
function onClick(ev) {
|
|
@@ -1674,6 +1714,7 @@ var boot = (function (injectedTag) {
|
|
|
1674
1714
|
var ua = window.navigator.userActivation;
|
|
1675
1715
|
if (!(ua && ua.isActive) && now() - gestureAt >= 1000) return;
|
|
1676
1716
|
}
|
|
1717
|
+
openMsg('click');
|
|
1677
1718
|
var matched = closestMatching(target, INTERACTIVE_SELECTOR);
|
|
1678
1719
|
if (!matched) return;
|
|
1679
1720
|
var props = elementProps(matched);
|
|
@@ -1696,10 +1737,10 @@ var boot = (function (injectedTag) {
|
|
|
1696
1737
|
|
|
1697
1738
|
function syncObserver() {
|
|
1698
1739
|
try {
|
|
1699
|
-
if ((rage || dead) && !observer && Observer) {
|
|
1740
|
+
if ((rage || dead || now() < msgUntil) && !observer && Observer) {
|
|
1700
1741
|
observer = new Observer(onMutations);
|
|
1701
1742
|
observer.observe(document, { subtree: true, childList: true, attributes: true, attributeOldValue: true, characterData: true });
|
|
1702
|
-
} else if (!rage && !dead && observer) {
|
|
1743
|
+
} else if (!rage && !dead && now() >= msgUntil && observer) {
|
|
1703
1744
|
observer.disconnect();
|
|
1704
1745
|
observer = null;
|
|
1705
1746
|
}
|
|
@@ -1727,6 +1768,20 @@ var boot = (function (injectedTag) {
|
|
|
1727
1768
|
|
|
1728
1769
|
function onMutations(records) {
|
|
1729
1770
|
var own = true;
|
|
1771
|
+
if (now() < msgUntil) {
|
|
1772
|
+
for (var j = 0; j < records.length && j < 100 && msgBudget > 0; j++) {
|
|
1773
|
+
var r = records[j];
|
|
1774
|
+
msgFound(r.target.nodeType === 1 ? r.target : r.target.parentNode, msgAfter);
|
|
1775
|
+
for (var k = 0; k < r.addedNodes.length; k++) {
|
|
1776
|
+
var n = r.addedNodes[k];
|
|
1777
|
+
if (n.nodeType !== 1) continue;
|
|
1778
|
+
msgFound(n, msgAfter);
|
|
1779
|
+
var inner = n.querySelectorAll(MSG_SEL);
|
|
1780
|
+
for (var m = 0; m < inner.length && m < 20 && msgBudget > 0; m++) msgFound(inner[m], msgAfter);
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
if (!rage && !dead) return syncObserver();
|
|
1730
1785
|
for (var i = 0; i < records.length; i++) {
|
|
1731
1786
|
if (records[i].type !== 'attributes' || !rage || records[i].target !== rage.el || stateChanged(records[i])) own = false;
|
|
1732
1787
|
}
|
|
@@ -1828,6 +1883,105 @@ var boot = (function (injectedTag) {
|
|
|
1828
1883
|
if ((dead || rage) && hasSelection()) effect(false);
|
|
1829
1884
|
}
|
|
1830
1885
|
|
|
1886
|
+
// ── on-screen messages: $ui_message (D1). Rule zero: the text is matched here against the project's patterns (from the
|
|
1887
|
+
// config, off without them) and only the CLASS is sent; no text, no part of it, no hash of it.
|
|
1888
|
+
var msgRules = null;
|
|
1889
|
+
try {
|
|
1890
|
+
if (uiMessages && uiMessages.patterns) {
|
|
1891
|
+
msgRules = [];
|
|
1892
|
+
for (var pi = 0; pi < uiMessages.patterns.length && pi < 50; pi++) {
|
|
1893
|
+
try {
|
|
1894
|
+
msgRules.push([String(uiMessages.patterns[pi][0]), new RegExp(String(uiMessages.patterns[pi][1]).slice(0, 300), 'i')]);
|
|
1895
|
+
} catch (e) {}
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
} catch (e) {}
|
|
1899
|
+
var msgUntil = 0;
|
|
1900
|
+
var msgAfter;
|
|
1901
|
+
var msgSeen = {};
|
|
1902
|
+
var msgView = 0;
|
|
1903
|
+
var msgTimes = [];
|
|
1904
|
+
var msgCapped = false;
|
|
1905
|
+
var msgBudget = 0;
|
|
1906
|
+
var msgExamined = null;
|
|
1907
|
+
var msgScanTimer;
|
|
1908
|
+
|
|
1909
|
+
// 3 s after a click, a submit or an Enter, what appears is read.
|
|
1910
|
+
function openMsg(after) {
|
|
1911
|
+
if (!msgRules) return;
|
|
1912
|
+
msgUntil = now() + 3000;
|
|
1913
|
+
msgAfter = after;
|
|
1914
|
+
msgBudget = 300;
|
|
1915
|
+
msgExamined = typeof WeakMap === 'function' ? new WeakMap() : null;
|
|
1916
|
+
syncObserver();
|
|
1917
|
+
setTimeout(syncObserver, 3001);
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
// The click selector's rules (an id only as a token: idToken).
|
|
1921
|
+
function msgNear(el, noIds) {
|
|
1922
|
+
var sel = stableSelector(el, noIds);
|
|
1923
|
+
return DETECT_IDENTITY && namesPerson(sel) ? stableSelector(el, true) : sel;
|
|
1924
|
+
}
|
|
1925
|
+
|
|
1926
|
+
function msgFound(el, after) {
|
|
1927
|
+
try {
|
|
1928
|
+
if (!msgRules || !el || el.nodeType !== 1 || msgBudget-- <= 0) return;
|
|
1929
|
+
var m = closestMatching(el, MSG_SEL);
|
|
1930
|
+
if (!m && MSG_STYLED.test(el.getAttribute('class') || '') && closestMatching(el, 'form')) m = el;
|
|
1931
|
+
if (!m || isMasked(m) || m.isContentEditable || document.designMode === 'on') return;
|
|
1932
|
+
var cls = String(m.getAttribute('class') || '');
|
|
1933
|
+
var role = m.getAttribute('role');
|
|
1934
|
+
var live = m.getAttribute('aria-live');
|
|
1935
|
+
var invalid = m.getAttribute('aria-invalid') === 'true';
|
|
1936
|
+
// A control is never the message (its own text is what was typed); one marked invalid points to its message.
|
|
1937
|
+
if (!invalid && closestMatching(m, MSG_TYPED)) return;
|
|
1938
|
+
var kind = invalid ? 'field_error' : role === 'alert' || live === 'assertive' ? 'alert' : role === 'status' || live === 'polite' ? 'status' : 'field_error';
|
|
1939
|
+
var shown = invalid ? document.getElementById((m.getAttribute('aria-errormessage') || m.getAttribute('aria-describedby') || '').split(' ')[0]) : m;
|
|
1940
|
+
if (!shown || isMasked(shown) || shown.isContentEditable || closestMatching(shown, MSG_TYPED) || shown.querySelector('[data-sq-mask], [data-sq-private]')) return;
|
|
1941
|
+
// The bounded walk of click text: no textarea/select content, no editable or masked part; cut before any rewrite.
|
|
1942
|
+
var text = subtreeText(shown, MSG_TYPED).slice(0, 500).replace(/\s+/g, ' ').replace(/^ | $/g, '').toLowerCase();
|
|
1943
|
+
// Read again only when its text changed ("Saving…" → "Network error" in one window is two messages).
|
|
1944
|
+
if (!text || (msgExamined && msgExamined.get(m) === text)) return;
|
|
1945
|
+
if (msgExamined) msgExamined.set(m, text);
|
|
1946
|
+
// Only now, for a candidate with new text: is the region itself seen (its ancestors' styles, once per new text)?
|
|
1947
|
+
if (unseen(shown, 1)) return;
|
|
1948
|
+
var cl = 'other';
|
|
1949
|
+
var t0 = now();
|
|
1950
|
+
for (var i = 0; i < msgRules.length; i++) {
|
|
1951
|
+
if (msgRules[i][1].test(text)) {
|
|
1952
|
+
cl = msgRules[i][0];
|
|
1953
|
+
break;
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
// A pattern this slow on this page: no detector for the rest of the page.
|
|
1957
|
+
if (now() - t0 > 5) msgRules = null;
|
|
1958
|
+
if (!MSG_CLASSES.test(cl)) cl = 'other';
|
|
1959
|
+
var near = closestMatching(m, 'form') || (invalid ? m : closestMatching(m, 'dialog, section, main') || m);
|
|
1960
|
+
var props = {
|
|
1961
|
+
$msg_kind: kind,
|
|
1962
|
+
$msg_tone: /error|danger|invalid/i.test(cls) ? 'error' : /warn/i.test(cls) ? 'warning' : /success/i.test(cls) ? 'success' : kind === 'status' ? 'info' : 'error',
|
|
1963
|
+
$msg_class: cl,
|
|
1964
|
+
$msg_near: cap(msgNear(near, near === m), EL_SELECTOR_MAX),
|
|
1965
|
+
$msg_after: after,
|
|
1966
|
+
$msg_len: text.length <= 40 ? 'short' : text.length <= 160 ? 'medium' : 'long'
|
|
1967
|
+
};
|
|
1968
|
+
var t = now();
|
|
1969
|
+
var key = kind + ' ' + props.$msg_near + ' ' + cl;
|
|
1970
|
+
if (msgSeen[key] > t - 10000) return;
|
|
1971
|
+
msgSeen[key] = t;
|
|
1972
|
+
while (msgTimes.length && msgTimes[0] <= t - 60000) msgTimes.shift();
|
|
1973
|
+
// 10 per page view, 30 per minute; past either, one 'capped'.
|
|
1974
|
+
if (msgView >= 10 || msgTimes.length >= 30) {
|
|
1975
|
+
if (msgCapped) return;
|
|
1976
|
+
msgCapped = true;
|
|
1977
|
+
props.$msg_class = 'capped';
|
|
1978
|
+
}
|
|
1979
|
+
msgView++;
|
|
1980
|
+
msgTimes.push(t);
|
|
1981
|
+
captureInternal('$ui_message', props);
|
|
1982
|
+
} catch (e) {}
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1831
1985
|
function onScroll() {
|
|
1832
1986
|
if (dead || rage) effect(false);
|
|
1833
1987
|
}
|
|
@@ -1849,10 +2003,11 @@ var boot = (function (injectedTag) {
|
|
|
1849
2003
|
try {
|
|
1850
2004
|
var target = ev && ev.target;
|
|
1851
2005
|
if (!target || tagNameOf(target) !== 'form') return;
|
|
2006
|
+
openMsg('submit');
|
|
1852
2007
|
|
|
1853
2008
|
captureInternal('$form_submit', {
|
|
1854
2009
|
$form_selector: cap(stableSelector(target), EL_SELECTOR_MAX),
|
|
1855
|
-
form:
|
|
2010
|
+
form: idToken(target.id) || undefined
|
|
1856
2011
|
});
|
|
1857
2012
|
} catch (e) {}
|
|
1858
2013
|
}
|
|
@@ -1861,9 +2016,10 @@ var boot = (function (injectedTag) {
|
|
|
1861
2016
|
document.addEventListener('submit', onSubmit, true);
|
|
1862
2017
|
document.addEventListener('pointerdown', onPointerDown, true);
|
|
1863
2018
|
document.addEventListener('pointerup', onPointerUp, true);
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
2019
|
+
// Window capture: the first stop of every event, so the gesture is marked before a page handler that clicks (#1173).
|
|
2020
|
+
window.addEventListener('pointerup', onGesture, true);
|
|
2021
|
+
window.addEventListener('touchend', onGesture, true);
|
|
2022
|
+
window.addEventListener('keydown', onGesture, true);
|
|
1867
2023
|
document.addEventListener('focusin', onFocusIn, true);
|
|
1868
2024
|
document.addEventListener('selectionchange', onSelectionChange, true);
|
|
1869
2025
|
document.addEventListener('scroll', onScroll, true);
|
|
@@ -2036,6 +2192,7 @@ var boot = (function (injectedTag) {
|
|
|
2036
2192
|
syncContextCookie();
|
|
2037
2193
|
if (config && config.redaction) installRedactor(config.redaction);
|
|
2038
2194
|
|
|
2195
|
+
uiMessages = config && config.ui_messages;
|
|
2039
2196
|
if (AUTOCAPTURE_ENABLED) startAutocapture(attachUrl);
|
|
2040
2197
|
bootRecorder(config);
|
|
2041
2198
|
} catch (e) {}
|
|
@@ -2070,7 +2227,7 @@ var boot = (function (injectedTag) {
|
|
|
2070
2227
|
}
|
|
2071
2228
|
});
|
|
2072
2229
|
|
|
2073
|
-
var VERSION = '1.0.
|
|
2230
|
+
var VERSION = '1.0.5';
|
|
2074
2231
|
var running = null;
|
|
2075
2232
|
|
|
2076
2233
|
function logLine(level, message) {
|
package/package.json
CHANGED