Open source CapCut alternative.
TypeScript
feat(site): browser errors flow into PostHog error tracking
David Le7cecada2f1de
diff --git a/site/src/instrumentation-client.ts b/site/src/instrumentation-client.tsindex 10c2d62c..d21ecf8f 100644--- a/site/src/instrumentation-client.ts+++ b/site/src/instrumentation-client.ts@@ -8,10 +8,35 @@ import posthog from "posthog-js";// navigation.const REPLAY_FREE = /^\/(?:cut\/)?(?:app|s)(?:\/|$)/;+// Signed media URLs carry user-id paths and signatures; error messages that+// embed one get it masked before the event leaves the browser.+const scrubUrls = (s: string) => s.replace(/https?:\/\/\S+/g, "<url>");+if (process.env.NEXT_PUBLIC_POSTHOG_KEY) {posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, {api_host: "https://us.i.posthog.com",defaults: "2026-05-30",disable_session_recording: REPLAY_FREE.test(window.location.pathname),+ // Error tracking: unhandled errors, unhandled rejections, and every+ // console.error become $exception events. Failures a feature swallows on+ // purpose reach it by logging with console.error. Event capture is+ // memory-queued batches — none of session replay's canvas readback cost,+ // so it runs on the Cut surfaces too.+ capture_exceptions: {+ capture_unhandled_errors: true,+ capture_unhandled_rejections: true,+ capture_console_errors: true,+ },+ before_send: (event) => {+ if (event?.event === "$exception") {+ const list = event.properties?.$exception_list;+ if (Array.isArray(list)) {+ for (const item of list) {+ if (typeof item?.value === "string") item.value = scrubUrls(item.value);+ }+ }+ }+ return event;+ },});}