From 0d46b89c68564449ccb8091879e0085e404a6942 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 18 Jul 2025 15:51:21 -0500 Subject: [PATCH] Use Sentry Loader script to handle CORS errors gracefully MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replaced direct Sentry SDK script tag with the Sentry Loader - The loader handles CORS/network failures gracefully without breaking the app - Moved Sentry configuration to use the onLoad callback - Maintains the same configuration (100% sampling, BrowserTracing, etc.) The Sentry Loader is a small inline script that: 1. Captures errors immediately (even before SDK loads) 2. Loads the SDK asynchronously 3. Handles load failures gracefully 4. Replays captured errors once SDK is loaded This approach avoids CORS errors breaking the page load while still providing error tracking when the SDK is accessible. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- assets/js/app.js | 34 ++++++++++--------- .../components/layouts/root.html.heex | 3 +- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index 18cc854..2f35c7b 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -22,23 +22,25 @@ import { Socket } from "phoenix"; import { LiveSocket } from "phoenix_live_view"; import topbar from "../vendor/topbar"; -// Initialize Sentry for JavaScript error tracking -if (typeof window.Sentry !== 'undefined') { - window.Sentry.init({ - dsn: "https://337ece4c07ff53c6719d900adfddd6e4@o4509627566063616.ingest.us.sentry.io/4509691336785920", - environment: process.env.NODE_ENV || "production", - integrations: [ - new window.Sentry.BrowserTracing(), - ], - tracesSampleRate: 1.0, // Capture 100% of transactions for performance monitoring - sampleRate: 1.0, // Capture 100% of errors - beforeSend(event, hint) { - // Filter out known non-critical errors - if (hint.originalException?.message?.includes('ResizeObserver loop limit exceeded')) { - return null; +// Sentry initialization happens via the loader script in the HTML +// Configure additional Sentry settings if needed +if (typeof window.Sentry !== 'undefined' && window.Sentry.onLoad) { + window.Sentry.onLoad(function() { + window.Sentry.init({ + environment: "production", + integrations: [ + new window.Sentry.BrowserTracing(), + ], + tracesSampleRate: 1.0, // Capture 100% of transactions for performance monitoring + sampleRate: 1.0, // Capture 100% of errors + beforeSend(event, hint) { + // Filter out known non-critical errors + if (hint.originalException?.message?.includes('ResizeObserver loop limit exceeded')) { + return null; + } + return event; } - return event; - } + }); }); } diff --git a/lib/aprsme_web/components/layouts/root.html.heex b/lib/aprsme_web/components/layouts/root.html.heex index 222c701..e583c06 100644 --- a/lib/aprsme_web/components/layouts/root.html.heex +++ b/lib/aprsme_web/components/layouts/root.html.heex @@ -64,7 +64,8 @@ -