@mushi-mushi/web 1.26.0 → 1.28.0

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.cjs CHANGED
@@ -77,7 +77,9 @@ var en = {
77
77
  visual: "Layout, styling, or display problem",
78
78
  confusing: "Hard to understand or navigate",
79
79
  other: "Something else"
80
- }
80
+ },
81
+ moreCategoriesLabel: "More issue types",
82
+ moreCategoriesCount: "{n} more"
81
83
  },
82
84
  step2: {
83
85
  heading: "What happened?",
@@ -214,6 +216,14 @@ var en = {
214
216
  label: "Feature request",
215
217
  description: "Suggest a change"
216
218
  },
219
+ betaStrip: {
220
+ defaultMessage: "{appName} is in early development",
221
+ contactHint: "Reports go to {email} \xB7 reviewed by the team",
222
+ ariaLabel: "Beta status"
223
+ },
224
+ changelog: {
225
+ whatsNew: "What's new in {version}"
226
+ },
217
227
  poweredBy: "Powered by Mushi v{version}"
218
228
  }
219
229
  };
@@ -257,7 +267,9 @@ var ja = {
257
267
  visual: "\u30EC\u30A4\u30A2\u30A6\u30C8\u3001\u30C7\u30B6\u30A4\u30F3\u3001\u8868\u793A\u306E\u554F\u984C",
258
268
  confusing: "\u7406\u89E3\u3057\u306B\u304F\u3044\u3001\u64CD\u4F5C\u304C\u308F\u304B\u308A\u306B\u304F\u3044",
259
269
  other: "\u305D\u306E\u4ED6\u306E\u554F\u984C"
260
- }
270
+ },
271
+ moreCategoriesLabel: "\u305D\u306E\u4ED6\u306E\u554F\u984C\u306E\u7A2E\u985E",
272
+ moreCategoriesCount: "\u4ED6{n}\u4EF6"
261
273
  },
262
274
  step2: {
263
275
  heading: "\u4F55\u304C\u8D77\u304D\u307E\u3057\u305F\u304B\uFF1F",
@@ -394,6 +406,14 @@ var ja = {
394
406
  label: "\u6A5F\u80FD\u30EA\u30AF\u30A8\u30B9\u30C8",
395
407
  description: "\u5909\u66F4\u3092\u63D0\u6848"
396
408
  },
409
+ betaStrip: {
410
+ defaultMessage: "{appName}\u306F\u958B\u767A\u521D\u671F\u6BB5\u968E\u3067\u3059",
411
+ contactHint: "\u30EC\u30DD\u30FC\u30C8\u306F {email} \u306B\u5C4A\u304D\u3001\u30C1\u30FC\u30E0\u304C\u78BA\u8A8D\u3057\u307E\u3059",
412
+ ariaLabel: "\u30D9\u30FC\u30BF\u7248\u306E\u304A\u77E5\u3089\u305B"
413
+ },
414
+ changelog: {
415
+ whatsNew: "{version} \u306E\u65B0\u6A5F\u80FD"
416
+ },
397
417
  poweredBy: "Mushi v{version}"
398
418
  }
399
419
  };
@@ -437,7 +457,9 @@ var th = {
437
457
  visual: "\u0E1B\u0E31\u0E0D\u0E2B\u0E32\u0E40\u0E25\u0E22\u0E4C\u0E40\u0E2D\u0E32\u0E15\u0E4C \u0E2A\u0E44\u0E15\u0E25\u0E4C \u0E2B\u0E23\u0E37\u0E2D\u0E01\u0E32\u0E23\u0E41\u0E2A\u0E14\u0E07\u0E1C\u0E25",
438
458
  confusing: "\u0E40\u0E02\u0E49\u0E32\u0E43\u0E08\u0E22\u0E32\u0E01\u0E2B\u0E23\u0E37\u0E2D\u0E19\u0E33\u0E17\u0E32\u0E07\u0E22\u0E32\u0E01",
439
459
  other: "\u0E2D\u0E22\u0E48\u0E32\u0E07\u0E2D\u0E37\u0E48\u0E19"
440
- }
460
+ },
461
+ moreCategoriesLabel: "\u0E1B\u0E23\u0E30\u0E40\u0E20\u0E17\u0E1B\u0E31\u0E0D\u0E2B\u0E32\u0E2D\u0E37\u0E48\u0E19 \u0E46",
462
+ moreCategoriesCount: "\u0E2D\u0E35\u0E01 {n} \u0E23\u0E32\u0E22\u0E01\u0E32\u0E23"
441
463
  },
442
464
  step2: {
443
465
  heading: "\u0E40\u0E01\u0E34\u0E14\u0E2D\u0E30\u0E44\u0E23\u0E02\u0E36\u0E49\u0E19?",
@@ -574,6 +596,14 @@ var th = {
574
596
  label: "\u0E02\u0E2D\u0E1F\u0E35\u0E40\u0E08\u0E2D\u0E23\u0E4C",
575
597
  description: "\u0E40\u0E2A\u0E19\u0E2D\u0E01\u0E32\u0E23\u0E40\u0E1B\u0E25\u0E35\u0E48\u0E22\u0E19\u0E41\u0E1B\u0E25\u0E07"
576
598
  },
599
+ betaStrip: {
600
+ defaultMessage: "{appName} \u0E2D\u0E22\u0E39\u0E48\u0E23\u0E30\u0E2B\u0E27\u0E48\u0E32\u0E07\u0E01\u0E32\u0E23\u0E1E\u0E31\u0E12\u0E19\u0E32\u0E0A\u0E48\u0E27\u0E07\u0E15\u0E49\u0E19",
601
+ contactHint: "\u0E23\u0E32\u0E22\u0E07\u0E32\u0E19\u0E08\u0E30\u0E2A\u0E48\u0E07\u0E44\u0E1B\u0E17\u0E35\u0E48 {email} \xB7 \u0E17\u0E35\u0E21\u0E07\u0E32\u0E19\u0E15\u0E23\u0E27\u0E08\u0E2A\u0E2D\u0E1A\u0E17\u0E38\u0E01\u0E09\u0E1A\u0E31\u0E1A",
602
+ ariaLabel: "\u0E2A\u0E16\u0E32\u0E19\u0E30\u0E40\u0E1A\u0E15\u0E49\u0E32"
603
+ },
604
+ changelog: {
605
+ whatsNew: "\u0E21\u0E35\u0E2D\u0E30\u0E44\u0E23\u0E43\u0E2B\u0E21\u0E48\u0E43\u0E19 {version}"
606
+ },
577
607
  poweredBy: "Powered by Mushi v{version}"
578
608
  }
579
609
  };
@@ -617,7 +647,9 @@ var es = {
617
647
  visual: "Problema de dise\xF1o, estilo o visualizaci\xF3n",
618
648
  confusing: "Dif\xEDcil de entender o navegar",
619
649
  other: "Otro problema"
620
- }
650
+ },
651
+ moreCategoriesLabel: "M\xE1s tipos de problemas",
652
+ moreCategoriesCount: "{n} m\xE1s"
621
653
  },
622
654
  step2: {
623
655
  heading: "\xBFQu\xE9 pas\xF3?",
@@ -754,6 +786,14 @@ var es = {
754
786
  label: "Solicitud de funci\xF3n",
755
787
  description: "Sugerir un cambio"
756
788
  },
789
+ betaStrip: {
790
+ defaultMessage: "{appName} est\xE1 en desarrollo temprano",
791
+ contactHint: "Los reportes van a {email} \xB7 revisados por el equipo",
792
+ ariaLabel: "Estado beta"
793
+ },
794
+ changelog: {
795
+ whatsNew: "Novedades de {version}"
796
+ },
757
797
  poweredBy: "Con tecnolog\xEDa de Mushi v{version}"
758
798
  }
759
799
  };
@@ -2675,7 +2715,7 @@ function getWidgetStyles(theme, accent = "", accentText = "") {
2675
2715
 
2676
2716
  // src/version.ts
2677
2717
  var MUSHI_SDK_PACKAGE = "@mushi-mushi/web";
2678
- var MUSHI_SDK_VERSION = "1.26.0" ;
2718
+ var MUSHI_SDK_VERSION = "1.28.0" ;
2679
2719
  var ASSISTANT_SESSION_STORAGE_KEY = "mushi-assistant-session-v1";
2680
2720
  function loadAssistantSession() {
2681
2721
  try {
@@ -3103,8 +3143,8 @@ function renderCategoryStep(ctx) {
3103
3143
  const primaryCategories = primaryEntries.map(renderEntry).join("");
3104
3144
  const secondaryCategories = secondaryEntries.map(renderEntry).join("");
3105
3145
  const secondaryHtml = hasMore ? ctx.showAllCategories ? `<div class="mushi-categories-expanded">${secondaryCategories}</div>` : `<button type="button" class="mushi-more-toggle" data-action="show-all-categories">
3106
- <span class="mushi-more-toggle-text">More issue types</span>
3107
- <span class="mushi-more-toggle-count">${secondaryEntries.length} more</span>
3146
+ <span class="mushi-more-toggle-text">${escapeHtml(t.step1.moreCategoriesLabel)}</span>
3147
+ <span class="mushi-more-toggle-count">${escapeHtml(t.step1.moreCategoriesCount.replace("{n}", String(secondaryEntries.length)))}</span>
3108
3148
  <span class="mushi-more-toggle-arrow" aria-hidden="true">\u2192</span>
3109
3149
  </button>` : "";
3110
3150
  return `
@@ -3147,7 +3187,10 @@ function renderBetaChangelog(ctx) {
3147
3187
  if (!entries?.length) return "";
3148
3188
  const latest = entries[0];
3149
3189
  const items = latest.items.map((item) => `<li>\u2022 ${escapeHtml(item)}</li>`).join("");
3150
- const label = latest.date ? `What\u2019s new in ${escapeHtml(latest.version)} \xB7 ${escapeHtml(latest.date)}` : `What\u2019s new in ${escapeHtml(latest.version)}`;
3190
+ const whatsNew = escapeHtml(
3191
+ ctx.locale.flows.changelog.whatsNew.replace("{version}", latest.version)
3192
+ );
3193
+ const label = latest.date ? `${whatsNew} \xB7 ${escapeHtml(latest.date)}` : whatsNew;
3151
3194
  return `
3152
3195
  <details class="mushi-changelog">
3153
3196
  <summary class="mushi-changelog-summary">${label}</summary>
@@ -3157,17 +3200,18 @@ function renderBetaChangelog(ctx) {
3157
3200
  }
3158
3201
  function renderBetaStrip(ctx) {
3159
3202
  const beta = ctx.config.betaMode;
3203
+ const strip = ctx.locale.flows.betaStrip;
3160
3204
  const appName = escapeHtml(beta.appName ?? "This app");
3161
- const message = beta.message ? escapeHtml(beta.message) : `${appName} is in early development`;
3205
+ const message = beta.message ? escapeHtml(beta.message) : escapeHtml(strip.defaultMessage).replace("{appName}", appName);
3162
3206
  const email = beta.contactEmail ? escapeHtml(beta.contactEmail) : null;
3163
3207
  const perks = beta.perks ?? [];
3164
3208
  return `
3165
- <div class="mushi-beta-strip" role="note" aria-label="Beta status">
3209
+ <div class="mushi-beta-strip" role="note" aria-label="${escapeHtml(strip.ariaLabel)}">
3166
3210
  <div class="mushi-beta-strip-row">
3167
3211
  <span class="mushi-beta-tag" aria-hidden="true">BETA</span>
3168
3212
  <span class="mushi-beta-msg">${message}</span>
3169
3213
  </div>
3170
- ${email ? `<div class="mushi-beta-contact-hint">Reports go to ${email} \xB7 reviewed by the team</div>` : ""}
3214
+ ${email ? `<div class="mushi-beta-contact-hint">${escapeHtml(strip.contactHint).replace("{email}", email)}</div>` : ""}
3171
3215
  ${perks.length > 0 ? `
3172
3216
  <ul class="mushi-beta-perks" aria-label="Beta tester perks">
3173
3217
  ${perks.map((p) => `<li>\u2713 ${escapeHtml(p)}</li>`).join("")}
@@ -6335,59 +6379,6 @@ function renderConsentBanner(projectId, config) {
6335
6379
  });
6336
6380
  document.body.appendChild(consentHost);
6337
6381
  }
6338
-
6339
- // src/capture/console.ts
6340
- var MAX_ENTRIES = 50;
6341
- var MAX_MESSAGE_LENGTH = 500;
6342
- function createConsoleCapture() {
6343
- const entries = [];
6344
- const originals = {};
6345
- const wrappers = {};
6346
- const levels = ["log", "warn", "error", "info", "debug"];
6347
- for (const level of levels) {
6348
- const original = console[level];
6349
- originals[level] = original;
6350
- const wrapper = (...args) => {
6351
- const message = args.map((arg) => {
6352
- try {
6353
- return typeof arg === "string" ? arg : JSON.stringify(arg);
6354
- } catch {
6355
- return String(arg);
6356
- }
6357
- }).join(" ").slice(0, MAX_MESSAGE_LENGTH);
6358
- const entry = {
6359
- level,
6360
- message,
6361
- timestamp: Date.now()
6362
- };
6363
- if (level === "error" && args[0] instanceof Error) {
6364
- entry.stack = args[0].stack?.slice(0, 1e3);
6365
- }
6366
- entries.push(entry);
6367
- if (entries.length > MAX_ENTRIES) {
6368
- entries.shift();
6369
- }
6370
- original.call(console, ...args);
6371
- };
6372
- wrappers[level] = wrapper;
6373
- console[level] = wrapper;
6374
- }
6375
- return {
6376
- getEntries() {
6377
- return [...entries];
6378
- },
6379
- clear() {
6380
- entries.length = 0;
6381
- },
6382
- destroy() {
6383
- for (const level of levels) {
6384
- if (originals[level] && console[level] === wrappers[level]) {
6385
- console[level] = originals[level];
6386
- }
6387
- }
6388
- }
6389
- };
6390
- }
6391
6382
  var DEFAULT_INTERNAL_URL_MATCHERS = [
6392
6383
  /\/v1\/sdk(?:\/|$)/,
6393
6384
  /\/v1\/reports(?:\/|$)/,
@@ -6451,7 +6442,7 @@ function readHeader(headers, name) {
6451
6442
  }
6452
6443
 
6453
6444
  // src/capture/network.ts
6454
- var MAX_ENTRIES2 = 30;
6445
+ var MAX_ENTRIES = 30;
6455
6446
  var TRACEPARENT_VERSION = "00";
6456
6447
  function generateTraceparent() {
6457
6448
  const traceBytes = crypto.getRandomValues(new Uint8Array(16));
@@ -6475,17 +6466,29 @@ function matchesCorsUrls(url, corsUrls) {
6475
6466
  }
6476
6467
  return false;
6477
6468
  }
6469
+ var _activeCorrelationStack = [];
6470
+ function getActiveCorrelationId() {
6471
+ return _activeCorrelationStack[_activeCorrelationStack.length - 1];
6472
+ }
6473
+ function generateCorrelationId() {
6474
+ const bytes = crypto.getRandomValues(new Uint8Array(4));
6475
+ return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
6476
+ }
6478
6477
  function createNetworkCapture(options = {}) {
6479
6478
  const entries = [];
6480
6479
  const originalFetch = globalThis.fetch;
6480
+ const OriginalXHR = typeof XMLHttpRequest !== "undefined" ? XMLHttpRequest : null;
6481
+ const originalXhrOpen = OriginalXHR ? XMLHttpRequest.prototype.open : null;
6482
+ const originalXhrSend = OriginalXHR ? XMLHttpRequest.prototype.send : null;
6483
+ const originalXhrSetRequestHeader = OriginalXHR ? XMLHttpRequest.prototype.setRequestHeader : null;
6481
6484
  let activeOptions = options;
6482
- let fetchWrapper;
6483
- globalThis.fetch = fetchWrapper = async function mushiFetchInterceptor(input, init) {
6485
+ const fetchWrapper = async function mushiFetchInterceptor(input, init) {
6484
6486
  const startTime = Date.now();
6485
6487
  const method = init?.method?.toUpperCase() ?? "GET";
6486
6488
  const url = getRequestUrl(input);
6487
6489
  const internalKind = getInternalRequestKind(input, init);
6488
6490
  const shouldRecord = !internalKind && !shouldIgnoreMushiUrl(url, activeOptions);
6491
+ const correlationId = shouldRecord ? generateCorrelationId() : void 0;
6489
6492
  let traceId;
6490
6493
  let patchedInit = init;
6491
6494
  const tp = activeOptions.tracePropagation;
@@ -6499,6 +6502,7 @@ function createNetworkCapture(options = {}) {
6499
6502
  }
6500
6503
  patchedInit = { ...init, headers: existingHeaders };
6501
6504
  }
6505
+ if (correlationId) _activeCorrelationStack.push(correlationId);
6502
6506
  try {
6503
6507
  const response = await originalFetch.call(globalThis, input, patchedInit);
6504
6508
  if (shouldRecord) {
@@ -6508,7 +6512,9 @@ function createNetworkCapture(options = {}) {
6508
6512
  status: response.status,
6509
6513
  duration: Date.now() - startTime,
6510
6514
  timestamp: startTime,
6511
- ...traceId ? { traceId } : {}
6515
+ captureMethod: "fetch",
6516
+ ...traceId ? { traceId } : {},
6517
+ ...correlationId ? { correlationId } : {}
6512
6518
  });
6513
6519
  }
6514
6520
  return response;
@@ -6521,15 +6527,100 @@ function createNetworkCapture(options = {}) {
6521
6527
  duration: Date.now() - startTime,
6522
6528
  timestamp: startTime,
6523
6529
  error: error instanceof Error ? error.message : "Network error",
6524
- ...traceId ? { traceId } : {}
6530
+ captureMethod: "fetch",
6531
+ ...traceId ? { traceId } : {},
6532
+ ...correlationId ? { correlationId } : {}
6525
6533
  });
6526
6534
  }
6527
6535
  throw error;
6536
+ } finally {
6537
+ if (correlationId) {
6538
+ const idx = _activeCorrelationStack.lastIndexOf(correlationId);
6539
+ if (idx !== -1) _activeCorrelationStack.splice(idx, 1);
6540
+ }
6528
6541
  }
6529
6542
  };
6543
+ globalThis.fetch = fetchWrapper;
6544
+ const xhrStateMap = typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : null;
6545
+ if (OriginalXHR && originalXhrOpen && originalXhrSend && originalXhrSetRequestHeader && xhrStateMap) {
6546
+ const _originalOpen = originalXhrOpen;
6547
+ XMLHttpRequest.prototype.open = function mushiXhrOpen(...args) {
6548
+ const [method, url] = args;
6549
+ const urlStr = typeof url === "string" ? url : String(url);
6550
+ const shouldRecord = !shouldIgnoreMushiUrl(urlStr, activeOptions);
6551
+ const correlationId = shouldRecord ? generateCorrelationId() : void 0;
6552
+ let traceId;
6553
+ let storedTraceparent;
6554
+ const tp = activeOptions.tracePropagation;
6555
+ if (shouldRecord && tp?.enabled && tp.corsUrls?.length && matchesCorsUrls(urlStr, tp.corsUrls)) {
6556
+ const generated = generateTraceparent();
6557
+ traceId = generated.traceId;
6558
+ storedTraceparent = generated.traceparent;
6559
+ }
6560
+ const _prevXhrState = xhrStateMap.get(this);
6561
+ if (_prevXhrState?._listener) {
6562
+ this.removeEventListener("readystatechange", _prevXhrState._listener);
6563
+ }
6564
+ xhrStateMap.set(this, {
6565
+ method: String(method).toUpperCase(),
6566
+ url: truncateUrl(urlStr),
6567
+ startTime: 0,
6568
+ // set in .send()
6569
+ shouldRecord,
6570
+ ...traceId ? { traceId } : {},
6571
+ ...correlationId ? { correlationId } : {},
6572
+ // Attach the traceparent string as an extra prop for injection in .send().
6573
+ ...storedTraceparent ? { _traceparent: storedTraceparent } : {}
6574
+ });
6575
+ _originalOpen.apply(this, args);
6576
+ };
6577
+ XMLHttpRequest.prototype.send = function mushiXhrSend(body) {
6578
+ const state = xhrStateMap.get(this);
6579
+ if (state) {
6580
+ state.startTime = Date.now();
6581
+ const xhrTraceparent = state._traceparent;
6582
+ if (xhrTraceparent) {
6583
+ originalXhrSetRequestHeader.call(this, "traceparent", xhrTraceparent);
6584
+ if (activeOptions.sessionId) {
6585
+ originalXhrSetRequestHeader.call(this, "x-mushi-session", activeOptions.sessionId);
6586
+ }
6587
+ }
6588
+ if (state.correlationId) _activeCorrelationStack.push(state.correlationId);
6589
+ const _readystateHandler = () => {
6590
+ if (this.readyState !== 4) return;
6591
+ if (state.shouldRecord) {
6592
+ const duration = Date.now() - state.startTime;
6593
+ const entry = {
6594
+ method: state.method,
6595
+ url: state.url,
6596
+ status: this.status,
6597
+ duration,
6598
+ timestamp: state.startTime,
6599
+ captureMethod: "xhr",
6600
+ ...state.traceId ? { traceId: state.traceId } : {},
6601
+ ...state.correlationId ? { correlationId: state.correlationId } : {}
6602
+ };
6603
+ if (this.status === 0) {
6604
+ entry.error = "XHR network error or aborted";
6605
+ }
6606
+ addEntry(entry);
6607
+ }
6608
+ if (state.correlationId) {
6609
+ const idx = _activeCorrelationStack.lastIndexOf(state.correlationId);
6610
+ if (idx !== -1) _activeCorrelationStack.splice(idx, 1);
6611
+ }
6612
+ };
6613
+ state._listener = _readystateHandler;
6614
+ this.addEventListener("readystatechange", _readystateHandler);
6615
+ }
6616
+ originalXhrSend.call(this, body);
6617
+ };
6618
+ }
6619
+ const xhrOpenWrapper = OriginalXHR ? XMLHttpRequest.prototype.open : null;
6620
+ const xhrSendWrapper = OriginalXHR ? XMLHttpRequest.prototype.send : null;
6530
6621
  function addEntry(entry) {
6531
6622
  entries.push(entry);
6532
- if (entries.length > MAX_ENTRIES2) {
6623
+ if (entries.length > MAX_ENTRIES) {
6533
6624
  entries.shift();
6534
6625
  }
6535
6626
  }
@@ -6547,22 +6638,86 @@ function createNetworkCapture(options = {}) {
6547
6638
  if (globalThis.fetch === fetchWrapper) {
6548
6639
  globalThis.fetch = originalFetch;
6549
6640
  }
6641
+ if (OriginalXHR && originalXhrOpen && originalXhrSend) {
6642
+ if (xhrOpenWrapper && XMLHttpRequest.prototype.open === xhrOpenWrapper) {
6643
+ XMLHttpRequest.prototype.open = originalXhrOpen;
6644
+ }
6645
+ if (xhrSendWrapper && XMLHttpRequest.prototype.send === xhrSendWrapper) {
6646
+ XMLHttpRequest.prototype.send = originalXhrSend;
6647
+ }
6648
+ }
6550
6649
  }
6551
6650
  };
6552
6651
  }
6553
6652
  function truncateUrl(url) {
6653
+ const scrubbed = core.scrubUrl(url);
6554
6654
  try {
6555
- const parsed = new URL(url);
6655
+ const parsed = new URL(scrubbed);
6556
6656
  const path = parsed.pathname + parsed.search;
6557
6657
  if (path.length > 200) {
6558
6658
  return parsed.origin + path.slice(0, 200) + "...";
6559
6659
  }
6560
6660
  return parsed.origin + path;
6561
6661
  } catch {
6562
- return url.slice(0, 200);
6662
+ return scrubbed.slice(0, 200);
6563
6663
  }
6564
6664
  }
6565
6665
 
6666
+ // src/capture/console.ts
6667
+ var MAX_ENTRIES2 = 50;
6668
+ var MAX_MESSAGE_LENGTH = 500;
6669
+ function createConsoleCapture() {
6670
+ const entries = [];
6671
+ const originals = {};
6672
+ const wrappers = {};
6673
+ const levels = ["log", "warn", "error", "info", "debug"];
6674
+ for (const level of levels) {
6675
+ const original = console[level];
6676
+ originals[level] = original;
6677
+ const wrapper = (...args) => {
6678
+ const message = args.map((arg) => {
6679
+ try {
6680
+ return typeof arg === "string" ? arg : JSON.stringify(arg);
6681
+ } catch {
6682
+ return String(arg);
6683
+ }
6684
+ }).join(" ").slice(0, MAX_MESSAGE_LENGTH);
6685
+ const correlationId = getActiveCorrelationId();
6686
+ const entry = {
6687
+ level,
6688
+ message,
6689
+ timestamp: Date.now(),
6690
+ ...correlationId ? { correlationId } : {}
6691
+ };
6692
+ if (level === "error" && args[0] instanceof Error) {
6693
+ entry.stack = args[0].stack?.slice(0, 1e3);
6694
+ }
6695
+ entries.push(entry);
6696
+ if (entries.length > MAX_ENTRIES2) {
6697
+ entries.shift();
6698
+ }
6699
+ original.call(console, ...args);
6700
+ };
6701
+ wrappers[level] = wrapper;
6702
+ console[level] = wrapper;
6703
+ }
6704
+ return {
6705
+ getEntries() {
6706
+ return [...entries];
6707
+ },
6708
+ clear() {
6709
+ entries.length = 0;
6710
+ },
6711
+ destroy() {
6712
+ for (const level of levels) {
6713
+ if (originals[level] && console[level] === wrappers[level]) {
6714
+ console[level] = originals[level];
6715
+ }
6716
+ }
6717
+ }
6718
+ };
6719
+ }
6720
+
6566
6721
  // src/capture/screenshot.ts
6567
6722
  function createScreenshotCapture(options = {}) {
6568
6723
  let activeOptions = options;
@@ -7096,8 +7251,6 @@ function createElementSelector() {
7096
7251
  }
7097
7252
  return { activate, deactivate, isActive: () => active };
7098
7253
  }
7099
-
7100
- // src/capture/timeline.ts
7101
7254
  var MAX_TIMELINE_ENTRIES = 120;
7102
7255
  function createTimelineCapture() {
7103
7256
  const entries = [];
@@ -7114,8 +7267,11 @@ function createTimelineCapture() {
7114
7267
  kind: "route",
7115
7268
  payload: {
7116
7269
  source,
7117
- route: `${location.pathname}${location.search}${location.hash}`,
7118
- href: location.href
7270
+ // Query VALUES are a PII channel (`?token=…`, `?email=…`) — scrub
7271
+ // them at capture, both in the search string and inside hash-router
7272
+ // fragments (`#/path?query`). Keys and paths are preserved.
7273
+ route: core.scrubUrl(`${location.pathname}${location.search}${location.hash}`),
7274
+ href: core.scrubUrl(location.href)
7119
7275
  }
7120
7276
  });
7121
7277
  }
@@ -7202,6 +7358,18 @@ function normalizeSegment(seg) {
7202
7358
  if (SLUG_HASHY_RE.test(seg) && /\d/.test(seg)) return "[id]";
7203
7359
  return seg;
7204
7360
  }
7361
+ function deriveRoute(pathname, hash, templates) {
7362
+ if (hash.startsWith("#/")) {
7363
+ const raw = hash.slice(1);
7364
+ const qIdx = raw.indexOf("?");
7365
+ const hashPath = qIdx === -1 ? raw : raw.slice(0, qIdx);
7366
+ const hashTemplates = templates?.map(
7367
+ (t) => t.startsWith("/#/") ? t.slice(2) : t
7368
+ );
7369
+ return "/#" + normalizeRoute(hashPath, hashTemplates);
7370
+ }
7371
+ return normalizeRoute(pathname, templates);
7372
+ }
7205
7373
  function normalizeRoute(pathname, templates) {
7206
7374
  const clean = pathname.length > 1 && pathname.endsWith("/") ? pathname.slice(0, -1) : pathname;
7207
7375
  if (templates?.length) {
@@ -7245,9 +7413,14 @@ function readTestids() {
7245
7413
  function readQueryParamKeys() {
7246
7414
  if (typeof window === "undefined") return [];
7247
7415
  try {
7248
- const params = new URLSearchParams(window.location.search);
7249
7416
  const out = /* @__PURE__ */ new Set();
7250
- params.forEach((_, key) => out.add(key));
7417
+ const collect = (qs) => {
7418
+ new URLSearchParams(qs).forEach((_, key) => out.add(key));
7419
+ };
7420
+ collect(window.location.search);
7421
+ const hash = window.location.hash;
7422
+ const qIdx = hash.indexOf("?");
7423
+ if (hash.startsWith("#/") && qIdx !== -1) collect(hash.slice(qIdx + 1));
7251
7424
  return Array.from(out).sort();
7252
7425
  } catch {
7253
7426
  return [];
@@ -7294,7 +7467,11 @@ function createDiscoveryCapture(opts) {
7294
7467
  let pendingTimer = null;
7295
7468
  async function emitForCurrent() {
7296
7469
  if (typeof window === "undefined") return;
7297
- const route = normalizeRoute(window.location.pathname, config.routeTemplates);
7470
+ const route = deriveRoute(
7471
+ window.location.pathname,
7472
+ window.location.hash,
7473
+ config.routeTemplates
7474
+ );
7298
7475
  const now = Date.now();
7299
7476
  const last = lastEmittedAt.get(route) ?? 0;
7300
7477
  if (now - last < throttleMs) return;
@@ -7326,7 +7503,8 @@ function createDiscoveryCapture(opts) {
7326
7503
  }
7327
7504
  function onMaybeNavigation() {
7328
7505
  if (typeof window === "undefined") return;
7329
- const path = window.location.pathname + window.location.search;
7506
+ const hashPart = window.location.hash.startsWith("#/") ? window.location.hash : "";
7507
+ const path = window.location.pathname + window.location.search + hashPart;
7330
7508
  if (path === lastPath) return;
7331
7509
  lastPath = path;
7332
7510
  scheduleEmit();
@@ -7343,10 +7521,12 @@ function createDiscoveryCapture(opts) {
7343
7521
  onReplace: onNav,
7344
7522
  onPop: onNav
7345
7523
  });
7524
+ window.addEventListener("hashchange", onNav);
7346
7525
  scheduleEmit();
7347
7526
  return {
7348
7527
  destroy() {
7349
7528
  unsubHistory();
7529
+ window.removeEventListener("hashchange", onNav);
7350
7530
  if (pendingTimer) {
7351
7531
  clearTimeout(pendingTimer);
7352
7532
  pendingTimer = null;
@@ -7819,8 +7999,6 @@ function tagSentryScope(reportId, options = {}) {
7819
7999
  } catch {
7820
8000
  }
7821
8001
  }
7822
-
7823
- // src/proactive-triggers.ts
7824
8002
  var DEFAULT_EXCLUDE_ROUTES = [
7825
8003
  "/login",
7826
8004
  "/logout",
@@ -7963,6 +8141,15 @@ function setupProactiveTriggers(callbacks, config = {}) {
7963
8141
  }
7964
8142
  if (config.errorBoundary) {
7965
8143
  let handleError2 = function(event) {
8144
+ if (core.shouldDropCapturedError({
8145
+ message: event.message,
8146
+ filename: event.filename,
8147
+ ignoreErrors: config.ignoreErrors,
8148
+ denyUrls: config.denyUrls,
8149
+ allowUrls: config.allowUrls
8150
+ })) {
8151
+ return;
8152
+ }
7966
8153
  callbacks.onTrigger("error_boundary", {
7967
8154
  message: event.message,
7968
8155
  filename: event.filename,
@@ -7970,8 +8157,17 @@ function setupProactiveTriggers(callbacks, config = {}) {
7970
8157
  colno: event.colno
7971
8158
  });
7972
8159
  }, handleUnhandledRejection2 = function(event) {
8160
+ const message = event.reason instanceof Error ? event.reason.message : String(event.reason);
8161
+ if (core.shouldDropCapturedError({
8162
+ message,
8163
+ ignoreErrors: config.ignoreErrors,
8164
+ denyUrls: config.denyUrls,
8165
+ allowUrls: config.allowUrls
8166
+ })) {
8167
+ return;
8168
+ }
7973
8169
  callbacks.onTrigger("error_boundary", {
7974
- message: event.reason instanceof Error ? event.reason.message : String(event.reason),
8170
+ message,
7975
8171
  type: "unhandled_rejection"
7976
8172
  });
7977
8173
  };
@@ -8134,6 +8330,7 @@ function createInstance(config) {
8134
8330
  ...typeof bootstrapConfig.timeout === "number" ? { timeout: bootstrapConfig.timeout } : {},
8135
8331
  ...typeof bootstrapConfig.maxRetries === "number" ? { maxRetries: bootstrapConfig.maxRetries } : {},
8136
8332
  ...bootstrapConfig.circuitBreaker ? { circuitBreaker: bootstrapConfig.circuitBreaker } : {},
8333
+ ...bootstrapConfig.tunnel ? { tunnel: bootstrapConfig.tunnel } : {},
8137
8334
  getUserToken: () => userToken,
8138
8335
  sdkPackage: MUSHI_SDK_PACKAGE,
8139
8336
  sdkVersion: MUSHI_SDK_VERSION
@@ -8165,6 +8362,14 @@ function createInstance(config) {
8165
8362
  return next;
8166
8363
  });
8167
8364
  }
8365
+ function scrubConsoleForWire(logs) {
8366
+ if (!logs) return logs;
8367
+ return logs.map((entry) => ({
8368
+ ...entry,
8369
+ message: piiScrubber.scrub(entry.message),
8370
+ ...entry.stack ? { stack: piiScrubber.scrub(entry.stack) } : {}
8371
+ }));
8372
+ }
8168
8373
  function scrubTagsForWire(tags) {
8169
8374
  if (!tags) return void 0;
8170
8375
  const out = {};
@@ -8313,7 +8518,11 @@ function createInstance(config) {
8313
8518
  discoveryCap = null;
8314
8519
  }
8315
8520
  const replayMode = activeConfig.capture?.replay ?? "off";
8316
- if (replayMode === "rrweb" || replayMode === "lite") {
8521
+ const replaySampleRate = activeConfig.replaySampleRate ?? 1;
8522
+ const replaySampled = replaySampleRate >= 1 || Math.random() < replaySampleRate;
8523
+ const onErrorReplayRate = activeConfig.replaysOnErrorSampleRate ?? 0;
8524
+ const replayOnErrorSampled = !replaySampled && onErrorReplayRate > 0 && Math.random() < onErrorReplayRate;
8525
+ if ((replayMode === "rrweb" || replayMode === "lite") && (replaySampled || replayOnErrorSampled)) {
8317
8526
  const generation = ++replayGeneration;
8318
8527
  void createReplayCapture({
8319
8528
  redactSelectors: activeConfig.privacy?.redactSelectors
@@ -8732,6 +8941,9 @@ function createInstance(config) {
8732
8941
  apiCascade: proactiveCfg?.apiCascade,
8733
8942
  apiEndpoint: resolveApiEndpoint(activeConfig),
8734
8943
  errorBoundary: proactiveCfg?.errorBoundary,
8944
+ ignoreErrors: activeConfig.ignoreErrors,
8945
+ denyUrls: activeConfig.denyUrls,
8946
+ allowUrls: activeConfig.allowUrls,
8735
8947
  pageDwell: proactiveCfg?.pageDwell,
8736
8948
  firstSession: proactiveCfg?.firstSession,
8737
8949
  projectId: bootstrapConfig.projectId
@@ -8852,6 +9064,13 @@ function createInstance(config) {
8852
9064
  });
8853
9065
  }
8854
9066
  }
9067
+ const isAutomatic = pendingProactiveTrigger !== null;
9068
+ if (isAutomatic && config.sampleRate !== void 0 && config.sampleRate < 1) {
9069
+ if (config.sampleRate <= 0 || Math.random() > config.sampleRate) {
9070
+ log.debug("Report dropped by sampleRate", { sampleRate: config.sampleRate, trigger: pendingProactiveTrigger });
9071
+ return void 0;
9072
+ }
9073
+ }
8855
9074
  if (!rateLimiter.tryConsume()) {
8856
9075
  log.warn("Report throttled \u2014 rate limit exceeded");
8857
9076
  return void 0;
@@ -8859,7 +9078,7 @@ function createInstance(config) {
8859
9078
  const scrubbedDescription = piiScrubber.scrub(preFilter.truncate(description));
8860
9079
  const sentryCtx = config.sentry ? captureSentryContext(config.sentry) : void 0;
8861
9080
  const fingerprintHash = await core.getDeviceFingerprintHash().catch(() => null);
8862
- const consoleLogs = activeConfig.capture?.console === false ? void 0 : consoleCap?.getEntries();
9081
+ const consoleLogs = activeConfig.capture?.console === false ? void 0 : scrubConsoleForWire(consoleCap?.getEntries());
8863
9082
  const networkLogs = activeConfig.capture?.network === false ? void 0 : networkCap?.getEntries();
8864
9083
  const reportBreadcrumbs = scrubBreadcrumbsForWire(breadcrumbs.getAll());
8865
9084
  const stickyTagSnapshot = scrubTagsForWire(
@@ -8937,10 +9156,11 @@ function createInstance(config) {
8937
9156
  config.integrations.custom(builder);
8938
9157
  }
8939
9158
  let finalReport = report;
8940
- if (config.beforeSendFeedback) {
9159
+ const sendHook = config.beforeSend ?? config.beforeSendFeedback;
9160
+ if (sendHook) {
8941
9161
  try {
8942
9162
  const hookResult = await Promise.race([
8943
- Promise.resolve(config.beforeSendFeedback(report)),
9163
+ Promise.resolve(sendHook(report)),
8944
9164
  // 2s timeout — async hooks must not block the user's "submit"
8945
9165
  // for longer than the network would. Falls back to original.
8946
9166
  new Promise(
@@ -8948,12 +9168,12 @@ function createInstance(config) {
8948
9168
  )
8949
9169
  ]);
8950
9170
  if (hookResult === null) {
8951
- log.info("Report dropped by beforeSendFeedback hook", { reportId: report.id });
9171
+ log.info("Report dropped by beforeSend hook", { reportId: report.id });
8952
9172
  return;
8953
9173
  }
8954
9174
  finalReport = hookResult;
8955
9175
  } catch (err) {
8956
- log.warn("beforeSendFeedback hook threw \u2014 sending unmodified report", {
9176
+ log.warn("beforeSend hook threw \u2014 sending unmodified report", {
8957
9177
  error: err instanceof Error ? err.message : String(err)
8958
9178
  });
8959
9179
  }
@@ -9231,6 +9451,16 @@ function createInstance(config) {
9231
9451
  },
9232
9452
  async captureException(error, options) {
9233
9453
  const normalised = core.normaliseThrown(error);
9454
+ const filename = typeof options?.metadata?.filename === "string" ? options.metadata.filename : void 0;
9455
+ if (core.shouldDropCapturedError({
9456
+ message: normalised.message,
9457
+ filename,
9458
+ ignoreErrors: activeConfig.ignoreErrors,
9459
+ denyUrls: activeConfig.denyUrls,
9460
+ allowUrls: activeConfig.allowUrls
9461
+ })) {
9462
+ return null;
9463
+ }
9234
9464
  breadcrumbs.add({
9235
9465
  category: "lifecycle",
9236
9466
  level: "error",
@@ -9424,6 +9654,8 @@ function createInstance(config) {
9424
9654
  localStorage.setItem(SENTINEL_KEY, "clean");
9425
9655
  } catch {
9426
9656
  }
9657
+ core.markPageUnloading();
9658
+ core.flushLastOutboundOnUnload();
9427
9659
  });
9428
9660
  } catch {
9429
9661
  }