@absolutejs/beacon 0.6.22 → 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;
@@ -3175,15 +3182,16 @@ var createBeacon = (options) => {
3175
3182
  submittedForms.add(event.target);
3176
3183
  dirtyForms.delete(event.target);
3177
3184
  };
3178
- const report = () => {
3185
+ const report = (departedUrl = location.href) => {
3179
3186
  for (const form of dirtyForms) {
3180
3187
  if (!form.isConnected || submittedForms.has(form))
3181
3188
  continue;
3182
3189
  const name = form.getAttribute(BEACON_ATTRIBUTE.FORM)?.trim() || describeElement(form);
3183
- emitSignal(`Form abandonment — ${name} left dirty — ${shortUrl(location.href)}`, {
3190
+ emitSignal(`Form abandonment — ${name} left dirty — ${shortUrl(departedUrl)}`, {
3184
3191
  fieldCount: String(form.elements.length),
3185
3192
  signal: BEACON_SIGNAL.FORM_ABANDONMENT,
3186
- target: name
3193
+ target: name,
3194
+ url: shortUrl(departedUrl)
3187
3195
  });
3188
3196
  dirtyForms.delete(form);
3189
3197
  }
@@ -3191,12 +3199,13 @@ var createBeacon = (options) => {
3191
3199
  reportFormAbandonmentOnNavigation = report;
3192
3200
  document.addEventListener("input", onInput, true);
3193
3201
  document.addEventListener("submit", onSubmit, true);
3194
- window.addEventListener("pagehide", report);
3202
+ const reportOnPageHide = () => report();
3203
+ window.addEventListener("pagehide", reportOnPageHide);
3195
3204
  cleanups.push(() => {
3196
3205
  reportFormAbandonmentOnNavigation = null;
3197
3206
  document.removeEventListener("input", onInput, true);
3198
3207
  document.removeEventListener("submit", onSubmit, true);
3199
- window.removeEventListener("pagehide", report);
3208
+ window.removeEventListener("pagehide", reportOnPageHide);
3200
3209
  });
3201
3210
  }
3202
3211
  }
@@ -3734,18 +3743,33 @@ var createBeacon = (options) => {
3734
3743
  });
3735
3744
  }
3736
3745
  if (instrument.history !== false && typeof history !== "undefined") {
3746
+ let recordedHistoryUrl = location.href;
3737
3747
  const record = () => {
3738
3748
  addBreadcrumb({
3739
3749
  message: `navigate ${location.pathname}${location.search}`,
3740
3750
  type: "navigation"
3741
3751
  });
3752
+ recordedHistoryUrl = location.href;
3742
3753
  overflowScanOnNavigation?.();
3743
3754
  };
3744
3755
  const patch = (key) => {
3745
3756
  const original = history[key].bind(history);
3746
3757
  history[key] = (...args) => {
3747
- 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
+ }
3748
3769
  const result = original(...args);
3770
+ if (!changesUrl)
3771
+ return result;
3772
+ reportFormAbandonmentOnNavigation?.(departedUrl);
3749
3773
  record();
3750
3774
  return result;
3751
3775
  };
@@ -3755,7 +3779,9 @@ var createBeacon = (options) => {
3755
3779
  };
3756
3780
  cleanups.push(patch("pushState"), patch("replaceState"));
3757
3781
  const onPopState = () => {
3758
- reportFormAbandonmentOnNavigation?.();
3782
+ if (location.href === recordedHistoryUrl)
3783
+ return;
3784
+ reportFormAbandonmentOnNavigation?.(recordedHistoryUrl);
3759
3785
  record();
3760
3786
  };
3761
3787
  window.addEventListener("popstate", onPopState);
@@ -3829,5 +3855,5 @@ export {
3829
3855
  BEACON_ATTRIBUTE
3830
3856
  };
3831
3857
 
3832
- //# debugId=757A87482E13AD7364756E2164756E21
3858
+ //# debugId=E7F1511EB71CCCEF64756E2164756E21
3833
3859
  //# sourceMappingURL=index.js.map