@usesequential/browser 1.0.2 → 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 +27 -0
- package/dist/index.cjs +214 -36
- package/dist/index.mjs +214 -36
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
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
|
+
|
|
19
|
+
## 1.0.3
|
|
20
|
+
|
|
21
|
+
- A click that a script makes (`el.click()`, `dispatchEvent`; the browser marks it `isTrusted: false`) is recorded only
|
|
22
|
+
while the person acts: while the page has transient user activation, or within 1 second of the person's own
|
|
23
|
+
pointerup, touchend or keydown. So a tap or key that the page forwards as its own click (FastClick on iOS, a key
|
|
24
|
+
handler on a `role="button"`) is still recorded, and a script that clicks on a timer from page load is not: no
|
|
25
|
+
`$click` and no dead click. A browser that does not set `isTrusted` is unchanged.
|
|
26
|
+
- At most 5 `$click` per element per second, on a monotonic clock. A faster loop on one element, even with events the
|
|
27
|
+
browser trusts, sends no more. Rage and dead clicks are unchanged.
|
|
28
|
+
- A dead click on an option that was already selected carries `$el_state: 'selected'`.
|
|
29
|
+
|
|
3
30
|
## 1.0.2
|
|
4
31
|
|
|
5
32
|
- The package now holds the same code as the script tag of 3 November 2026. Changes since 1.0.0:
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @usesequential/browser 1.0.
|
|
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) {
|
|
@@ -206,10 +206,7 @@ var boot = (function (injectedTag) {
|
|
|
206
206
|
var REQUEST_TIMEOUT_MS = 10000;
|
|
207
207
|
var MAX_SEND_ATTEMPTS = 3;
|
|
208
208
|
var RETRY_BASE_MS = 500;
|
|
209
|
-
// A 429
|
|
210
|
-
// server's retry time, clamped; hold the refused batch whole and what is captured meanwhile, capped, the oldest dropped
|
|
211
|
-
// first. A held batch is resent after each pause, as its own request, until 5 min after its first refusal
|
|
212
|
-
// (sequential.core.ts holdRateLimited).
|
|
209
|
+
// A 429 or a 503 overloaded: pause and hold, as sequential.core.ts holdRateLimited.
|
|
213
210
|
var RATE_LIMIT_DEFAULT_SEC = 60;
|
|
214
211
|
var RATE_LIMIT_MIN_SEC = 1;
|
|
215
212
|
var RATE_LIMIT_MAX_SEC = 300;
|
|
@@ -960,11 +957,11 @@ var boot = (function (injectedTag) {
|
|
|
960
957
|
for (i = 0; i < w.length; i++) if (w[i].length > 2 && inList(idWords, w[i])) return true;
|
|
961
958
|
}
|
|
962
959
|
|
|
963
|
-
// Account UI (the element or
|
|
964
|
-
//
|
|
965
|
-
//
|
|
966
|
-
//
|
|
967
|
-
//
|
|
960
|
+
// Account UI (the element or its 3 nearest ancestors):
|
|
961
|
+
// as in sequential.autocapture.ts.
|
|
962
|
+
// `profile` alone is not
|
|
963
|
+
// account UI
|
|
964
|
+
// (2026-10-26).
|
|
968
965
|
var ACCOUNT_WORD = /(\b|_)(avatar|account|user[-_]?menu|profile[-_](menu|dropdown|button|avatar)|(my|user)[-_]profile)(\b|_)/;
|
|
969
966
|
var ACCOUNT_LABEL = /^(account|user|profile)$|\b(my|your|open) (account|profile)\b|\b(user|account|profile)( navigation)? (menu|dropdown|options)\b/;
|
|
970
967
|
function inAccountUi(node) {
|
|
@@ -1123,11 +1120,11 @@ var boot = (function (injectedTag) {
|
|
|
1123
1120
|
} catch (e) {}
|
|
1124
1121
|
}
|
|
1125
1122
|
|
|
1126
|
-
// Another tab's optOut() (
|
|
1127
|
-
//
|
|
1128
|
-
//
|
|
1129
|
-
//
|
|
1130
|
-
//
|
|
1123
|
+
// Another tab's optOut() (__sq_opt set to '1') opts this tab out at once;
|
|
1124
|
+
// it writes back none of the ids that tab deleted.
|
|
1125
|
+
// Another tab's optIn() or localStorage.clear()
|
|
1126
|
+
// does not opt this tab in:
|
|
1127
|
+
// that waits for the next page load.
|
|
1131
1128
|
try {
|
|
1132
1129
|
window.addEventListener('storage', function (e) {
|
|
1133
1130
|
if (e && e.key === OPT_OUT_KEY && e.newValue === '1' && !optedOut) optOut();
|
|
@@ -1263,6 +1260,12 @@ var boot = (function (injectedTag) {
|
|
|
1263
1260
|
var EL_DATA_VALUE_MAX = 128;
|
|
1264
1261
|
|
|
1265
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
|
+
}
|
|
1266
1269
|
var EL_SELECTOR_MAX = 256;
|
|
1267
1270
|
|
|
1268
1271
|
var URL_MAX = 512;
|
|
@@ -1319,7 +1322,8 @@ var boot = (function (injectedTag) {
|
|
|
1319
1322
|
return !!closestMatching(el, '[data-sq-mask], [data-sq-private]');
|
|
1320
1323
|
}
|
|
1321
1324
|
|
|
1322
|
-
|
|
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) {
|
|
1323
1327
|
var out = '';
|
|
1324
1328
|
function visit(node) {
|
|
1325
1329
|
for (var child = node.firstChild; child !== null; child = child.nextSibling) {
|
|
@@ -1332,6 +1336,7 @@ var boot = (function (injectedTag) {
|
|
|
1332
1336
|
if (inList(TEXT_OPAQUE_TAGS, tagNameOf(child))) continue;
|
|
1333
1337
|
if (isEditable(child)) continue;
|
|
1334
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;
|
|
1335
1340
|
visit(child);
|
|
1336
1341
|
}
|
|
1337
1342
|
}
|
|
@@ -1405,7 +1410,7 @@ var boot = (function (injectedTag) {
|
|
|
1405
1410
|
var node = el;
|
|
1406
1411
|
var root = document.documentElement;
|
|
1407
1412
|
while (node && node !== root && node.nodeType === 1) {
|
|
1408
|
-
if (node.id
|
|
1413
|
+
if (!noIds && idToken(node.id)) {
|
|
1409
1414
|
parts.unshift('#' + node.id);
|
|
1410
1415
|
break;
|
|
1411
1416
|
}
|
|
@@ -1455,6 +1460,12 @@ var boot = (function (injectedTag) {
|
|
|
1455
1460
|
}
|
|
1456
1461
|
|
|
1457
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;
|
|
1458
1469
|
// Set by startAutocapture: sends an open rage burst before the unload path drains the queue.
|
|
1459
1470
|
var flushOpenSignals = noop;
|
|
1460
1471
|
|
|
@@ -1543,9 +1554,7 @@ var boot = (function (injectedTag) {
|
|
|
1543
1554
|
return r.target.getAttribute(r.attributeName) !== r.oldValue;
|
|
1544
1555
|
}
|
|
1545
1556
|
|
|
1546
|
-
//
|
|
1547
|
-
// isPrimary: Chromium sends `click` as a PointerEvent with isPrimary=false; only pointer events
|
|
1548
|
-
// check it (isPlainPointer).
|
|
1557
|
+
// As sequential.autocapture.ts isPlainClick and isPlainPointer.
|
|
1549
1558
|
function isPlainClick(ev) {
|
|
1550
1559
|
return ev.button === 0 && !ev.ctrlKey && !ev.metaKey && !ev.shiftKey && !ev.altKey;
|
|
1551
1560
|
}
|
|
@@ -1554,6 +1563,12 @@ var boot = (function (injectedTag) {
|
|
|
1554
1563
|
return isPlainClick(ev) && ev.isPrimary !== false;
|
|
1555
1564
|
}
|
|
1556
1565
|
|
|
1566
|
+
// Monotonic where there is one, so a step of the wall clock cannot freeze the $click cap's window.
|
|
1567
|
+
function now() {
|
|
1568
|
+
var p = window.performance;
|
|
1569
|
+
return p && p.now ? p.now() : Date.now();
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1557
1572
|
function startAutocapture(attachUrl) {
|
|
1558
1573
|
if (autocaptureStarted || !redactor) return;
|
|
1559
1574
|
autocaptureStarted = true;
|
|
@@ -1574,11 +1589,23 @@ var boot = (function (injectedTag) {
|
|
|
1574
1589
|
$nav: nav,
|
|
1575
1590
|
$load_type: nav === 'load' ? loadTypeOf() : undefined
|
|
1576
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
|
+
}
|
|
1577
1606
|
}
|
|
1578
1607
|
|
|
1579
|
-
// One page key
|
|
1580
|
-
// route) for every trigger, as in
|
|
1581
|
-
// sequential.autocapture.ts pageKey: a router's same-URL replaceState is not a pageview.
|
|
1608
|
+
// One page key for every trigger, as sequential.autocapture.ts pageKey.
|
|
1582
1609
|
var lastPageKey = null;
|
|
1583
1610
|
var lastPathKey = null;
|
|
1584
1611
|
var lastNavigationType;
|
|
@@ -1600,9 +1627,7 @@ var boot = (function (injectedTag) {
|
|
|
1600
1627
|
} catch (e) {}
|
|
1601
1628
|
}
|
|
1602
1629
|
|
|
1603
|
-
// A traversal the page's router answers with replaceState
|
|
1604
|
-
// replace while a popstate is being handled (window.event, or our capture listener's mark) is that traversal, of
|
|
1605
|
-
// the kind of the last navigate event before it that was not a replace.
|
|
1630
|
+
// A traversal the page's router answers with replaceState: as sequential.autocapture.ts inPopstate (F1).
|
|
1606
1631
|
var popPending = false;
|
|
1607
1632
|
var popKind;
|
|
1608
1633
|
function onPopCapture() {
|
|
@@ -1650,7 +1675,7 @@ var boot = (function (injectedTag) {
|
|
|
1650
1675
|
return {
|
|
1651
1676
|
$el_tag_name: tagNameOf(matched),
|
|
1652
1677
|
$el_selector: cap(selector, EL_SELECTOR_MAX),
|
|
1653
|
-
$el_id:
|
|
1678
|
+
$el_id: !noIds && idToken(matched.id) || undefined,
|
|
1654
1679
|
$el_data: masked || identity ? undefined : dataAttrs(matched, redactor),
|
|
1655
1680
|
$el_text: raw !== undefined && !identity ? redactor.boundedRedact(raw, CLICK_TEXT_MAX) : undefined,
|
|
1656
1681
|
$el_label: label && !labelOrHrefIdentity ? redactor.boundedRedact(label, CLICK_TEXT_MAX) : undefined,
|
|
@@ -1658,20 +1683,45 @@ var boot = (function (injectedTag) {
|
|
|
1658
1683
|
};
|
|
1659
1684
|
}
|
|
1660
1685
|
|
|
1686
|
+
// At most 5 $click per element per second (sequential.autocapture.ts CLICK_CAP): capAt is the window's start, caps
|
|
1687
|
+
// each element's count in it; the clicks past 5 are counted there, not sent.
|
|
1688
|
+
var caps = {};
|
|
1689
|
+
var capAt = 0;
|
|
1690
|
+
// The last trusted pointerup, touchend or keydown (sequential.autocapture.ts GESTURE_MS).
|
|
1691
|
+
var gestureAt = -1e9;
|
|
1692
|
+
|
|
1693
|
+
function onGesture(ev) {
|
|
1694
|
+
if (ev.isTrusted) {
|
|
1695
|
+
gestureAt = now();
|
|
1696
|
+
if (ev.key === 'Enter') openMsg('submit');
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1661
1700
|
function onClick(ev) {
|
|
1662
1701
|
try {
|
|
1663
1702
|
var target = ev && ev.target;
|
|
1664
1703
|
if (!target || target.nodeType !== 1) return;
|
|
1704
|
+
// A script's click (isTrusted false) counts only while the person acts (sequential.autocapture.ts untrusted).
|
|
1705
|
+
if (ev.isTrusted === false) {
|
|
1706
|
+
var ua = window.navigator.userActivation;
|
|
1707
|
+
if (!(ua && ua.isActive) && now() - gestureAt >= 1000) return;
|
|
1708
|
+
}
|
|
1709
|
+
openMsg('click');
|
|
1665
1710
|
var matched = closestMatching(target, INTERACTIVE_SELECTOR);
|
|
1666
1711
|
if (!matched) return;
|
|
1667
|
-
|
|
1712
|
+
var props = elementProps(matched);
|
|
1713
|
+
var t = now();
|
|
1714
|
+
if (t - capAt >= 1000) {
|
|
1715
|
+
caps = {};
|
|
1716
|
+
capAt = t;
|
|
1717
|
+
}
|
|
1718
|
+
if ((caps[props.$el_selector] = (caps[props.$el_selector] || 0) + 1) <= 5) captureInternal('$click', props);
|
|
1668
1719
|
if (isPlainClick(ev) && !deadExcluded(matched, target)) openDead(matched);
|
|
1669
1720
|
} catch (e) {}
|
|
1670
1721
|
}
|
|
1671
1722
|
|
|
1672
1723
|
// ── rage and dead clicks: as in sequential.autocapture.ts (BE spec 2026-10-08, BE #432) ──
|
|
1673
|
-
// One MutationObserver, only while a burst or a dead window is open
|
|
1674
|
-
// neither signal runs, because "no effect" cannot be told from "an effect we cannot see".
|
|
1724
|
+
// One MutationObserver, only while a burst or a dead window is open; none: neither signal runs.
|
|
1675
1725
|
var Observer = window.MutationObserver;
|
|
1676
1726
|
var rage = null;
|
|
1677
1727
|
var dead = null;
|
|
@@ -1679,10 +1729,10 @@ var boot = (function (injectedTag) {
|
|
|
1679
1729
|
|
|
1680
1730
|
function syncObserver() {
|
|
1681
1731
|
try {
|
|
1682
|
-
if ((rage || dead) && !observer && Observer) {
|
|
1732
|
+
if ((rage || dead || now() < msgUntil) && !observer && Observer) {
|
|
1683
1733
|
observer = new Observer(onMutations);
|
|
1684
1734
|
observer.observe(document, { subtree: true, childList: true, attributes: true, attributeOldValue: true, characterData: true });
|
|
1685
|
-
} else if (!rage && !dead && observer) {
|
|
1735
|
+
} else if (!rage && !dead && now() >= msgUntil && observer) {
|
|
1686
1736
|
observer.disconnect();
|
|
1687
1737
|
observer = null;
|
|
1688
1738
|
}
|
|
@@ -1710,6 +1760,20 @@ var boot = (function (injectedTag) {
|
|
|
1710
1760
|
|
|
1711
1761
|
function onMutations(records) {
|
|
1712
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();
|
|
1713
1777
|
for (var i = 0; i < records.length; i++) {
|
|
1714
1778
|
if (records[i].type !== 'attributes' || !rage || records[i].target !== rage.el || stateChanged(records[i])) own = false;
|
|
1715
1779
|
}
|
|
@@ -1780,7 +1844,7 @@ var boot = (function (injectedTag) {
|
|
|
1780
1844
|
if (!Observer || document.visibilityState === 'hidden') return;
|
|
1781
1845
|
// A new click means the person did something: the old window ends with no event.
|
|
1782
1846
|
if (dead) clearTimeout(dead.timer);
|
|
1783
|
-
dead = { at: Date.now(), el: el, href: String(window.location.href), timer: setTimeout(endDead, DEAD_WAIT_MS) };
|
|
1847
|
+
dead = { at: Date.now(), el: el, href: String(window.location.href), selected: !closestMatching(el, '[data-sq-private]') && selectedState(el), timer: setTimeout(endDead, DEAD_WAIT_MS) };
|
|
1784
1848
|
syncObserver();
|
|
1785
1849
|
}
|
|
1786
1850
|
|
|
@@ -1791,7 +1855,7 @@ var boot = (function (injectedTag) {
|
|
|
1791
1855
|
syncObserver();
|
|
1792
1856
|
if (!d || String(window.location.href) !== d.href) return;
|
|
1793
1857
|
var props = elementProps(d.el);
|
|
1794
|
-
props.$wait_ms = DEAD_WAIT_MS;
|
|
1858
|
+
props.$wait_ms = DEAD_WAIT_MS; if (d.selected) props.$el_state = 'selected';
|
|
1795
1859
|
captureInternal('$deadclick', props, d.at);
|
|
1796
1860
|
} catch (e) {}
|
|
1797
1861
|
}
|
|
@@ -1811,6 +1875,103 @@ var boot = (function (injectedTag) {
|
|
|
1811
1875
|
if ((dead || rage) && hasSelection()) effect(false);
|
|
1812
1876
|
}
|
|
1813
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
|
+
|
|
1814
1975
|
function onScroll() {
|
|
1815
1976
|
if (dead || rage) effect(false);
|
|
1816
1977
|
}
|
|
@@ -1832,10 +1993,11 @@ var boot = (function (injectedTag) {
|
|
|
1832
1993
|
try {
|
|
1833
1994
|
var target = ev && ev.target;
|
|
1834
1995
|
if (!target || tagNameOf(target) !== 'form') return;
|
|
1996
|
+
openMsg('submit');
|
|
1835
1997
|
|
|
1836
1998
|
captureInternal('$form_submit', {
|
|
1837
1999
|
$form_selector: cap(stableSelector(target), EL_SELECTOR_MAX),
|
|
1838
|
-
form:
|
|
2000
|
+
form: idToken(target.id) || undefined
|
|
1839
2001
|
});
|
|
1840
2002
|
} catch (e) {}
|
|
1841
2003
|
}
|
|
@@ -1844,6 +2006,10 @@ var boot = (function (injectedTag) {
|
|
|
1844
2006
|
document.addEventListener('submit', onSubmit, true);
|
|
1845
2007
|
document.addEventListener('pointerdown', onPointerDown, true);
|
|
1846
2008
|
document.addEventListener('pointerup', onPointerUp, 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);
|
|
1847
2013
|
document.addEventListener('focusin', onFocusIn, true);
|
|
1848
2014
|
document.addEventListener('selectionchange', onSelectionChange, true);
|
|
1849
2015
|
document.addEventListener('scroll', onScroll, true);
|
|
@@ -2016,6 +2182,7 @@ var boot = (function (injectedTag) {
|
|
|
2016
2182
|
syncContextCookie();
|
|
2017
2183
|
if (config && config.redaction) installRedactor(config.redaction);
|
|
2018
2184
|
|
|
2185
|
+
uiMessages = config && config.ui_messages;
|
|
2019
2186
|
if (AUTOCAPTURE_ENABLED) startAutocapture(attachUrl);
|
|
2020
2187
|
bootRecorder(config);
|
|
2021
2188
|
} catch (e) {}
|
|
@@ -2027,6 +2194,17 @@ var boot = (function (injectedTag) {
|
|
|
2027
2194
|
} catch (e) {}
|
|
2028
2195
|
}
|
|
2029
2196
|
|
|
2197
|
+
// F7: already selected when clicked (ARIA, or a class like is-active); only 'selected' is sent ($deadclick)
|
|
2198
|
+
function selectedState(el) {
|
|
2199
|
+
var v = el.getAttribute('aria-current');
|
|
2200
|
+
return ['pressed', 'checked', 'selected'].some(function (a) { return /^\s*true\s*$/i.test(el.getAttribute('aria-' + a)); }) ||
|
|
2201
|
+
(v !== null && !/^\s*(false)?\s*$/i.test(v)) ||
|
|
2202
|
+
String(el.getAttribute('class') || '').toLowerCase().split(/\s+/).some(function (t) {
|
|
2203
|
+
t = t.split(/--|__|[-_]/);
|
|
2204
|
+
return /^(active|selected|checked|current|on)$/.test(t[t.length - 1]) && !t.some(function (x) { return /^(not|un|non|no)$/.test(x); });
|
|
2205
|
+
});
|
|
2206
|
+
}
|
|
2207
|
+
|
|
2030
2208
|
if (!DISABLED) {
|
|
2031
2209
|
try {
|
|
2032
2210
|
document.addEventListener('visibilitychange', function () {
|
|
@@ -2039,7 +2217,7 @@ var boot = (function (injectedTag) {
|
|
|
2039
2217
|
}
|
|
2040
2218
|
});
|
|
2041
2219
|
|
|
2042
|
-
var VERSION = '1.0.
|
|
2220
|
+
var VERSION = '1.0.4';
|
|
2043
2221
|
var running = null;
|
|
2044
2222
|
|
|
2045
2223
|
function logLine(level, message) {
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @usesequential/browser 1.0.
|
|
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';
|
|
@@ -205,10 +205,7 @@ var boot = (function (injectedTag) {
|
|
|
205
205
|
var REQUEST_TIMEOUT_MS = 10000;
|
|
206
206
|
var MAX_SEND_ATTEMPTS = 3;
|
|
207
207
|
var RETRY_BASE_MS = 500;
|
|
208
|
-
// A 429
|
|
209
|
-
// server's retry time, clamped; hold the refused batch whole and what is captured meanwhile, capped, the oldest dropped
|
|
210
|
-
// first. A held batch is resent after each pause, as its own request, until 5 min after its first refusal
|
|
211
|
-
// (sequential.core.ts holdRateLimited).
|
|
208
|
+
// A 429 or a 503 overloaded: pause and hold, as sequential.core.ts holdRateLimited.
|
|
212
209
|
var RATE_LIMIT_DEFAULT_SEC = 60;
|
|
213
210
|
var RATE_LIMIT_MIN_SEC = 1;
|
|
214
211
|
var RATE_LIMIT_MAX_SEC = 300;
|
|
@@ -959,11 +956,11 @@ var boot = (function (injectedTag) {
|
|
|
959
956
|
for (i = 0; i < w.length; i++) if (w[i].length > 2 && inList(idWords, w[i])) return true;
|
|
960
957
|
}
|
|
961
958
|
|
|
962
|
-
// Account UI (the element or
|
|
963
|
-
//
|
|
964
|
-
//
|
|
965
|
-
//
|
|
966
|
-
//
|
|
959
|
+
// Account UI (the element or its 3 nearest ancestors):
|
|
960
|
+
// as in sequential.autocapture.ts.
|
|
961
|
+
// `profile` alone is not
|
|
962
|
+
// account UI
|
|
963
|
+
// (2026-10-26).
|
|
967
964
|
var ACCOUNT_WORD = /(\b|_)(avatar|account|user[-_]?menu|profile[-_](menu|dropdown|button|avatar)|(my|user)[-_]profile)(\b|_)/;
|
|
968
965
|
var ACCOUNT_LABEL = /^(account|user|profile)$|\b(my|your|open) (account|profile)\b|\b(user|account|profile)( navigation)? (menu|dropdown|options)\b/;
|
|
969
966
|
function inAccountUi(node) {
|
|
@@ -1122,11 +1119,11 @@ var boot = (function (injectedTag) {
|
|
|
1122
1119
|
} catch (e) {}
|
|
1123
1120
|
}
|
|
1124
1121
|
|
|
1125
|
-
// Another tab's optOut() (
|
|
1126
|
-
//
|
|
1127
|
-
//
|
|
1128
|
-
//
|
|
1129
|
-
//
|
|
1122
|
+
// Another tab's optOut() (__sq_opt set to '1') opts this tab out at once;
|
|
1123
|
+
// it writes back none of the ids that tab deleted.
|
|
1124
|
+
// Another tab's optIn() or localStorage.clear()
|
|
1125
|
+
// does not opt this tab in:
|
|
1126
|
+
// that waits for the next page load.
|
|
1130
1127
|
try {
|
|
1131
1128
|
window.addEventListener('storage', function (e) {
|
|
1132
1129
|
if (e && e.key === OPT_OUT_KEY && e.newValue === '1' && !optedOut) optOut();
|
|
@@ -1262,6 +1259,12 @@ var boot = (function (injectedTag) {
|
|
|
1262
1259
|
var EL_DATA_VALUE_MAX = 128;
|
|
1263
1260
|
|
|
1264
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
|
+
}
|
|
1265
1268
|
var EL_SELECTOR_MAX = 256;
|
|
1266
1269
|
|
|
1267
1270
|
var URL_MAX = 512;
|
|
@@ -1318,7 +1321,8 @@ var boot = (function (injectedTag) {
|
|
|
1318
1321
|
return !!closestMatching(el, '[data-sq-mask], [data-sq-private]');
|
|
1319
1322
|
}
|
|
1320
1323
|
|
|
1321
|
-
|
|
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) {
|
|
1322
1326
|
var out = '';
|
|
1323
1327
|
function visit(node) {
|
|
1324
1328
|
for (var child = node.firstChild; child !== null; child = child.nextSibling) {
|
|
@@ -1331,6 +1335,7 @@ var boot = (function (injectedTag) {
|
|
|
1331
1335
|
if (inList(TEXT_OPAQUE_TAGS, tagNameOf(child))) continue;
|
|
1332
1336
|
if (isEditable(child)) continue;
|
|
1333
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;
|
|
1334
1339
|
visit(child);
|
|
1335
1340
|
}
|
|
1336
1341
|
}
|
|
@@ -1404,7 +1409,7 @@ var boot = (function (injectedTag) {
|
|
|
1404
1409
|
var node = el;
|
|
1405
1410
|
var root = document.documentElement;
|
|
1406
1411
|
while (node && node !== root && node.nodeType === 1) {
|
|
1407
|
-
if (node.id
|
|
1412
|
+
if (!noIds && idToken(node.id)) {
|
|
1408
1413
|
parts.unshift('#' + node.id);
|
|
1409
1414
|
break;
|
|
1410
1415
|
}
|
|
@@ -1454,6 +1459,12 @@ var boot = (function (injectedTag) {
|
|
|
1454
1459
|
}
|
|
1455
1460
|
|
|
1456
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;
|
|
1457
1468
|
// Set by startAutocapture: sends an open rage burst before the unload path drains the queue.
|
|
1458
1469
|
var flushOpenSignals = noop;
|
|
1459
1470
|
|
|
@@ -1542,9 +1553,7 @@ var boot = (function (injectedTag) {
|
|
|
1542
1553
|
return r.target.getAttribute(r.attributeName) !== r.oldValue;
|
|
1543
1554
|
}
|
|
1544
1555
|
|
|
1545
|
-
//
|
|
1546
|
-
// isPrimary: Chromium sends `click` as a PointerEvent with isPrimary=false; only pointer events
|
|
1547
|
-
// check it (isPlainPointer).
|
|
1556
|
+
// As sequential.autocapture.ts isPlainClick and isPlainPointer.
|
|
1548
1557
|
function isPlainClick(ev) {
|
|
1549
1558
|
return ev.button === 0 && !ev.ctrlKey && !ev.metaKey && !ev.shiftKey && !ev.altKey;
|
|
1550
1559
|
}
|
|
@@ -1553,6 +1562,12 @@ var boot = (function (injectedTag) {
|
|
|
1553
1562
|
return isPlainClick(ev) && ev.isPrimary !== false;
|
|
1554
1563
|
}
|
|
1555
1564
|
|
|
1565
|
+
// Monotonic where there is one, so a step of the wall clock cannot freeze the $click cap's window.
|
|
1566
|
+
function now() {
|
|
1567
|
+
var p = window.performance;
|
|
1568
|
+
return p && p.now ? p.now() : Date.now();
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1556
1571
|
function startAutocapture(attachUrl) {
|
|
1557
1572
|
if (autocaptureStarted || !redactor) return;
|
|
1558
1573
|
autocaptureStarted = true;
|
|
@@ -1573,11 +1588,23 @@ var boot = (function (injectedTag) {
|
|
|
1573
1588
|
$nav: nav,
|
|
1574
1589
|
$load_type: nav === 'load' ? loadTypeOf() : undefined
|
|
1575
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
|
+
}
|
|
1576
1605
|
}
|
|
1577
1606
|
|
|
1578
|
-
// One page key
|
|
1579
|
-
// route) for every trigger, as in
|
|
1580
|
-
// sequential.autocapture.ts pageKey: a router's same-URL replaceState is not a pageview.
|
|
1607
|
+
// One page key for every trigger, as sequential.autocapture.ts pageKey.
|
|
1581
1608
|
var lastPageKey = null;
|
|
1582
1609
|
var lastPathKey = null;
|
|
1583
1610
|
var lastNavigationType;
|
|
@@ -1599,9 +1626,7 @@ var boot = (function (injectedTag) {
|
|
|
1599
1626
|
} catch (e) {}
|
|
1600
1627
|
}
|
|
1601
1628
|
|
|
1602
|
-
// A traversal the page's router answers with replaceState
|
|
1603
|
-
// replace while a popstate is being handled (window.event, or our capture listener's mark) is that traversal, of
|
|
1604
|
-
// the kind of the last navigate event before it that was not a replace.
|
|
1629
|
+
// A traversal the page's router answers with replaceState: as sequential.autocapture.ts inPopstate (F1).
|
|
1605
1630
|
var popPending = false;
|
|
1606
1631
|
var popKind;
|
|
1607
1632
|
function onPopCapture() {
|
|
@@ -1649,7 +1674,7 @@ var boot = (function (injectedTag) {
|
|
|
1649
1674
|
return {
|
|
1650
1675
|
$el_tag_name: tagNameOf(matched),
|
|
1651
1676
|
$el_selector: cap(selector, EL_SELECTOR_MAX),
|
|
1652
|
-
$el_id:
|
|
1677
|
+
$el_id: !noIds && idToken(matched.id) || undefined,
|
|
1653
1678
|
$el_data: masked || identity ? undefined : dataAttrs(matched, redactor),
|
|
1654
1679
|
$el_text: raw !== undefined && !identity ? redactor.boundedRedact(raw, CLICK_TEXT_MAX) : undefined,
|
|
1655
1680
|
$el_label: label && !labelOrHrefIdentity ? redactor.boundedRedact(label, CLICK_TEXT_MAX) : undefined,
|
|
@@ -1657,20 +1682,45 @@ var boot = (function (injectedTag) {
|
|
|
1657
1682
|
};
|
|
1658
1683
|
}
|
|
1659
1684
|
|
|
1685
|
+
// At most 5 $click per element per second (sequential.autocapture.ts CLICK_CAP): capAt is the window's start, caps
|
|
1686
|
+
// each element's count in it; the clicks past 5 are counted there, not sent.
|
|
1687
|
+
var caps = {};
|
|
1688
|
+
var capAt = 0;
|
|
1689
|
+
// The last trusted pointerup, touchend or keydown (sequential.autocapture.ts GESTURE_MS).
|
|
1690
|
+
var gestureAt = -1e9;
|
|
1691
|
+
|
|
1692
|
+
function onGesture(ev) {
|
|
1693
|
+
if (ev.isTrusted) {
|
|
1694
|
+
gestureAt = now();
|
|
1695
|
+
if (ev.key === 'Enter') openMsg('submit');
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1660
1699
|
function onClick(ev) {
|
|
1661
1700
|
try {
|
|
1662
1701
|
var target = ev && ev.target;
|
|
1663
1702
|
if (!target || target.nodeType !== 1) return;
|
|
1703
|
+
// A script's click (isTrusted false) counts only while the person acts (sequential.autocapture.ts untrusted).
|
|
1704
|
+
if (ev.isTrusted === false) {
|
|
1705
|
+
var ua = window.navigator.userActivation;
|
|
1706
|
+
if (!(ua && ua.isActive) && now() - gestureAt >= 1000) return;
|
|
1707
|
+
}
|
|
1708
|
+
openMsg('click');
|
|
1664
1709
|
var matched = closestMatching(target, INTERACTIVE_SELECTOR);
|
|
1665
1710
|
if (!matched) return;
|
|
1666
|
-
|
|
1711
|
+
var props = elementProps(matched);
|
|
1712
|
+
var t = now();
|
|
1713
|
+
if (t - capAt >= 1000) {
|
|
1714
|
+
caps = {};
|
|
1715
|
+
capAt = t;
|
|
1716
|
+
}
|
|
1717
|
+
if ((caps[props.$el_selector] = (caps[props.$el_selector] || 0) + 1) <= 5) captureInternal('$click', props);
|
|
1667
1718
|
if (isPlainClick(ev) && !deadExcluded(matched, target)) openDead(matched);
|
|
1668
1719
|
} catch (e) {}
|
|
1669
1720
|
}
|
|
1670
1721
|
|
|
1671
1722
|
// ── rage and dead clicks: as in sequential.autocapture.ts (BE spec 2026-10-08, BE #432) ──
|
|
1672
|
-
// One MutationObserver, only while a burst or a dead window is open
|
|
1673
|
-
// neither signal runs, because "no effect" cannot be told from "an effect we cannot see".
|
|
1723
|
+
// One MutationObserver, only while a burst or a dead window is open; none: neither signal runs.
|
|
1674
1724
|
var Observer = window.MutationObserver;
|
|
1675
1725
|
var rage = null;
|
|
1676
1726
|
var dead = null;
|
|
@@ -1678,10 +1728,10 @@ var boot = (function (injectedTag) {
|
|
|
1678
1728
|
|
|
1679
1729
|
function syncObserver() {
|
|
1680
1730
|
try {
|
|
1681
|
-
if ((rage || dead) && !observer && Observer) {
|
|
1731
|
+
if ((rage || dead || now() < msgUntil) && !observer && Observer) {
|
|
1682
1732
|
observer = new Observer(onMutations);
|
|
1683
1733
|
observer.observe(document, { subtree: true, childList: true, attributes: true, attributeOldValue: true, characterData: true });
|
|
1684
|
-
} else if (!rage && !dead && observer) {
|
|
1734
|
+
} else if (!rage && !dead && now() >= msgUntil && observer) {
|
|
1685
1735
|
observer.disconnect();
|
|
1686
1736
|
observer = null;
|
|
1687
1737
|
}
|
|
@@ -1709,6 +1759,20 @@ var boot = (function (injectedTag) {
|
|
|
1709
1759
|
|
|
1710
1760
|
function onMutations(records) {
|
|
1711
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();
|
|
1712
1776
|
for (var i = 0; i < records.length; i++) {
|
|
1713
1777
|
if (records[i].type !== 'attributes' || !rage || records[i].target !== rage.el || stateChanged(records[i])) own = false;
|
|
1714
1778
|
}
|
|
@@ -1779,7 +1843,7 @@ var boot = (function (injectedTag) {
|
|
|
1779
1843
|
if (!Observer || document.visibilityState === 'hidden') return;
|
|
1780
1844
|
// A new click means the person did something: the old window ends with no event.
|
|
1781
1845
|
if (dead) clearTimeout(dead.timer);
|
|
1782
|
-
dead = { at: Date.now(), el: el, href: String(window.location.href), timer: setTimeout(endDead, DEAD_WAIT_MS) };
|
|
1846
|
+
dead = { at: Date.now(), el: el, href: String(window.location.href), selected: !closestMatching(el, '[data-sq-private]') && selectedState(el), timer: setTimeout(endDead, DEAD_WAIT_MS) };
|
|
1783
1847
|
syncObserver();
|
|
1784
1848
|
}
|
|
1785
1849
|
|
|
@@ -1790,7 +1854,7 @@ var boot = (function (injectedTag) {
|
|
|
1790
1854
|
syncObserver();
|
|
1791
1855
|
if (!d || String(window.location.href) !== d.href) return;
|
|
1792
1856
|
var props = elementProps(d.el);
|
|
1793
|
-
props.$wait_ms = DEAD_WAIT_MS;
|
|
1857
|
+
props.$wait_ms = DEAD_WAIT_MS; if (d.selected) props.$el_state = 'selected';
|
|
1794
1858
|
captureInternal('$deadclick', props, d.at);
|
|
1795
1859
|
} catch (e) {}
|
|
1796
1860
|
}
|
|
@@ -1810,6 +1874,103 @@ var boot = (function (injectedTag) {
|
|
|
1810
1874
|
if ((dead || rage) && hasSelection()) effect(false);
|
|
1811
1875
|
}
|
|
1812
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
|
+
|
|
1813
1974
|
function onScroll() {
|
|
1814
1975
|
if (dead || rage) effect(false);
|
|
1815
1976
|
}
|
|
@@ -1831,10 +1992,11 @@ var boot = (function (injectedTag) {
|
|
|
1831
1992
|
try {
|
|
1832
1993
|
var target = ev && ev.target;
|
|
1833
1994
|
if (!target || tagNameOf(target) !== 'form') return;
|
|
1995
|
+
openMsg('submit');
|
|
1834
1996
|
|
|
1835
1997
|
captureInternal('$form_submit', {
|
|
1836
1998
|
$form_selector: cap(stableSelector(target), EL_SELECTOR_MAX),
|
|
1837
|
-
form:
|
|
1999
|
+
form: idToken(target.id) || undefined
|
|
1838
2000
|
});
|
|
1839
2001
|
} catch (e) {}
|
|
1840
2002
|
}
|
|
@@ -1843,6 +2005,10 @@ var boot = (function (injectedTag) {
|
|
|
1843
2005
|
document.addEventListener('submit', onSubmit, true);
|
|
1844
2006
|
document.addEventListener('pointerdown', onPointerDown, true);
|
|
1845
2007
|
document.addEventListener('pointerup', onPointerUp, 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);
|
|
1846
2012
|
document.addEventListener('focusin', onFocusIn, true);
|
|
1847
2013
|
document.addEventListener('selectionchange', onSelectionChange, true);
|
|
1848
2014
|
document.addEventListener('scroll', onScroll, true);
|
|
@@ -2015,6 +2181,7 @@ var boot = (function (injectedTag) {
|
|
|
2015
2181
|
syncContextCookie();
|
|
2016
2182
|
if (config && config.redaction) installRedactor(config.redaction);
|
|
2017
2183
|
|
|
2184
|
+
uiMessages = config && config.ui_messages;
|
|
2018
2185
|
if (AUTOCAPTURE_ENABLED) startAutocapture(attachUrl);
|
|
2019
2186
|
bootRecorder(config);
|
|
2020
2187
|
} catch (e) {}
|
|
@@ -2026,6 +2193,17 @@ var boot = (function (injectedTag) {
|
|
|
2026
2193
|
} catch (e) {}
|
|
2027
2194
|
}
|
|
2028
2195
|
|
|
2196
|
+
// F7: already selected when clicked (ARIA, or a class like is-active); only 'selected' is sent ($deadclick)
|
|
2197
|
+
function selectedState(el) {
|
|
2198
|
+
var v = el.getAttribute('aria-current');
|
|
2199
|
+
return ['pressed', 'checked', 'selected'].some(function (a) { return /^\s*true\s*$/i.test(el.getAttribute('aria-' + a)); }) ||
|
|
2200
|
+
(v !== null && !/^\s*(false)?\s*$/i.test(v)) ||
|
|
2201
|
+
String(el.getAttribute('class') || '').toLowerCase().split(/\s+/).some(function (t) {
|
|
2202
|
+
t = t.split(/--|__|[-_]/);
|
|
2203
|
+
return /^(active|selected|checked|current|on)$/.test(t[t.length - 1]) && !t.some(function (x) { return /^(not|un|non|no)$/.test(x); });
|
|
2204
|
+
});
|
|
2205
|
+
}
|
|
2206
|
+
|
|
2029
2207
|
if (!DISABLED) {
|
|
2030
2208
|
try {
|
|
2031
2209
|
document.addEventListener('visibilitychange', function () {
|
|
@@ -2038,7 +2216,7 @@ var boot = (function (injectedTag) {
|
|
|
2038
2216
|
}
|
|
2039
2217
|
});
|
|
2040
2218
|
|
|
2041
|
-
var VERSION = '1.0.
|
|
2219
|
+
var VERSION = '1.0.4';
|
|
2042
2220
|
var running = null;
|
|
2043
2221
|
|
|
2044
2222
|
function logLine(level, message) {
|
package/package.json
CHANGED