@absolutejs/beacon 0.6.4 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -302,7 +302,7 @@ export type BeaconSignals = {
302
302
  mediaFailures?: boolean;
303
303
  /** Time continuously waiting/stalled before reporting. Default 10000ms. */
304
304
  mediaStallMs?: number;
305
- /** Long-frame duration that counts as a main-thread stall. Default 200ms. */
305
+ /** Blocking duration that counts as a main-thread stall. Default 200ms. */
306
306
  mainThreadStallMs?: number;
307
307
  /** Stalls inside the window that trip a report. Default 3. */
308
308
  mainThreadStallCount?: number;
package/dist/index.js CHANGED
@@ -490,14 +490,13 @@ var formControlState = (control) => {
490
490
  }
491
491
  return control.value;
492
492
  };
493
- var snapshotOwningForm = (control) => {
493
+ var snapshotRelevantFormControls = (control) => {
494
494
  const nearest = control.closest("form");
495
495
  const associated = control instanceof HTMLButtonElement || control instanceof HTMLInputElement ? control.form : null;
496
- const form = nearest ?? associated;
497
- if (form === null)
498
- return null;
496
+ const root = nearest ?? associated ?? control.closest('[role="dialog"]') ?? document;
499
497
  const snapshot = new Map;
500
- for (const element of Array.from(form.elements)) {
498
+ const elements = root instanceof HTMLFormElement ? Array.from(root.elements) : Array.from(root.querySelectorAll("input, select, textarea"));
499
+ for (const element of elements) {
501
500
  if (isFormControl(element)) {
502
501
  snapshot.set(element, formControlState(element));
503
502
  }
@@ -703,6 +702,7 @@ var createBeacon = (options) => {
703
702
  const rageCount = signals?.rageClickCount ?? RAGE_COUNT_DEFAULT;
704
703
  let networkRequestCount = 0;
705
704
  let externalNavigationCount = 0;
705
+ let clipboardWriteCount = 0;
706
706
  let inSignalConsole = false;
707
707
  let pageLifecycleEnding = false;
708
708
  let recentInteraction;
@@ -1175,9 +1175,10 @@ var createBeacon = (options) => {
1175
1175
  const urlBefore = location.href;
1176
1176
  const scrollBefore = window.scrollY;
1177
1177
  const activeBefore = document.activeElement;
1178
- const formBefore = snapshotOwningForm(control);
1178
+ const formBefore = snapshotRelevantFormControls(control);
1179
1179
  const networkRequestsBefore = networkRequestCount;
1180
1180
  const externalNavigationsBefore = externalNavigationCount;
1181
+ const clipboardWritesBefore = clipboardWriteCount;
1181
1182
  let routerAcceptedNavigation = false;
1182
1183
  let mutated = false;
1183
1184
  let extended = false;
@@ -1188,7 +1189,7 @@ var createBeacon = (options) => {
1188
1189
  return;
1189
1190
  routerAcceptedNavigation = control instanceof HTMLAnchorElement && handledEvent.defaultPrevented;
1190
1191
  };
1191
- const responded = () => mutated || formStateChanged(formBefore) || location.href !== urlBefore || window.scrollY !== scrollBefore || document.activeElement !== activeBefore || networkRequestCount !== networkRequestsBefore || externalNavigationCount !== externalNavigationsBefore;
1192
+ const responded = () => mutated || formStateChanged(formBefore) || location.href !== urlBefore || window.scrollY !== scrollBefore || document.activeElement !== activeBefore || networkRequestCount !== networkRequestsBefore || externalNavigationCount !== externalNavigationsBefore || clipboardWriteCount !== clipboardWritesBefore;
1192
1193
  const finish = (didRespond, navigationStalled = false) => {
1193
1194
  if (finished)
1194
1195
  return;
@@ -1334,7 +1335,9 @@ var createBeacon = (options) => {
1334
1335
  if (reported || document.visibilityState === "hidden")
1335
1336
  return;
1336
1337
  for (const entry of list.getEntries()) {
1337
- if (entry.duration < stallMs)
1338
+ const animationFrame = entry;
1339
+ const blockingDuration = entry.entryType === "long-animation-frame" && animationFrame.blockingDuration !== undefined ? animationFrame.blockingDuration : entry.duration;
1340
+ if (blockingDuration < stallMs)
1338
1341
  continue;
1339
1342
  const now = Date.now();
1340
1343
  stallTimes = stallTimes.filter((at) => now - at < stallWindowMs);
@@ -1342,7 +1345,6 @@ var createBeacon = (options) => {
1342
1345
  if (stallTimes.length < stallCount)
1343
1346
  continue;
1344
1347
  reported = true;
1345
- const animationFrame = entry;
1346
1348
  const script = [...animationFrame.scripts ?? []].sort((left, right) => (right.duration ?? 0) - (left.duration ?? 0))[0];
1347
1349
  emitSignal(`Main-thread stall — repeated long frames blocked the page — ${shortUrl(location.href)}`, {
1348
1350
  ...animationFrame.blockingDuration === undefined ? {} : {
@@ -1542,7 +1544,9 @@ var createBeacon = (options) => {
1542
1544
  const target = typeof document !== "undefined" && document.activeElement instanceof Element ? describeElement(document.activeElement) : "unknown";
1543
1545
  const activation = navigator.userActivation?.isActive ?? false;
1544
1546
  try {
1545
- return await originalWriteText.call(clipboard, value);
1547
+ const result = await originalWriteText.call(clipboard, value);
1548
+ clipboardWriteCount += 1;
1549
+ return result;
1546
1550
  } catch (error) {
1547
1551
  if (!pageLifecycleEnding && typeof document !== "undefined" && document.visibilityState !== "hidden") {
1548
1552
  const resolved = toError(error);
@@ -3576,5 +3580,5 @@ export {
3576
3580
  BEACON_ATTRIBUTE
3577
3581
  };
3578
3582
 
3579
- //# debugId=9A47E9967A8B159F64756E2164756E21
3583
+ //# debugId=89339955D8F62E0E64756E2164756E21
3580
3584
  //# sourceMappingURL=index.js.map