@absolutejs/beacon 0.4.18 → 0.4.19

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/README.md CHANGED
@@ -128,6 +128,21 @@ beacon.captureMessage("checkout started", "info");
128
128
  frustration (identical resubmits / repeated native-validation failures).
129
129
  Each is individually toggleable on `signals`, deduped, capped, and exempts
130
130
  `data-beacon-scan="allow"` subtrees where a DOM scan is involved.
131
+ - **Theme and loading contracts** — mark an application boundary with
132
+ `data-beacon-theme="adaptive"` to report large opaque surfaces whose
133
+ luminance polarity contradicts the active light/dark mode. Intentional
134
+ inverted brand/media surfaces use `data-beacon-theme="allow"`. Loading UI
135
+ participates through native `aria-busy`/`role="progressbar"` semantics or
136
+ `data-beacon-loading`, without coupling the SDK to framework class names.
137
+ - **Browser capability failures** — rejected clipboard writes are observed even
138
+ when application code catches them (contents are never read), visible WebGL
139
+ contexts that do not restore after `webglcontextlost` become warnings, and a
140
+ focused editable control stranded behind the mobile visual viewport is
141
+ reported after the keyboard settles.
142
+ - **Embedded-content stalls** — visible iframes explicitly named with
143
+ `data-beacon-embed` report when their initial `load` never arrives. Generic
144
+ cross-origin error pages cannot be inspected, so Beacon deliberately makes no
145
+ stronger claim than the load deadline.
131
146
  - **Actionable network signals** — expected aborts remain breadcrumbs instead of
132
147
  issues; offline, timeout, isolated-endpoint, and multi-endpoint connectivity
133
148
  failures are classified separately. HTTP 429 responses and repeated 401/403
package/dist/index.d.ts CHANGED
@@ -25,13 +25,16 @@ export declare const BEACON_SIGNAL: {
25
25
  readonly BROWSER_INTERVENTION: "browser_intervention";
26
26
  readonly CONSOLE_ERROR: "console_error";
27
27
  readonly CSP_VIOLATION: "csp_violation";
28
+ readonly CLIPBOARD_FAILURE: "clipboard_failure";
28
29
  readonly DEAD_CLICK: "dead_click";
29
30
  readonly FETCH_FAILED: "fetch_failed";
30
31
  readonly FOCUS_LOST: "focus_lost";
31
32
  readonly FONT_FAILURE: "font_failure";
32
33
  readonly FORM_FRUSTRATION: "form_frustration";
34
+ readonly FOCUSED_CONTROL_OFFSCREEN: "focused_control_offscreen";
33
35
  readonly HTTP_5XX: "http_5xx";
34
36
  readonly INVISIBLE_TEXT: "invisible_text";
37
+ readonly EMBEDDED_CONTENT_STALLED: "embedded_content_stalled";
35
38
  readonly LAYOUT_OVERFLOW: "layout_overflow";
36
39
  readonly MAIN_THREAD_STALL: "main_thread_stall";
37
40
  readonly MODAL_FOCUS_ESCAPE: "modal_focus_escape";
@@ -48,6 +51,8 @@ export declare const BEACON_SIGNAL: {
48
51
  readonly STALE_RELEASE: "stale_release";
49
52
  readonly STALLED_STREAM: "stalled_stream";
50
53
  readonly STUCK_LOADING: "stuck_loading";
54
+ readonly THEME_MISMATCH: "theme_mismatch";
55
+ readonly WEBGL_CONTEXT_LOST: "webgl_context_lost";
51
56
  readonly SERVICE_WORKER_FAILURE: "service_worker_failure";
52
57
  readonly WORKER_FAILURE: "worker_failure";
53
58
  };
@@ -56,12 +61,19 @@ export type BeaconSignal = (typeof BEACON_SIGNAL)[keyof typeof BEACON_SIGNAL];
56
61
  export declare const BEACON_ATTRIBUTE: {
57
62
  readonly DEAD_CLICK: "data-beacon-dead-click";
58
63
  readonly NAME: "data-beacon-name";
64
+ /** Names an iframe whose initial load should be watched for a stall. */
65
+ readonly EMBED: "data-beacon-embed";
66
+ /** Marks loading UI that should participate in the stuck-loading watchdog. */
67
+ readonly LOADING: "data-beacon-loading";
59
68
  /** `="allow"` exempts an element AND its subtree from layout-overflow
60
69
  * detection — for deliberate bleeds (decorative shapes, marquees). */
61
70
  readonly OVERFLOW: "data-beacon-overflow";
62
71
  /** `="allow"` exempts an element AND its subtree from the visual scan
63
72
  * detectors (occluded controls, invisible text, stuck loading). */
64
73
  readonly SCAN: "data-beacon-scan";
74
+ /** `="adaptive"` opts a subtree into theme-polarity checks; `="allow"`
75
+ * exempts an intentional opposite-theme surface and its subtree. */
76
+ readonly THEME: "data-beacon-theme";
65
77
  };
66
78
  /** Response header used to correlate a browser signal with its server request. */
67
79
  export declare const BEACON_TRACE_HEADER = "x-absolute-trace-id";
@@ -166,6 +178,9 @@ export type BeaconSignals = {
166
178
  browserInterventions?: boolean;
167
179
  /** Enforced Content Security Policy violations. Default true. */
168
180
  cspViolations?: boolean;
181
+ /** Rejected clipboard writes, including failures handled by application
182
+ * code. Clipboard contents are never captured. Default true. */
183
+ clipboardFailures?: boolean;
169
184
  /** N rapid clicks in roughly the same spot. Default true. */
170
185
  rageClicks?: boolean;
171
186
  /** An interactive control clicked with no DOM/nav/scroll/focus/request response. Default true. */
@@ -187,6 +202,16 @@ export type BeaconSignals = {
187
202
  /** The same form submitted or failing native validation repeatedly within a
188
203
  * minute — the quiet sibling of a rage click. Default true. */
189
204
  formFrustration?: boolean;
205
+ /** A focused editable control left outside the mobile visual viewport after
206
+ * the on-screen keyboard settles. Default true. */
207
+ focusedControlsOffscreen?: boolean;
208
+ /** Grace period after focus/visual-viewport movement. Default 500ms. */
209
+ focusedControlSettleMs?: number;
210
+ /** Opt-in iframes marked with `data-beacon-embed` that never fire their
211
+ * initial load event. Default true. */
212
+ embeddedContentStalls?: boolean;
213
+ /** Initial iframe load deadline. Default 15000ms. */
214
+ embeddedContentStallMs?: number;
190
215
  /** Sampled scan for text rendered nearly the same color as its opaque
191
216
  * background (theme-token bugs). Default true. */
192
217
  invisibleText?: boolean;
@@ -268,6 +293,17 @@ export type BeaconSignals = {
268
293
  /** Age at which a visible loading indicator counts as stuck.
269
294
  * Default 20000ms. */
270
295
  stuckLoadingMs?: number;
296
+ /** Opposite-polarity opaque surfaces inside subtrees explicitly marked
297
+ * `data-beacon-theme="adaptive"`. Default true. */
298
+ themeMismatches?: boolean;
299
+ /** Visible surface area required for theme-polarity checks. Default
300
+ * 10000px². */
301
+ themeMismatchMinArea?: number;
302
+ /** Visible WebGL canvases whose context remains lost after a restoration
303
+ * grace period. Default true. */
304
+ webglContextLosses?: boolean;
305
+ /** Grace period for `webglcontextrestored`. Default 2000ms. */
306
+ webglRestoreGraceMs?: number;
271
307
  /** Dedicated/shared worker construction, runtime, and message decoding
272
308
  * failures. Default true. */
273
309
  workerFailures?: boolean;
package/dist/index.js CHANGED
@@ -12,13 +12,16 @@ var BEACON_SIGNAL = {
12
12
  BROWSER_INTERVENTION: "browser_intervention",
13
13
  CONSOLE_ERROR: "console_error",
14
14
  CSP_VIOLATION: "csp_violation",
15
+ CLIPBOARD_FAILURE: "clipboard_failure",
15
16
  DEAD_CLICK: "dead_click",
16
17
  FETCH_FAILED: "fetch_failed",
17
18
  FOCUS_LOST: "focus_lost",
18
19
  FONT_FAILURE: "font_failure",
19
20
  FORM_FRUSTRATION: "form_frustration",
21
+ FOCUSED_CONTROL_OFFSCREEN: "focused_control_offscreen",
20
22
  HTTP_5XX: "http_5xx",
21
23
  INVISIBLE_TEXT: "invisible_text",
24
+ EMBEDDED_CONTENT_STALLED: "embedded_content_stalled",
22
25
  LAYOUT_OVERFLOW: "layout_overflow",
23
26
  MAIN_THREAD_STALL: "main_thread_stall",
24
27
  MODAL_FOCUS_ESCAPE: "modal_focus_escape",
@@ -35,14 +38,19 @@ var BEACON_SIGNAL = {
35
38
  STALE_RELEASE: "stale_release",
36
39
  STALLED_STREAM: "stalled_stream",
37
40
  STUCK_LOADING: "stuck_loading",
41
+ THEME_MISMATCH: "theme_mismatch",
42
+ WEBGL_CONTEXT_LOST: "webgl_context_lost",
38
43
  SERVICE_WORKER_FAILURE: "service_worker_failure",
39
44
  WORKER_FAILURE: "worker_failure"
40
45
  };
41
46
  var BEACON_ATTRIBUTE = {
42
47
  DEAD_CLICK: "data-beacon-dead-click",
43
48
  NAME: "data-beacon-name",
49
+ EMBED: "data-beacon-embed",
50
+ LOADING: "data-beacon-loading",
44
51
  OVERFLOW: "data-beacon-overflow",
45
- SCAN: "data-beacon-scan"
52
+ SCAN: "data-beacon-scan",
53
+ THEME: "data-beacon-theme"
46
54
  };
47
55
  var BEACON_TRACE_HEADER = "x-absolute-trace-id";
48
56
  var inBrowser = () => typeof window !== "undefined";
@@ -553,8 +561,16 @@ var createBeacon = (options) => {
553
561
  const OCCLUSION_COVERAGE_MIN = 0.9;
554
562
  const INVISIBLE_TEXT_SAMPLE_LIMIT = 40;
555
563
  const INVISIBLE_TEXT_CONTRAST_MAX = 1.2;
564
+ const THEME_SURFACE_SAMPLE_LIMIT = 200;
565
+ const THEME_MISMATCH_DEFAULT_MIN_AREA = 1e4;
566
+ const THEME_DARK_SURFACE_LUMINANCE_MAX = 0.12;
567
+ const THEME_LIGHT_SURFACE_LUMINANCE_MIN = 0.85;
556
568
  const STUCK_LOADING_DEFAULT_MS = 20000;
557
569
  const STUCK_LOADING_POLL_MS = 5000;
570
+ const EMBEDDED_CONTENT_STALL_DEFAULT_MS = 15000;
571
+ const WEBGL_RESTORE_GRACE_DEFAULT_MS = 2000;
572
+ const FOCUSED_CONTROL_SETTLE_DEFAULT_MS = 500;
573
+ const KEYBOARD_VIEWPORT_HEIGHT_RATIO_MAX = 0.8;
558
574
  const SCROLL_JAIL_EVENT_COUNT = 8;
559
575
  const SCROLL_JAIL_WINDOW_MS = 2000;
560
576
  const SCROLL_JAIL_BOUNDARY_TOLERANCE_PX = 2;
@@ -1237,6 +1253,35 @@ var createBeacon = (options) => {
1237
1253
  });
1238
1254
  }
1239
1255
  }
1256
+ if (signals !== null && signals.clipboardFailures !== false && typeof navigator !== "undefined" && navigator.clipboard !== undefined && typeof navigator.clipboard.writeText === "function") {
1257
+ const clipboard = navigator.clipboard;
1258
+ const originalWriteText = clipboard.writeText;
1259
+ const wrappedWriteText = async (value) => {
1260
+ const target = typeof document !== "undefined" && document.activeElement instanceof Element ? describeElement(document.activeElement) : "unknown";
1261
+ const activation = navigator.userActivation?.isActive ?? false;
1262
+ try {
1263
+ return await originalWriteText.call(clipboard, value);
1264
+ } catch (error) {
1265
+ if (!pageLifecycleEnding && typeof document !== "undefined" && document.visibilityState !== "hidden") {
1266
+ const resolved = toError(error);
1267
+ emitSignal(`Clipboard write failed — ${target} — ${shortUrl(location.href)}`, {
1268
+ errorName: resolved.name,
1269
+ secureContext: String(globalThis.isSecureContext === true),
1270
+ signal: BEACON_SIGNAL.CLIPBOARD_FAILURE,
1271
+ target,
1272
+ userActivation: String(activation)
1273
+ });
1274
+ }
1275
+ throw error;
1276
+ }
1277
+ };
1278
+ try {
1279
+ clipboard.writeText = wrappedWriteText;
1280
+ cleanups.push(() => {
1281
+ clipboard.writeText = originalWriteText;
1282
+ });
1283
+ } catch {}
1284
+ }
1240
1285
  if (instrument.clicks !== false && typeof document !== "undefined") {
1241
1286
  if (signals !== null) {
1242
1287
  const originalWindowOpen = window.open;
@@ -1300,9 +1345,11 @@ var createBeacon = (options) => {
1300
1345
  const detectOcclusion = signals.occludedControls !== false;
1301
1346
  const detectInvisibleText = signals.invisibleText !== false;
1302
1347
  const detectStuckLoading = signals.stuckLoading !== false;
1348
+ const detectThemeMismatch = signals.themeMismatches !== false;
1303
1349
  const overflowSettleMs = signals.layoutOverflowSettleMs ?? LAYOUT_OVERFLOW_SETTLE_DEFAULT_MS;
1304
1350
  const overflowMaxReports = signals.layoutOverflowMaxReports ?? LAYOUT_OVERFLOW_MAX_REPORTS_DEFAULT;
1305
1351
  const stuckLoadingMs = signals.stuckLoadingMs ?? STUCK_LOADING_DEFAULT_MS;
1352
+ const themeMismatchMinArea = signals.themeMismatchMinArea ?? THEME_MISMATCH_DEFAULT_MIN_AREA;
1306
1353
  const seenOverflows = new Set;
1307
1354
  let overflowReports = 0;
1308
1355
  let overflowTimer;
@@ -1603,12 +1650,72 @@ var createBeacon = (options) => {
1603
1650
  });
1604
1651
  }
1605
1652
  };
1653
+ const activeTheme = () => {
1654
+ const root = document.documentElement;
1655
+ const declared = window.getComputedStyle(root).colorScheme.trim();
1656
+ if (declared === "dark")
1657
+ return "dark";
1658
+ if (declared === "light")
1659
+ return "light";
1660
+ const dataTheme = root.getAttribute("data-theme");
1661
+ if (dataTheme === "dark" || dataTheme === "light")
1662
+ return dataTheme;
1663
+ if (root.classList.contains("dark"))
1664
+ return "dark";
1665
+ return null;
1666
+ };
1667
+ const scanForThemeMismatch = () => {
1668
+ const theme = activeTheme();
1669
+ if (theme === null)
1670
+ return;
1671
+ const roots = document.querySelectorAll(`[${BEACON_ATTRIBUTE.THEME}="adaptive"]`);
1672
+ const viewportWidth = document.documentElement.clientWidth;
1673
+ const viewportHeight = document.documentElement.clientHeight;
1674
+ let sampled = 0;
1675
+ for (const root of Array.from(roots)) {
1676
+ const candidates = [root, ...Array.from(root.querySelectorAll("*"))];
1677
+ for (const element of candidates) {
1678
+ if (sampled >= THEME_SURFACE_SAMPLE_LIMIT)
1679
+ return;
1680
+ if (element.closest(`[${BEACON_ATTRIBUTE.THEME}="allow"]`) !== null || isScanExempt(element) || element.matches("canvas, iframe, img, picture, svg, video")) {
1681
+ continue;
1682
+ }
1683
+ const rect = element.getBoundingClientRect();
1684
+ if (rect.width * rect.height < themeMismatchMinArea)
1685
+ continue;
1686
+ if (rect.bottom < 0 || rect.top > viewportHeight || rect.right < 0 || rect.left > viewportWidth) {
1687
+ continue;
1688
+ }
1689
+ const hasContent = (element.textContent ?? "").trim() !== "" || element.querySelector("button, input, select, textarea, [role=button]") !== null;
1690
+ if (!hasContent)
1691
+ continue;
1692
+ const style = window.getComputedStyle(element);
1693
+ if (style.display === "none" || style.visibility === "hidden" || style.backgroundImage !== "none" && style.backgroundImage !== "") {
1694
+ continue;
1695
+ }
1696
+ const surface = parseColor(style.backgroundColor);
1697
+ if (surface === null || surface.a < 0.95)
1698
+ continue;
1699
+ sampled += 1;
1700
+ const luminance = relativeLuminance(surface);
1701
+ const opposite = theme === "dark" ? luminance >= THEME_LIGHT_SURFACE_LUMINANCE_MIN : luminance <= THEME_DARK_SURFACE_LUMINANCE_MAX;
1702
+ if (!opposite)
1703
+ continue;
1704
+ reportScanIssue(element, BEACON_SIGNAL.THEME_MISMATCH, `Theme mismatch — ${describeElement(element)} renders an opposite-polarity surface in ${theme} mode`, {
1705
+ activeTheme: theme,
1706
+ area: String(Math.round(rect.width * rect.height)),
1707
+ surfaceColor: style.backgroundColor,
1708
+ surfaceLuminance: luminance.toFixed(3)
1709
+ });
1710
+ }
1711
+ }
1712
+ };
1606
1713
  const loadingFirstSeen = new WeakMap;
1607
1714
  const reportedStuckLoading = new WeakSet;
1608
1715
  const checkStuckLoading = () => {
1609
1716
  if (document.visibilityState === "hidden")
1610
1717
  return;
1611
- const indicators = document.querySelectorAll('[aria-busy="true"], [role="progressbar"]');
1718
+ const indicators = document.querySelectorAll(`[aria-busy="true"], [role="progressbar"], [${BEACON_ATTRIBUTE.LOADING}]`);
1612
1719
  const now = Date.now();
1613
1720
  for (const indicator of Array.from(indicators)) {
1614
1721
  if (isScanExempt(indicator))
@@ -1635,6 +1742,8 @@ var createBeacon = (options) => {
1635
1742
  scanForOcclusion();
1636
1743
  if (detectInvisibleText)
1637
1744
  scanForInvisibleText();
1745
+ if (detectThemeMismatch)
1746
+ scanForThemeMismatch();
1638
1747
  if (detectStuckLoading)
1639
1748
  checkStuckLoading();
1640
1749
  };
@@ -1654,9 +1763,15 @@ var createBeacon = (options) => {
1654
1763
  cleanups.push(() => window.removeEventListener("load", onLoad));
1655
1764
  }
1656
1765
  window.addEventListener("resize", scheduleOverflowScan);
1766
+ const themeObserver = new MutationObserver(scheduleOverflowScan);
1767
+ themeObserver.observe(document.documentElement, {
1768
+ attributeFilter: ["class", "data-theme", "style"],
1769
+ attributes: true
1770
+ });
1657
1771
  overflowScanOnNavigation = scheduleOverflowScan;
1658
1772
  cleanups.push(() => {
1659
1773
  window.removeEventListener("resize", scheduleOverflowScan);
1774
+ themeObserver.disconnect();
1660
1775
  overflowScanOnNavigation = null;
1661
1776
  if (overflowTimer !== undefined)
1662
1777
  clearTimeout(overflowTimer);
@@ -1667,7 +1782,188 @@ var createBeacon = (options) => {
1667
1782
  cleanups.push(() => clearInterval(stuckTimer));
1668
1783
  }
1669
1784
  }
1785
+ if (signals !== null && signals.embeddedContentStalls !== false && typeof document !== "undefined") {
1786
+ const stallMs = signals.embeddedContentStallMs ?? EMBEDDED_CONTENT_STALL_DEFAULT_MS;
1787
+ const watched = new Map;
1788
+ const stopWatching = (frame) => {
1789
+ const state = watched.get(frame);
1790
+ if (state === undefined)
1791
+ return;
1792
+ clearTimeout(state.timer);
1793
+ frame.removeEventListener("load", state.onLoad);
1794
+ watched.delete(frame);
1795
+ };
1796
+ const watchFrame = (frame) => {
1797
+ stopWatching(frame);
1798
+ const name = frame.getAttribute(BEACON_ATTRIBUTE.EMBED);
1799
+ if (name === null)
1800
+ return;
1801
+ const onLoad = () => stopWatching(frame);
1802
+ const timer2 = setTimeout(() => {
1803
+ stopWatching(frame);
1804
+ if (pageLifecycleEnding || document.visibilityState === "hidden" || !frame.isConnected) {
1805
+ return;
1806
+ }
1807
+ const rect = frame.getBoundingClientRect();
1808
+ if (rect.width === 0 || rect.height === 0)
1809
+ return;
1810
+ const source = frame.getAttribute("src") ?? "";
1811
+ emitSignal(`Embedded content stalled — ${describeElement(frame)} never loaded — ${shortUrl(location.href)}`, {
1812
+ embed: name.slice(0, 64),
1813
+ elapsedMs: String(stallMs),
1814
+ signal: BEACON_SIGNAL.EMBEDDED_CONTENT_STALLED,
1815
+ sourcePath: shortUrl(source),
1816
+ target: describeElement(frame)
1817
+ });
1818
+ }, stallMs);
1819
+ watched.set(frame, { onLoad, timer: timer2 });
1820
+ frame.addEventListener("load", onLoad, { once: true });
1821
+ };
1822
+ const discoverFrames = (root) => {
1823
+ if (root instanceof HTMLIFrameElement && root.hasAttribute(BEACON_ATTRIBUTE.EMBED)) {
1824
+ watchFrame(root);
1825
+ }
1826
+ for (const frame of Array.from(root.querySelectorAll(`iframe[${BEACON_ATTRIBUTE.EMBED}]`))) {
1827
+ watchFrame(frame);
1828
+ }
1829
+ };
1830
+ discoverFrames(document);
1831
+ const observer = new MutationObserver((records) => {
1832
+ for (const record of records) {
1833
+ if (record.type === "attributes") {
1834
+ if (record.target instanceof HTMLIFrameElement) {
1835
+ watchFrame(record.target);
1836
+ }
1837
+ continue;
1838
+ }
1839
+ for (const node of Array.from(record.addedNodes)) {
1840
+ if (node instanceof Element)
1841
+ discoverFrames(node);
1842
+ }
1843
+ for (const node of Array.from(record.removedNodes)) {
1844
+ if (node instanceof HTMLIFrameElement)
1845
+ stopWatching(node);
1846
+ if (node instanceof Element) {
1847
+ for (const frame of Array.from(node.querySelectorAll("iframe"))) {
1848
+ stopWatching(frame);
1849
+ }
1850
+ }
1851
+ }
1852
+ }
1853
+ });
1854
+ observer.observe(document.documentElement, {
1855
+ attributeFilter: [BEACON_ATTRIBUTE.EMBED, "src"],
1856
+ attributes: true,
1857
+ childList: true,
1858
+ subtree: true
1859
+ });
1860
+ cleanups.push(() => {
1861
+ observer.disconnect();
1862
+ for (const frame of Array.from(watched.keys()))
1863
+ stopWatching(frame);
1864
+ });
1865
+ }
1866
+ if (signals !== null && signals.webglContextLosses !== false && typeof document !== "undefined") {
1867
+ const graceMs = signals.webglRestoreGraceMs ?? WEBGL_RESTORE_GRACE_DEFAULT_MS;
1868
+ const pending = new Map;
1869
+ const reported = new WeakSet;
1870
+ const clearPending = (canvas) => {
1871
+ const timer2 = pending.get(canvas);
1872
+ if (timer2 !== undefined)
1873
+ clearTimeout(timer2);
1874
+ pending.delete(canvas);
1875
+ };
1876
+ const onLost = (event) => {
1877
+ if (!(event.target instanceof HTMLCanvasElement))
1878
+ return;
1879
+ const canvas = event.target;
1880
+ clearPending(canvas);
1881
+ const timer2 = setTimeout(() => {
1882
+ pending.delete(canvas);
1883
+ if (reported.has(canvas) || pageLifecycleEnding || document.visibilityState === "hidden" || !canvas.isConnected) {
1884
+ return;
1885
+ }
1886
+ const rect = canvas.getBoundingClientRect();
1887
+ if (rect.width === 0 || rect.height === 0)
1888
+ return;
1889
+ reported.add(canvas);
1890
+ emitSignal(`WebGL context lost — ${describeElement(canvas)} did not restore — ${shortUrl(location.href)}`, {
1891
+ canvasHeight: String(canvas.height),
1892
+ canvasWidth: String(canvas.width),
1893
+ graceMs: String(graceMs),
1894
+ signal: BEACON_SIGNAL.WEBGL_CONTEXT_LOST,
1895
+ target: describeElement(canvas)
1896
+ });
1897
+ }, graceMs);
1898
+ pending.set(canvas, timer2);
1899
+ };
1900
+ const onRestored = (event) => {
1901
+ if (event.target instanceof HTMLCanvasElement)
1902
+ clearPending(event.target);
1903
+ };
1904
+ document.addEventListener("webglcontextlost", onLost, true);
1905
+ document.addEventListener("webglcontextrestored", onRestored, true);
1906
+ cleanups.push(() => {
1907
+ document.removeEventListener("webglcontextlost", onLost, true);
1908
+ document.removeEventListener("webglcontextrestored", onRestored, true);
1909
+ for (const timer2 of pending.values())
1910
+ clearTimeout(timer2);
1911
+ pending.clear();
1912
+ });
1913
+ }
1670
1914
  if (signals !== null && typeof document !== "undefined") {
1915
+ if (signals.focusedControlsOffscreen !== false && window.visualViewport !== undefined && window.visualViewport !== null) {
1916
+ const visualViewport = window.visualViewport;
1917
+ const settleMs = signals.focusedControlSettleMs ?? FOCUSED_CONTROL_SETTLE_DEFAULT_MS;
1918
+ const reported = new Set;
1919
+ let timer2;
1920
+ const checkFocusedControl = () => {
1921
+ timer2 = undefined;
1922
+ if (pageLifecycleEnding || document.visibilityState === "hidden" || visualViewport.height >= window.innerHeight * KEYBOARD_VIEWPORT_HEIGHT_RATIO_MAX) {
1923
+ return;
1924
+ }
1925
+ const active = document.activeElement;
1926
+ const editable = active instanceof HTMLInputElement || active instanceof HTMLTextAreaElement || active instanceof HTMLElement && active.isContentEditable;
1927
+ if (!editable || !(active instanceof HTMLElement))
1928
+ return;
1929
+ const rect = active.getBoundingClientRect();
1930
+ if (rect.width === 0 || rect.height === 0)
1931
+ return;
1932
+ const viewportTop = visualViewport.offsetTop;
1933
+ const viewportBottom = viewportTop + visualViewport.height;
1934
+ const obscuredPx = Math.max(viewportTop - rect.top, rect.bottom - viewportBottom, 0);
1935
+ if (obscuredPx <= 1)
1936
+ return;
1937
+ const target = describeElement(active);
1938
+ const key = target;
1939
+ if (reported.has(key))
1940
+ return;
1941
+ reported.add(key);
1942
+ emitSignal(`Focused control offscreen — ${target} is outside the mobile visual viewport — ${shortUrl(location.href)}`, {
1943
+ layoutViewportHeight: String(window.innerHeight),
1944
+ obscuredPx: String(Math.round(obscuredPx)),
1945
+ signal: BEACON_SIGNAL.FOCUSED_CONTROL_OFFSCREEN,
1946
+ target,
1947
+ visualViewportHeight: String(Math.round(visualViewport.height)),
1948
+ visualViewportOffsetTop: String(Math.round(visualViewport.offsetTop))
1949
+ });
1950
+ };
1951
+ const scheduleCheck = () => {
1952
+ if (timer2 !== undefined)
1953
+ clearTimeout(timer2);
1954
+ timer2 = setTimeout(checkFocusedControl, settleMs);
1955
+ };
1956
+ document.addEventListener("focusin", scheduleCheck, true);
1957
+ visualViewport.addEventListener("resize", scheduleCheck);
1958
+ visualViewport.addEventListener("scroll", scheduleCheck);
1959
+ cleanups.push(() => {
1960
+ document.removeEventListener("focusin", scheduleCheck, true);
1961
+ visualViewport.removeEventListener("resize", scheduleCheck);
1962
+ visualViewport.removeEventListener("scroll", scheduleCheck);
1963
+ if (timer2 !== undefined)
1964
+ clearTimeout(timer2);
1965
+ });
1966
+ }
1671
1967
  if (signals.scrollJail !== false) {
1672
1968
  const nearestScrollable = (start) => {
1673
1969
  let node = start;
@@ -2469,5 +2765,5 @@ export {
2469
2765
  BEACON_ATTRIBUTE
2470
2766
  };
2471
2767
 
2472
- //# debugId=9FE1CDE5E81701FA64756E2164756E21
2768
+ //# debugId=317C700390399FC364756E2164756E21
2473
2769
  //# sourceMappingURL=index.js.map