glitchgrab 1.67.0 → 1.68.1

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.mjs CHANGED
@@ -159,9 +159,11 @@ var SENSITIVE_KEY_RE = /(pass|pwd|secret|token|auth|session|cookie|credential|ap
159
159
  var EMAIL_RE = /[\w.+-]+@[\w-]+\.[\w.-]+/g;
160
160
  var JWT_RE = /\beyJ[\w-]{8,}\.[\w-]{8,}\.[\w-]{8,}\b/g;
161
161
  var BEARER_RE = /\b(bearer\s+)[\w-.~+/]{12,}=*/gi;
162
+ var KEY_PREFIX_RE = /\b(?:(?:sk|rk|pk)_(?:live|test)_[A-Za-z0-9]{10,}|sk-[A-Za-z0-9_-]{16,}|gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,}|AKIA[0-9A-Z]{16}|xox[abposr]-[A-Za-z0-9-]{10,}|gg[cswi]?_[A-Za-z0-9]{20,})\b/g;
162
163
  var MAX_BODY_LENGTH = 500;
164
+ var URL_CREDENTIALS_RE = /\b([a-z][a-z0-9+.-]*:\/\/[^\s:@/]+):[^\s@/]+@/gi;
163
165
  function redactString(value) {
164
- return value.replace(JWT_RE, "[REDACTED]").replace(BEARER_RE, "$1[REDACTED]").replace(EMAIL_RE, "[REDACTED_EMAIL]");
166
+ return value.replace(URL_CREDENTIALS_RE, "$1:[REDACTED]@").replace(KEY_PREFIX_RE, "[REDACTED]").replace(JWT_RE, "[REDACTED]").replace(BEARER_RE, "$1[REDACTED]").replace(EMAIL_RE, "[REDACTED_EMAIL]");
165
167
  }
166
168
  function redactValue(value, depth) {
167
169
  if (depth > 4) return "[DEPTH]";
@@ -210,6 +212,29 @@ function mayCaptureBody(url) {
210
212
  return false;
211
213
  }
212
214
  }
215
+ var consoleObserver = null;
216
+ var requestObserver = null;
217
+ function setConsoleObserver(observer2) {
218
+ consoleObserver = observer2;
219
+ }
220
+ function setRequestObserver(observer2) {
221
+ requestObserver = observer2;
222
+ }
223
+ function isOwnOrigin(url) {
224
+ return mayCaptureBody(url);
225
+ }
226
+ function notifyConsole(level, args) {
227
+ try {
228
+ consoleObserver == null ? void 0 : consoleObserver(level, args);
229
+ } catch (e) {
230
+ }
231
+ }
232
+ function notifyRequest(request) {
233
+ try {
234
+ requestObserver == null ? void 0 : requestObserver(request);
235
+ } catch (e) {
236
+ }
237
+ }
213
238
  function initBreadcrumbs(max, options) {
214
239
  var _a;
215
240
  if ((_a = options == null ? void 0 : options.responseBodyOrigins) == null ? void 0 : _a.length) {
@@ -261,10 +286,12 @@ function interceptConsole() {
261
286
  console.warn = function(...args) {
262
287
  addBreadcrumb("console", `[warn] ${argsToString(args)}`);
263
288
  origWarn.apply(console, args);
289
+ notifyConsole("warn", args);
264
290
  };
265
291
  console.error = function(...args) {
266
292
  addBreadcrumb("console", `[error] ${argsToString(args)}`);
267
293
  origError.apply(console, args);
294
+ notifyConsole("error", args);
268
295
  };
269
296
  }
270
297
  var CONSOLE_TEXT_MAX = 200;
@@ -360,7 +387,7 @@ function interceptFetch() {
360
387
  window.fetch = async function(input, init) {
361
388
  var _a;
362
389
  const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input instanceof Request ? input.url : String(input);
363
- const method = (_a = init == null ? void 0 : init.method) != null ? _a : "GET";
390
+ const method = ((_a = init == null ? void 0 : init.method) != null ? _a : input instanceof Request ? input.method : "GET").toUpperCase();
364
391
  const start = Date.now();
365
392
  try {
366
393
  const response = await origFetch(
@@ -374,6 +401,7 @@ function interceptFetch() {
374
401
  duration: `${Date.now() - start}ms`,
375
402
  ...body ? { responseBody: body } : {}
376
403
  });
404
+ notifyRequest({ method, url, status: response.status, durationMs: Date.now() - start });
377
405
  return response;
378
406
  } catch (err) {
379
407
  addBreadcrumb("api", `${method} ${url.slice(0, 100)} \u2192 FAILED`, {
@@ -394,7 +422,7 @@ function interceptXhr() {
394
422
  this.__ggMethod = method;
395
423
  this.__ggUrl = typeof url === "string" ? url : url.toString();
396
424
  const record = () => {
397
- var _a, _b, _c, _d;
425
+ var _a, _b, _c, _d, _e, _f;
398
426
  try {
399
427
  const recordedMethod = (_a = this.__ggMethod) != null ? _a : "GET";
400
428
  const recordedUrl = ((_b = this.__ggUrl) != null ? _b : "").slice(0, 100);
@@ -406,8 +434,14 @@ function interceptXhr() {
406
434
  });
407
435
  return;
408
436
  }
437
+ notifyRequest({
438
+ method: recordedMethod,
439
+ url: (_d = this.__ggUrl) != null ? _d : "",
440
+ status: this.status,
441
+ durationMs: Date.now() - ((_e = this.__ggStart) != null ? _e : Date.now())
442
+ });
409
443
  const failed = this.status < 200 || this.status >= 300;
410
- const body = failed && mayCaptureBody((_d = this.__ggUrl) != null ? _d : "") ? readXhrBody(this) : "";
444
+ const body = failed && mayCaptureBody((_f = this.__ggUrl) != null ? _f : "") ? readXhrBody(this) : "";
411
445
  addBreadcrumb("api", `${recordedMethod} ${recordedUrl} \u2192 ${this.status}`, {
412
446
  method: recordedMethod,
413
447
  status: String(this.status),
@@ -1305,6 +1339,23 @@ var config = null;
1305
1339
  function registerCaptureConfig(next) {
1306
1340
  config = next;
1307
1341
  }
1342
+ function getCaptureConfig() {
1343
+ return config;
1344
+ }
1345
+ var reportedErrors = /* @__PURE__ */ new WeakSet();
1346
+ function markErrorReported(error) {
1347
+ try {
1348
+ if (error && typeof error === "object") reportedErrors.add(error);
1349
+ } catch (e) {
1350
+ }
1351
+ }
1352
+ function wasErrorReported(error) {
1353
+ try {
1354
+ return !!error && typeof error === "object" && reportedErrors.has(error);
1355
+ } catch (e) {
1356
+ return false;
1357
+ }
1358
+ }
1308
1359
  function matchesIgnorePatterns(message, patterns) {
1309
1360
  if (!patterns || patterns.length === 0) return false;
1310
1361
  return patterns.some(
@@ -1325,6 +1376,7 @@ function buildCapturedErrorPayload(error, options, cfg, capturedBy = "captureErr
1325
1376
  const errorMessage = err ? err.message : String(error);
1326
1377
  if (!errorMessage) return null;
1327
1378
  if (matchesIgnorePatterns(errorMessage, cfg.ignoreErrors)) return null;
1379
+ markErrorReported(error);
1328
1380
  incrementErrorCount();
1329
1381
  const context = captureContext(cfg.getVisitedPages());
1330
1382
  const digest = (_a = options == null ? void 0 : options.digest) != null ? _a : typeof (error == null ? void 0 : error.digest) === "string" ? error.digest : void 0;
@@ -2033,8 +2085,6 @@ var ATTACHMENT_ACCEPT = [
2033
2085
  ...TEXT_ATTACHMENT_EXTENSIONS,
2034
2086
  ...BINARY_ATTACHMENT_EXTENSIONS
2035
2087
  ].join(",");
2036
- var ASSIST_ATTACHMENT_ACCEPT = ["image/*", ...TEXT_ATTACHMENT_EXTENSIONS].join(",");
2037
- var ASSIST_ATTACHMENT_ACCEPT_WITH_PDF = [ASSIST_ATTACHMENT_ACCEPT, ".pdf"].join(",");
2038
2088
  function isPdfFile(name) {
2039
2089
  return name.toLowerCase().endsWith(".pdf");
2040
2090
  }
@@ -2756,7 +2806,6 @@ function AssistSheet({
2756
2806
  pageShot = null,
2757
2807
  onAddFiles,
2758
2808
  files = NO_FILES,
2759
- canReadPdf = false,
2760
2809
  onRemoveFile,
2761
2810
  onRemoveImage,
2762
2811
  onAnnotateImage,
@@ -3118,7 +3167,7 @@ function AssistSheet({
3118
3167
  seedFromDescription();
3119
3168
  }
3120
3169
  }
3121
- function send(text) {
3170
+ function send2(text) {
3122
3171
  const value = text.trim();
3123
3172
  if (!value || busy) return;
3124
3173
  setStalled(null);
@@ -3922,7 +3971,7 @@ function AssistSheet({
3922
3971
  "data-gg-chip": "",
3923
3972
  onClick: () => {
3924
3973
  logEvent("starter_tap", s);
3925
- send(s);
3974
+ send2(s);
3926
3975
  },
3927
3976
  style: {
3928
3977
  border: `1px solid ${t.inputBorder}`,
@@ -4089,7 +4138,7 @@ function AssistSheet({
4089
4138
  "data-gg-glitchgrab-offer-no": "",
4090
4139
  onClick: () => {
4091
4140
  logEvent("glitchgrab_offer_declined");
4092
- send("No \u2014 it's about this app, not the reporting tool");
4141
+ send2("No \u2014 it's about this app, not the reporting tool");
4093
4142
  },
4094
4143
  style: {
4095
4144
  padding: "8px 12px",
@@ -4134,7 +4183,7 @@ function AssistSheet({
4134
4183
  "data-gg-option": "",
4135
4184
  onClick: () => {
4136
4185
  logEvent("option_tap", option);
4137
- send(option);
4186
+ send2(option);
4138
4187
  },
4139
4188
  style: {
4140
4189
  border: primary ? "1px solid transparent" : `1px solid ${t.inputBorder}`,
@@ -4840,7 +4889,7 @@ function AssistSheet({
4840
4889
  "label",
4841
4890
  {
4842
4891
  "data-gg-assist-attach": "",
4843
- title: "Attach an image or a file (html, json, log\u2026) \u2014 or paste one",
4892
+ title: "Attach an image or a file (pdf, docx, xlsx, csv, html, json, log, zip\u2026) \u2014 or paste one",
4844
4893
  style: {
4845
4894
  width: "40px",
4846
4895
  height: "40px",
@@ -4860,7 +4909,7 @@ function AssistSheet({
4860
4909
  "input",
4861
4910
  {
4862
4911
  type: "file",
4863
- accept: canReadPdf ? ASSIST_ATTACHMENT_ACCEPT_WITH_PDF : ASSIST_ATTACHMENT_ACCEPT,
4912
+ accept: ATTACHMENT_ACCEPT,
4864
4913
  multiple: true,
4865
4914
  onChange: (e) => {
4866
4915
  var _a2;
@@ -4902,7 +4951,7 @@ function AssistSheet({
4902
4951
  onKeyDown: (e) => {
4903
4952
  if (e.key === "Enter" && !e.shiftKey) {
4904
4953
  e.preventDefault();
4905
- send(input);
4954
+ send2(input);
4906
4955
  }
4907
4956
  },
4908
4957
  placeholder: phase === "draft" ? "Anything to change? Tell me here\u2026" : phase === "type" ? "What went wrong, or what would you like? Type it here\u2026" : "Type your answer\u2026",
@@ -4932,7 +4981,7 @@ function AssistSheet({
4932
4981
  {
4933
4982
  type: "button",
4934
4983
  "data-gg-sheet-send": "",
4935
- onClick: () => send(input),
4984
+ onClick: () => send2(input),
4936
4985
  disabled: busy || !input.trim(),
4937
4986
  "aria-label": "Send message",
4938
4987
  "data-gg-send-message": "",
@@ -5067,7 +5116,7 @@ function describeSentAlong(hasChat, screenshotCount) {
5067
5116
  return `${parts.slice(0, -1).join(", ")} and ${parts[parts.length - 1]}`;
5068
5117
  }
5069
5118
  function GlitchgrabProblemPanel({
5070
- send,
5119
+ send: send2,
5071
5120
  theme: t,
5072
5121
  surface,
5073
5122
  conversationId,
@@ -5138,7 +5187,7 @@ function GlitchgrabProblemPanel({
5138
5187
  setBusy(true);
5139
5188
  setError(null);
5140
5189
  try {
5141
- const result = await send({
5190
+ const result = await send2({
5142
5191
  description,
5143
5192
  surface,
5144
5193
  conversationId,
@@ -10764,6 +10813,174 @@ function describeRejection(reason) {
10764
10813
  }
10765
10814
  }
10766
10815
 
10816
+ // src/auto-signals.ts
10817
+ var DEFAULT_CAPTURE_CONSOLE = ["error", "warn"];
10818
+ var DEFAULT_SLOW_REQUEST_MS = 1e4;
10819
+ var CONSOLE_MESSAGE_MAX = 500;
10820
+ var ERROR_ARG_DELAY_MS = 1e3;
10821
+ var CONSOLE_NOISE = [
10822
+ /^\[glitchgrab\]/i,
10823
+ /ResizeObserver loop/i,
10824
+ /\b(?:chrome|safari|moz)-extension:\/\//,
10825
+ /Download the React DevTools/i
10826
+ ];
10827
+ var filing = false;
10828
+ var MAX_SIGNALS_PER_PAGE = 10;
10829
+ var sentThisPage = 0;
10830
+ function firstError(args) {
10831
+ return args.find((a) => a instanceof Error);
10832
+ }
10833
+ function routeOf(url) {
10834
+ var _a;
10835
+ try {
10836
+ const base = typeof window !== "undefined" ? window.location.href : "http://localhost";
10837
+ const { pathname } = new URL(url, base);
10838
+ return pathname.split("/").map(
10839
+ (part) => /^\d+$/.test(part) || /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(part) || /^c[a-z0-9]{20,}$/.test(part) || /^[0-9a-f]{24}$/i.test(part) ? "[id]" : part
10840
+ ).join("/") || "/";
10841
+ } catch (e) {
10842
+ return (_a = url.split("?")[0]) != null ? _a : url;
10843
+ }
10844
+ }
10845
+ function send(payload, baseUrl) {
10846
+ const cfg = getCaptureConfig();
10847
+ if (sentThisPage >= MAX_SIGNALS_PER_PAGE) return;
10848
+ sentThisPage += 1;
10849
+ filing = true;
10850
+ try {
10851
+ void sendReport(payload, baseUrl).then((result) => {
10852
+ if (result && (cfg == null ? void 0 : cfg.onReportSent)) cfg.onReportSent(result);
10853
+ });
10854
+ } finally {
10855
+ filing = false;
10856
+ }
10857
+ }
10858
+ function fileConsole(level, args) {
10859
+ var _a;
10860
+ try {
10861
+ const cfg = getCaptureConfig();
10862
+ if (!(cfg == null ? void 0 : cfg.token)) return;
10863
+ const err = firstError(args);
10864
+ if (err && wasErrorReported(err)) return;
10865
+ const text = redactString(
10866
+ (err && args.length === 1 ? err.message : argsToString(args)).slice(0, CONSOLE_MESSAGE_MAX)
10867
+ );
10868
+ if (!text.trim()) return;
10869
+ if (CONSOLE_NOISE.some((re) => re.test(text))) return;
10870
+ if (matchesIgnorePatterns(text, cfg.ignoreErrors)) return;
10871
+ const errorMessage = `console.${level}: ${text}`;
10872
+ const errorStack = (err == null ? void 0 : err.stack) ? redactString(err.stack) : void 0;
10873
+ const context = captureContext(cfg.getVisitedPages());
10874
+ const sig = computeSignature({ errorMessage, pageUrl: context.url, errorStack });
10875
+ if (shouldSkipDuplicate(sig)) return;
10876
+ send(
10877
+ {
10878
+ token: cfg.token,
10879
+ source: "SDK_AUTO",
10880
+ type: "BUG",
10881
+ errorMessage,
10882
+ errorStack,
10883
+ pageUrl: context.url,
10884
+ userAgent: context.userAgent,
10885
+ breadcrumbs: context.breadcrumbs,
10886
+ deviceInfo: (_a = context.deviceInfo) != null ? _a : void 0,
10887
+ metadata: {
10888
+ timestamp: context.timestamp,
10889
+ visitedPages: JSON.stringify(context.visitedPages),
10890
+ capturedBy: `console.${level}`,
10891
+ autoKind: "console",
10892
+ consoleLevel: level,
10893
+ ...contextMetadata(context),
10894
+ ...originMetadata(err == null ? void 0 : err.stack),
10895
+ ...sessionMetadata2(cfg.session)
10896
+ }
10897
+ },
10898
+ cfg.baseUrl
10899
+ );
10900
+ } catch (e) {
10901
+ }
10902
+ }
10903
+ function fileSlowRequest(request, thresholdMs) {
10904
+ var _a, _b;
10905
+ try {
10906
+ const cfg = getCaptureConfig();
10907
+ if (!(cfg == null ? void 0 : cfg.token)) return;
10908
+ if (request.durationMs < thresholdMs) return;
10909
+ if (!isOwnOrigin(request.url)) return;
10910
+ const own = (_a = cfg.baseUrl) != null ? _a : DEFAULT_BASE_URL;
10911
+ if (request.url.startsWith(own) || request.url.includes("/api/v1/sdk/")) return;
10912
+ const method = request.method.toUpperCase();
10913
+ const route = routeOf(request.url);
10914
+ const errorMessage = `Slow request: ${method} ${route}`;
10915
+ if (matchesIgnorePatterns(errorMessage, cfg.ignoreErrors)) return;
10916
+ const context = captureContext(cfg.getVisitedPages());
10917
+ const sig = computeSignature({ errorMessage, pageUrl: context.url });
10918
+ if (shouldSkipDuplicate(sig)) return;
10919
+ const seconds = (request.durationMs / 1e3).toFixed(1);
10920
+ send(
10921
+ {
10922
+ token: cfg.token,
10923
+ source: "SDK_AUTO",
10924
+ type: "PERFORMANCE",
10925
+ errorMessage,
10926
+ description: `${method} ${route} took ${seconds}s (threshold ${(thresholdMs / 1e3).toFixed(1)}s)${request.status ? `, answered ${request.status}` : ", never completed"}.`,
10927
+ pageUrl: context.url,
10928
+ userAgent: context.userAgent,
10929
+ breadcrumbs: context.breadcrumbs,
10930
+ deviceInfo: (_b = context.deviceInfo) != null ? _b : void 0,
10931
+ metadata: {
10932
+ timestamp: context.timestamp,
10933
+ visitedPages: JSON.stringify(context.visitedPages),
10934
+ capturedBy: "slowRequestMs",
10935
+ autoKind: "slow-request",
10936
+ requestMethod: method,
10937
+ requestRoute: route,
10938
+ durationMs: String(request.durationMs),
10939
+ thresholdMs: String(thresholdMs),
10940
+ ...request.status ? { status: String(request.status) } : {},
10941
+ ...contextMetadata(context),
10942
+ ...sessionMetadata2(cfg.session)
10943
+ }
10944
+ },
10945
+ cfg.baseUrl
10946
+ );
10947
+ } catch (e) {
10948
+ }
10949
+ }
10950
+ function sessionMetadata2(session) {
10951
+ return {
10952
+ ...(session == null ? void 0 : session.userId) ? { sessionUserId: session.userId } : {},
10953
+ ...(session == null ? void 0 : session.name) ? { sessionUserName: String(session.name) } : {},
10954
+ ...(session == null ? void 0 : session.email) ? { sessionUserEmail: String(session.email) } : {},
10955
+ ...(session == null ? void 0 : session.phone) ? { sessionUserPhone: String(session.phone) } : {}
10956
+ };
10957
+ }
10958
+ function installAutoSignals(options) {
10959
+ var _a;
10960
+ try {
10961
+ const levels = new Set((_a = options.captureConsole) != null ? _a : []);
10962
+ const slowMs = options.slowRequestMs && options.slowRequestMs > 0 ? options.slowRequestMs : 0;
10963
+ setConsoleObserver(
10964
+ levels.size ? (level, args) => {
10965
+ if (filing || !levels.has(level)) return;
10966
+ if (firstError(args)) {
10967
+ setTimeout(() => fileConsole(level, args), ERROR_ARG_DELAY_MS);
10968
+ } else {
10969
+ fileConsole(level, args);
10970
+ }
10971
+ } : null
10972
+ );
10973
+ setRequestObserver(slowMs ? (request) => fileSlowRequest(request, slowMs) : null);
10974
+ return () => {
10975
+ setConsoleObserver(null);
10976
+ setRequestObserver(null);
10977
+ };
10978
+ } catch (e) {
10979
+ return () => {
10980
+ };
10981
+ }
10982
+ }
10983
+
10767
10984
  // src/shortcut.ts
10768
10985
  var GLITCHGRAB_SHORTCUT2 = "Ctrl+Shift+G";
10769
10986
  var GLITCHGRAB_SHORTCUT_MAC2 = "\u2318\u21E7G";
@@ -10808,7 +11025,9 @@ function GlitchgrabProviderInner({
10808
11025
  ignoreErrors,
10809
11026
  release: release2,
10810
11027
  context: appContext2,
10811
- responseBodyOrigins: responseBodyOrigins2
11028
+ responseBodyOrigins: responseBodyOrigins2,
11029
+ captureConsole = DEFAULT_CAPTURE_CONSOLE,
11030
+ slowRequestMs = DEFAULT_SLOW_REQUEST_MS
10812
11031
  }) {
10813
11032
  const visitedPagesRef = useRef5([]);
10814
11033
  const sessionKey = sessionProp ? [
@@ -10839,6 +11058,16 @@ function GlitchgrabProviderInner({
10839
11058
  initBreadcrumbs(maxBreadcrumbs2, { responseBodyOrigins: responseBodyOrigins2 });
10840
11059
  }
10841
11060
  }, [enableBreadcrumbs, maxBreadcrumbs2, responseBodyOrigins2 == null ? void 0 : responseBodyOrigins2.join(",")]);
11061
+ const captureConsoleKey = captureConsole ? captureConsole.join(",") : "";
11062
+ useEffect6(() => {
11063
+ if (!enableBreadcrumbs) return;
11064
+ if (process.env.NODE_ENV === "development") return;
11065
+ if (!captureConsoleKey && !slowRequestMs) return;
11066
+ return installAutoSignals({
11067
+ captureConsole: captureConsoleKey ? captureConsoleKey.split(",") : [],
11068
+ slowRequestMs
11069
+ });
11070
+ }, [enableBreadcrumbs, captureConsoleKey, slowRequestMs]);
10842
11071
  useEffect6(() => {
10843
11072
  try {
10844
11073
  if (typeof window === "undefined") return;
@@ -10905,6 +11134,7 @@ function GlitchgrabProviderInner({
10905
11134
  return;
10906
11135
  }
10907
11136
  if (isHandledHydrationError(event.error)) return;
11137
+ markErrorReported(event.error);
10908
11138
  incrementErrorCount();
10909
11139
  const context = captureContext(visitedPagesRef.current);
10910
11140
  const sig = computeSignature({
@@ -10962,6 +11192,7 @@ function GlitchgrabProviderInner({
10962
11192
  }
10963
11193
  if (errStack && EXTENSION_ORIGIN_RE.test(errStack)) return;
10964
11194
  if (isUnactionableRejection(description)) return;
11195
+ markErrorReported(reason);
10965
11196
  incrementErrorCount();
10966
11197
  const context = captureContext(visitedPagesRef.current);
10967
11198
  const sig = computeSignature({