@absolutejs/beacon 0.6.21 → 0.6.23

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.js CHANGED
@@ -317,8 +317,15 @@ var isInstagramIosBridgeInjection = (event, userAgent) => INSTAGRAM_IOS_IN_APP_B
317
317
  var FACEBOOK_ANDROID_DETACHED_BRIDGE_MESSAGE = "Error invoking postMessage: Java object is gone";
318
318
  var FACEBOOK_ANDROID_PERFORMANCE_LOGGER = "iabjs://navigation_performance_logger_android";
319
319
  var KNOWN_CRAWLER_USER_AGENT = /(?:AdsBot-Google|Googlebot|bingbot|Baiduspider|YandexBot|DuckDuckBot|Applebot|Bytespider|PetalBot|SemrushBot|AhrefsBot|DotBot|MJ12bot|GPTBot|ClaudeBot|PerplexityBot|Google-NotebookLM|BitSightBot|Dataprovider\.com|meta-external(?:agent|ads))/i;
320
+ var GOOGLE_WEB_RENDERER_SERVICE_WORKER_WRAPPER = "wrsParams.serviceWorkers.navigator.serviceWorker.register";
321
+ var isInjectedServiceWorkerRejection = (event) => {
322
+ const stack = event.stack ?? "";
323
+ if (stack.includes(GOOGLE_WEB_RENDERER_SERVICE_WORKER_WRAPPER))
324
+ return true;
325
+ return event.message === "Rejected" && stack.includes("ServiceWorkerContainer.<anonymous> (<anonymous>:") && stack.includes("ServiceWorkerContainer.register (<anonymous>:");
326
+ };
320
327
  var browserUserAgent = () => typeof navigator === "undefined" ? "" : navigator.userAgent;
321
- var isKnownBeaconNoise = (event, userAgent = browserUserAgent()) => KNOWN_CRAWLER_USER_AGENT.test(userAgent) || event.name === "UnhandledRejection" && CEF_SHARP_REJECTION.test(event.message) || FACEBOOK_IOS_IN_APP_BROWSER.test(userAgent) && FACEBOOK_IOS_HOST_INJECTION.has(event.message) || isInstagramIosBridgeInjection(event, userAgent) || event.name === "Error" && event.message === FACEBOOK_ANDROID_DETACHED_BRIDGE_MESSAGE && event.tags?.errorFilename === FACEBOOK_ANDROID_PERFORMANCE_LOGGER && event.stack?.includes(FACEBOOK_ANDROID_PERFORMANCE_LOGGER) === true;
328
+ var isKnownBeaconNoise = (event, userAgent = browserUserAgent()) => KNOWN_CRAWLER_USER_AGENT.test(userAgent) || event.name === "UnhandledRejection" && CEF_SHARP_REJECTION.test(event.message) || FACEBOOK_IOS_IN_APP_BROWSER.test(userAgent) && FACEBOOK_IOS_HOST_INJECTION.has(event.message) || isInstagramIosBridgeInjection(event, userAgent) || isInjectedServiceWorkerRejection(event) || event.name === "Error" && event.message === FACEBOOK_ANDROID_DETACHED_BRIDGE_MESSAGE && event.tags?.errorFilename === FACEBOOK_ANDROID_PERFORMANCE_LOGGER && event.stack?.includes(FACEBOOK_ANDROID_PERFORMANCE_LOGGER) === true;
322
329
  var errorWithStack = (name, message, location2) => {
323
330
  const error = new Error(message);
324
331
  error.name = name;
@@ -683,6 +690,7 @@ var createBeacon = (options) => {
683
690
  const MEDIA_STALL_DEFAULT_MS = 1e4;
684
691
  const THRASHED_CURSOR_DEFAULT_REVERSALS = 8;
685
692
  const THRASHED_CURSOR_WINDOW_MS = 2000;
693
+ const THRASHED_CURSOR_REVERSAL_COSINE = -0.5;
686
694
  const NAVIGATION_RESPONSE_DEFAULT_MS = 8000;
687
695
  const LAYOUT_OVERFLOW_SETTLE_DEFAULT_MS = 600;
688
696
  const LAYOUT_OVERFLOW_MAX_REPORTS_DEFAULT = 5;
@@ -2907,7 +2915,9 @@ var createBeacon = (options) => {
2907
2915
  for (let index = 1;index < points.length; index += 1) {
2908
2916
  const prior = points[index - 1];
2909
2917
  const current = points[index];
2910
- if (prior.dx * current.dx < 0 || prior.dy * current.dy < 0)
2918
+ const dot = prior.dx * current.dx + prior.dy * current.dy;
2919
+ const magnitudeProduct = Math.hypot(prior.dx, prior.dy) * Math.hypot(current.dx, current.dy);
2920
+ if (dot / magnitudeProduct <= THRASHED_CURSOR_REVERSAL_COSINE)
2911
2921
  reversals += 1;
2912
2922
  }
2913
2923
  if (reversals < reversalThreshold)
@@ -3172,15 +3182,16 @@ var createBeacon = (options) => {
3172
3182
  submittedForms.add(event.target);
3173
3183
  dirtyForms.delete(event.target);
3174
3184
  };
3175
- const report = () => {
3185
+ const report = (departedUrl = location.href) => {
3176
3186
  for (const form of dirtyForms) {
3177
3187
  if (!form.isConnected || submittedForms.has(form))
3178
3188
  continue;
3179
3189
  const name = form.getAttribute(BEACON_ATTRIBUTE.FORM)?.trim() || describeElement(form);
3180
- emitSignal(`Form abandonment — ${name} left dirty — ${shortUrl(location.href)}`, {
3190
+ emitSignal(`Form abandonment — ${name} left dirty — ${shortUrl(departedUrl)}`, {
3181
3191
  fieldCount: String(form.elements.length),
3182
3192
  signal: BEACON_SIGNAL.FORM_ABANDONMENT,
3183
- target: name
3193
+ target: name,
3194
+ url: shortUrl(departedUrl)
3184
3195
  });
3185
3196
  dirtyForms.delete(form);
3186
3197
  }
@@ -3188,12 +3199,13 @@ var createBeacon = (options) => {
3188
3199
  reportFormAbandonmentOnNavigation = report;
3189
3200
  document.addEventListener("input", onInput, true);
3190
3201
  document.addEventListener("submit", onSubmit, true);
3191
- window.addEventListener("pagehide", report);
3202
+ const reportOnPageHide = () => report();
3203
+ window.addEventListener("pagehide", reportOnPageHide);
3192
3204
  cleanups.push(() => {
3193
3205
  reportFormAbandonmentOnNavigation = null;
3194
3206
  document.removeEventListener("input", onInput, true);
3195
3207
  document.removeEventListener("submit", onSubmit, true);
3196
- window.removeEventListener("pagehide", report);
3208
+ window.removeEventListener("pagehide", reportOnPageHide);
3197
3209
  });
3198
3210
  }
3199
3211
  }
@@ -3731,18 +3743,33 @@ var createBeacon = (options) => {
3731
3743
  });
3732
3744
  }
3733
3745
  if (instrument.history !== false && typeof history !== "undefined") {
3746
+ let recordedHistoryUrl = location.href;
3734
3747
  const record = () => {
3735
3748
  addBreadcrumb({
3736
3749
  message: `navigate ${location.pathname}${location.search}`,
3737
3750
  type: "navigation"
3738
3751
  });
3752
+ recordedHistoryUrl = location.href;
3739
3753
  overflowScanOnNavigation?.();
3740
3754
  };
3741
3755
  const patch = (key) => {
3742
3756
  const original = history[key].bind(history);
3743
3757
  history[key] = (...args) => {
3744
- reportFormAbandonmentOnNavigation?.();
3758
+ const departedUrl = location.href;
3759
+ const destination = args[2];
3760
+ let changesUrl = false;
3761
+ if (destination !== undefined && destination !== null) {
3762
+ try {
3763
+ changesUrl = new URL(String(destination), departedUrl).href !== departedUrl;
3764
+ } catch {
3765
+ const rawDestination = String(destination);
3766
+ changesUrl = rawDestination !== departedUrl && rawDestination !== `${location.pathname}${location.search}${location.hash}`;
3767
+ }
3768
+ }
3745
3769
  const result = original(...args);
3770
+ if (!changesUrl)
3771
+ return result;
3772
+ reportFormAbandonmentOnNavigation?.(departedUrl);
3746
3773
  record();
3747
3774
  return result;
3748
3775
  };
@@ -3752,7 +3779,9 @@ var createBeacon = (options) => {
3752
3779
  };
3753
3780
  cleanups.push(patch("pushState"), patch("replaceState"));
3754
3781
  const onPopState = () => {
3755
- reportFormAbandonmentOnNavigation?.();
3782
+ if (location.href === recordedHistoryUrl)
3783
+ return;
3784
+ reportFormAbandonmentOnNavigation?.(recordedHistoryUrl);
3756
3785
  record();
3757
3786
  };
3758
3787
  window.addEventListener("popstate", onPopState);
@@ -3826,5 +3855,5 @@ export {
3826
3855
  BEACON_ATTRIBUTE
3827
3856
  };
3828
3857
 
3829
- //# debugId=031AAABEB97215B864756E2164756E21
3858
+ //# debugId=E7F1511EB71CCCEF64756E2164756E21
3830
3859
  //# sourceMappingURL=index.js.map