Loader Script

Learn about the Sentry JavaScript Loader Script

The Loader Script is the easiest way to initialize the Sentry SDK. The Loader Script also automatically keeps your Sentry SDK up to date and offers configuration for different Sentry features.

To use the loader, go in the Sentry UI to Settings > Projects > (select project) > Client Keys (DSN), and then press the "Configure" button. Copy the script tag from the "JavaScript Loader" section and include it as the first script on your page. By including it first, you allow it to catch and buffer events from any subsequent scripts, while still ensuring the full SDK doesn't load until after everything else has run.

Copied
<script
  src="https://js.sentry-cdn.com/examplePublicKey.min.js"
  crossorigin="anonymous"
></script>

By default, Tracing and Session Replay are enabled.

To have correct stack traces for minified asset files when using the Loader Script, you will have to either host your Source Maps publicly or upload them to Sentry.

The loader has a few configuration options:

  • What version of the SDK to load
  • Using Tracing
  • Using Session Replay
  • Showing debug logs

To configure the version, use the dropdown in the "JavaScript Loader" settings, directly beneath the script tag you copied earlier.

JavaScript Loader Settings

Note that because of caching, it can take a few minutes for version changes made here to take effect.

If you only use the Loader for errors, the loader won't load the full SDK until triggered by one of the following:

  • an unhandled error
  • an unhandled promise rejection
  • a call to Sentry.captureException
  • a call to Sentry.captureMessage
  • a call to Sentry.captureEvent

Once one of those occurs, the loader will buffer that event and immediately request the full SDK from our CDN. Any events that occur between that request being made and the completion of SDK initialization will also be buffered, and all buffered events will be sent to Sentry once the SDK is fully initialized.

Alternatively, you can set the loader to request the full SDK earlier: still as part of page load, but after all of the other JavaScript on the page has run. (In other words, in a subsequent event loop.) To do this, include data-lazy="no" in your script tag.

Copied
<script
  src="https://js.sentry-cdn.com/examplePublicKey.min.js"
  crossorigin="anonymous"
  data-lazy="no"
></script>

Finally, if you want to control the timing yourself, you can call Sentry.forceLoad(). You can do this as early as immediately after the loader runs (which has the same effect as setting data-lazy="no") and as late as the first unhandled error, unhandled promise rejection, or call to Sentry.captureMessage or Sentry.captureEvent (which has the same effect as not calling it at all). Note that you can't delay loading past one of the aforementioned triggering events.

If Tracing and/or Session Replay is enabled, the SDK will immediately fetch and initialize the bundle to make sure it can capture transactions and/or replays once the page loads.

While the Loader Script will work out of the box without any configuration in your application, you can still configure the SDK according to your needs.

For Tracing, the SDK will be initialized with tracesSampleRate: 1 by default. This means that the SDK will capture all traces.

For Session Replay, the defaults are replaysSessionSampleRate: 0.1 and replaysOnErrorSampleRate: 1. This means Replays will be captured for 10% of all normal sessions and for all sessions with an error.

You can configure the release by adding the following to your page:

Copied
<script>
  window.SENTRY_RELEASE = {
    id: "...",
  };
</script>

The loader script always includes a call to Sentry.init with a default configuration, including your DSN. If you want to configure your SDK beyond that, you can configure a custom init call by defining a window.sentryOnLoad function. Whatever is defined inside of this function will always be called first, before any other SDK method is called.

Be sure to define this function before you add the loader script, to ensure it can be called at the right time:

Copied
<script>
  // Configure sentryOnLoad before adding the Loader Script
  window.sentryOnLoad = function () {
    Sentry.init({
      // add custom config here
    });
  };
</script>

<script
  src="https://js.sentry-cdn.com/examplePublicKey.min.js"
  crossorigin="anonymous"
></script>

Inside of the window.sentryOnLoad function, you can configure a custom Sentry.init() call. You can configure your SDK exactly the way you would if you were using the CDN, with one difference: your Sentry.init() call doesn't need to include your DSN, since it's already been set. Inside of this function, the full Sentry SDK is guaranteed to be loaded & available.

Copied
<script>
  // Configure sentryOnLoad before adding the Loader Script
  window.sentryOnLoad = function () {
    Sentry.init({
      release: " ... ",
      environment: " ... "
    });
    Sentry.setTag(...);
    // etc.
  };
</script>

By default, the loader will make sure you can call these functions directly on Sentry at any time, even if the SDK is not yet loaded:

  • Sentry.captureException()
  • Sentry.captureMessage()
  • Sentry.captureEvent()
  • Sentry.addBreadcrumb()
  • Sentry.withScope()
  • Sentry.showReportDialog()

If you want to call any other method when using the Loader, you have to guard it with Sentry.onLoad(). Any callback given to onLoad() will be called either immediately (if the SDK is already loaded), or later once the SDK has been loaded:

Copied
// Guard against window.Sentry not being available, e.g. due to Ad-blockers
window.Sentry &&
  Sentry.onLoad(function () {
    // Inside of this callback,
    // we guarantee that `Sentry` is fully loaded and all APIs are available
    const client = Sentry.getClient();
    // do something custom here
  });

When using the Loader Script with just errors, the script injects the SDK asynchronously. This means that only unhandled errors and unhandled promise rejections will be caught and buffered before the SDK is fully loaded. Specifically, capturing breadcrumb data will not be available until the SDK is fully loaded and initialized. To reduce the amount of time these features are unavailable, set data-lazy="no" or call forceLoad() as described above.

If you want to understand the inner workings of the loader itself, you can read the documented source code in all its glory over at the Sentry repository.

Sentry supports loading the JavaScript SDK from a CDN. Generally we suggest using our Loader instead. If you must use a CDN, see Available Bundles below.

To use Sentry for error and tracing, you can use the following bundle:

Copied
<script
  src="https://browser.sentry-cdn.com/8.53.0/bundle.tracing.min.js"
  integrity="sha384-c4yTGqQoFcFpu8R8lJ/scdheMKW/tbl4MaQ+7ViTSMklpC/fAYfQhLnW40cLNhr0"
  crossorigin="anonymous"
></script>

To use Sentry for error and tracing, as well as for Session Replay, you can use the following bundle:

Copied
<script
  src="https://browser.sentry-cdn.com/8.53.0/bundle.tracing.replay.min.js"
  integrity="sha384-0WHq047OrF+1a7ech4gk9tyhhuaapjsWM0E8IiC5H4p/KkqfeiaB3Owidtbt3+25"
  crossorigin="anonymous"
></script>

To use Sentry for error monitoring, as well as for Session Replay, but not for tracing, you can use the following bundle:

Copied
<script
  src="https://browser.sentry-cdn.com/8.53.0/bundle.replay.min.js"
  integrity="sha384-YWvPUcftY2P8gO5axD4aXCxhVcD6LFuBJygqMALZi69BJT0LmhLNhHWM1l2LilZW"
  crossorigin="anonymous"
></script>

If you only use Sentry for error monitoring, and don't need performance tracing or replay functionality, you can use the following bundle:

Copied
<script
  src="https://browser.sentry-cdn.com/8.53.0/bundle.min.js"
  integrity="sha384-DYUttCOEZIXGrLRphM/xGDsps+AQ8eKYHK5X6mWt6fBm9zqil2Y9zNm0wedLxd0j"
  crossorigin="anonymous"
></script>

Once you've included the Sentry SDK bundle in your page, you can use Sentry in your own bundle:

Copied
Sentry.init({
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
  // this assumes your build process replaces `process.env.npm_package_version` with a value
  release: "my-project-name@" + process.env.npm_package_version,
  integrations: [
    // If you use a bundle with tracing enabled, add the BrowserTracing integration
    Sentry.browserTracingIntegration(),
    // If you use a bundle with session replay enabled, add the Replay integration
    Sentry.replayIntegration(),
  ],

  // We recommend adjusting this value in production, or using tracesSampler
  // for finer control
  tracesSampleRate: 1.0,

  // Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled
  tracePropagationTargets: ["localhost", /^https:\/\/yourserver\.io\/api/],
});

Our CDN hosts a variety of bundles:

  • @sentry/browser with error monitoring only (named bundle.<modifiers>.js)
  • @sentry/browser with error and tracing (named bundle.tracing.<modifiers>.js)
  • @sentry/browser with error and session replay (named bundle.replay.<modifiers>.js)
  • @sentry/browser with error, tracing and session replay (named bundle.tracing.replay.<modifiers>.js)
  • each of the integrations in @sentry/integrations (named <integration-name>.<modifiers>.js)

Each bundle is offered in both ES6 and ES5 versions. Since v7 of the SDK, the bundles are ES6 by default. To use the ES5 bundle, add the .es5 modifier.

Each version has three bundle varieties:

  • minified (.min)
  • unminified (no .min), includes debug logging
  • minified with debug logging (.debug.min)

Bundles that include debug logging output more detailed log messages, which can be helpful for debugging problems. Make sure to enable debug to see debug messages in the console. Unminified and debug logging bundles have a greater bundle size than minified ones.

For example:

  • bundle.js is @sentry/browser, compiled to ES6 but not minified, with debug logging included (as it is for all unminified bundles)
  • rewriteframes.es5.min.js is the RewriteFrames integration, compiled to ES5 and minified, with no debug logging
  • bundle.tracing.es5.debug.min.js is @sentry/browser with tracing enabled, compiled to ES5 and minified, with debug logging included
FileIntegrity Checksum
browserprofiling.debug.min.jssha384-cY7LDppMDiO57L1L/deGNcpKBuTYhPxuU5nSDHltpstos/3cgKcqyuq//LUI14fw
browserprofiling.jssha384-ngy71Y0IlZJBpsXmYW5bgbdZ9aRqAJ/kb51O4pFgGjowadLvtRnmO2sxZkeBNNV4
browserprofiling.min.jssha384-61RG8pLD6/gOABwML1nHQEuDRPXK+E4x++/0c8kYFD2JolUMroAwNYEVvV5UdaNf
bundle.debug.min.jssha384-0DoUrFFQiocRq8ViBcn8AERrk87NrZ1NDKYrlEA0B5RkP2MRwQQRZ4auyUaMZtAn
bundle.feedback.debug.min.jssha384-sPe8dIbreqzOzpZGOw89piKYQu9PjFV10KVQGIYRqu6IAa34YNJ5nOzCIFWjjxm9
bundle.feedback.jssha384-zM/MaL3Fw7V98gj4rxDqFeYDo/4fNSiCducl5Fg03NJ+lmFeBGHORXMirXfvGOpe
bundle.feedback.min.jssha384-NTMPbi62NSOZ1tTuE7Zh0XLAQcVYVJ9OQNsFppEopeU+Q0E6hZkFx9DjXx2j/4uX
bundle.jssha384-a+ImrnUYUzheM6jvvLbD0VJy/NCHPNn9PJ7cPaK5cswSNT4H54Wm+ohOrXkgJNd6
bundle.min.jssha384-DYUttCOEZIXGrLRphM/xGDsps+AQ8eKYHK5X6mWt6fBm9zqil2Y9zNm0wedLxd0j
bundle.replay.debug.min.jssha384-DOEWmXvU3d5bYLHVOM2e5ohTqBtGU383jQe2v8vrLyP+Ij0sAR5ktxefp1PL1pBe
bundle.replay.jssha384-8r3t1/RXMCRIB6enzGfGXL2tbV7TyXRFtMs5BJAIZLXeZZAgRCfjrkWb6LRgwj6A
bundle.replay.min.jssha384-YWvPUcftY2P8gO5axD4aXCxhVcD6LFuBJygqMALZi69BJT0LmhLNhHWM1l2LilZW
bundle.tracing.debug.min.jssha384-asYiArUtwlQwiqjwZfYXpnosQOBckZVJktgITdWIBAejBywRV+3GTXN+0jRXVX9N
bundle.tracing.jssha384-JdqMErK6GFpRf+vU45Gsd5ORP0mifIMDk7r3z+9f+zirWr9oIDbWeo5bv9w6qhVt
bundle.tracing.min.jssha384-c4yTGqQoFcFpu8R8lJ/scdheMKW/tbl4MaQ+7ViTSMklpC/fAYfQhLnW40cLNhr0
bundle.tracing.replay.debug.min.jssha384-OYVA0W/eSdhKiCOQhpOCQcLRvU2QjMpBAKreKZ2fFDXlNDKedio637quhIdK/shb
bundle.tracing.replay.feedback.debug.min.jssha384-g59I3obCPfu/5a5WNe0jSf3AhqeYiw9sSfvzAT4K54098DN74R8/lqjGlU/qiL6O
bundle.tracing.replay.feedback.jssha384-/qersPLCMuWH3eapcyZOiQ3HIYkhovrGPtDVQFYiHDNDWDfQi33BjBzN21+Di7F0
bundle.tracing.replay.feedback.min.jssha384-C1FP9/P+3XwqY9hBf+50+jCmrRwo3O/s76fD6OSOXXnNIfanpPuQyJLKf8GgPEMQ
bundle.tracing.replay.jssha384-UNFV2CdBW6pzFQw8VAknYhe6zAh88+hG7d65bIaE78T/UM5NM3roOFDiwpRsMC7O
bundle.tracing.replay.min.jssha384-0WHq047OrF+1a7ech4gk9tyhhuaapjsWM0E8IiC5H4p/KkqfeiaB3Owidtbt3+25
captureconsole.debug.min.jssha384-kmZFtrQMGjkqfvli5yT4pDD0GcGy5Ct93Vktjfm4jpOaNBxkTBobtgGlU+lbrUZZ
captureconsole.jssha384-QsJ436cBihyc49sveeWC4aDiGAEavICWgSduWKzDjhCp9PyOTzM58yor1xvAv7pB
captureconsole.min.jssha384-onUoOqYXVy0i1AZzBZnBvsUnT/tFE4f/4rBpuS6mM4jCRVHt7oYgngdt1UGSKJbi
contextlines.debug.min.jssha384-G8Ezxh3AEFwIj/oJP+m260oDmAtHbaNUgmYwXnfagSx0wOPfrxVaYFVwqn2gyDjz
contextlines.jssha384-PvhW2M4aBxsz1pzM7bwccYHIdX0Xw9XD6CilypKZSDbzT8ydNoZ3In6L+nUqOOV6
contextlines.min.jssha384-aNW6OjMZyNDmCT2Xhxw/scCkajPobr6vvJn/olP+iLjdN2lHVAqmGgUrsrzWQaU7
debug.debug.min.jssha384-KSjL4J1zvR2fwiRh1LtTVYn41z3HKDz+7PlXOSnkwdn7zOWi3ic2zAOhn57sGPor
debug.jssha384-EjFsCtyrha/Ece0KXwASsi+SMi2XqDW3a6SYLOoQuDvgKCaGUr+KS0Mve6sP71GU
debug.min.jssha384-/KVfsvGJmJ1zTwNU3TngEUr9gqPVozyua3eKJAcctlHQY9bNXS71NxnFRVVw1+D+
dedupe.debug.min.jssha384-ud2iYRPS/I7ddcSb+T8KIdU1JT/2CcqUCL5CNI70OCdfnxQRIlSX2NTMCCxqwu4o
dedupe.jssha384-7F8nFjQq46tFpHcNkWgSfxIiQi55uM1WdH69GwIfc+CO+XyYCm6LYrqyIch33eKa
dedupe.min.jssha384-WMQYgCqA0FHInxW1qIw+idA2Li/CMwniVbO2DVke2RxclQj2k7wAkVD4/3n+/Jqe
extraerrordata.debug.min.jssha384-+MnOs+7gZKOMReIxJNzR+uYUfQ6WK+tmsiXCew0KYTd8NPOpndFps2NiUfZMt4Qz
extraerrordata.jssha384-+u+wK6OLoyyHtJVnxeVsseM+z3DR2hgLlCTF3UBXwbOxp5nDPSrp+TOEAKAKlcRw
extraerrordata.min.jssha384-pLU27GvJettlKaDB6LXYB3gCMH8sXbCSvAy1WeIiGATmExzpPncUjO6qqokfl8tN
feedback-modal.debug.min.jssha384-ttBk4X0QfSakQsWtUBronNjPru3qATvyCGwXvxkEQBv5flWbLiR/n0JpRBDBtfE5
feedback-modal.jssha384-hlIXzcnBlLIKYPEYdKxdMU1HBZW1NoyryZs1OIcnlwZGxWLPKUde01CSRCRMBZVC
feedback-modal.min.jssha384-o9QGx+l7Y3d19V528WKqT01aOuqDXnhDLy7rCJiYzfvKIAFjXhAJz9N907m+bvDK
feedback-screenshot.debug.min.jssha384-Hc9XElO2Jithb6Ood0SZjkLOtsFu/7dU1T4OM1V6W0T/rQ1PPn/GbA/c2scYM1zd
feedback-screenshot.jssha384-WJ8UIhGRs2GtiVA77WgFYxvJSimHhgqyradBrUTU1sRpcvNt45GupPsojcSZKaU9
feedback-screenshot.min.jssha384-VBBTu45CMQubqbmThuadMpHNG0g2UjepE7kMHVBgUVRhZ2MnYIvlv7YJYWInig/p
feedback.debug.min.jssha384-epujjKkonouXn6StPhldXTH5QW3ty9cuGa1g5ATcCKkoDU6TrF8ezqvQDp8o8Ak9
feedback.jssha384-qUbrx/APPuoBtEIeAzyIyud7Q5hV7OWrWtpOlUaF54v5t9AsONv3RAiJ/nwLH1pD
feedback.min.jssha384-BPCeFy+PKF4flDyD0H6M9Nq60YUgfsu3TJf6GQjR8B+SF8JfVer5vh11r/4XgQ9p
httpclient.debug.min.jssha384-94SHU3HofJlDfC8P514p4b3DffxOtVkBAdYr/LswwWF5OBzOnSy7BUtEh0GjZvx7
httpclient.jssha384-qvFsMhm4bb9Bl9nb8xJL1QyUpkw1jc3+sqEMBPAQEguGR413kztkSapdgYFHdApX
httpclient.min.jssha384-H8G3q+kvO8fNpRZZ/D0iuNWHdc1aM3xZBHbCXNl7wK5wDtDzM24JUU/7YJlNT0jf
modulemetadata.debug.min.jssha384-2uhTGOeaqK2H5ZoZZeTL5lv1cffvC3xW5w/YRHFH4pogoLbDMZFnlh0mI1KrIvBB
modulemetadata.jssha384-uZ7Ntzzewt3D/DMc5zxcAudDISFqMxaxO7dxeEjC7txS368jzeEewUD5DfLS33ME
modulemetadata.min.jssha384-jadLqZ9N0yY7cGbthmwShak2iJR0jMX1txwwrdS0CBluE1aWRKEXBJG1l911KyM3
multiplexedtransport.debug.min.jssha384-cTMt9uFDyKNj6ZSHI9HYjIrrOI7cEKIUrZkMfurWfxiC/+WIE7cY6gustrOem1nL
multiplexedtransport.jssha384-yZ1Ec2TF9xsPCZ8jcXSDgVjYKwFf4Jf/7WEq/YiGmOxnNFshi6l5lYsgBYTuooHB
multiplexedtransport.min.jssha384-EqkPL7YdsDQRByHAhDsQbDiEPrej3sCJkTSoRBygtiIruGzXZCKHwcXIPJTVxSlf
replay-canvas.debug.min.jssha384-waZ1porsTXFis/9bNFTLckM0PsP56cjjeJ2c4AXRRSIA9wcGhkafCf9VpnwrTjnn
replay-canvas.jssha384-HGJ6fO5z1kxG+f1qQyqOLEUFay/53NsKRyen0+OgTEONW2BBcP/FsEYmmQQ0cEZN
replay-canvas.min.jssha384-DsWIJqxEt1w665R507wpwYkDqEGIdkBop17dv8V7ctUj591yEp/aOdYiNhzvDx2e
replay.debug.min.jssha384-QllWaRJmjaEVtfCJUZXJJmVhhNJI/q/x5yjT7cIlPO8etjeRoxrLCj5gKs+ntUrw
replay.jssha384-mQ9YHQYLAvw0PDtuG+Uwo/R8ClocUGiP5mcQWJgUvGDVwjTLAfjwnE+smoQBCIU5
replay.min.jssha384-nubrYj9sIuCGYxHCEF+r8fiLcB38YqX9Igx9u2F8TFsxbq0Gj8oJ/xrxezEDR2po
reportingobserver.debug.min.jssha384-uBPWi3lWVo3/WyPWP0LnXP9GBoaFBxQWK37e9t6lS2jbjvcwQXJ8cNy2OClijXDN
reportingobserver.jssha384-/u0gNDxIQbaMCr7L9YwK3BqBNI94LS9Y3krKxIqt+46DJhRF3liP/5FLMJPm+WgL
reportingobserver.min.jssha384-a2Wi+31hl+jr7RfeH4AjWHS3mus2hDIhjUCM9Zk4/+sia/gnGCKijweQ0H1+IsA8
rewriteframes.debug.min.jssha384-UJZzqdscuvc7nJNFAS5+Pdio4EPFuqYP1lCYXUNZnCvKAg5TdPkk/3wE5xJdW+2p
rewriteframes.jssha384-GAp3cRpJdIZzMiboBWypz2HrRXprhnMhiMMggZM1ehCJArMTH+4FbTM1bx6Pl5oH
rewriteframes.min.jssha384-B0p/UEm++kuGd66C+Xz4E4xCssSXTsrqZ/WbYvQszuNLkeZ1CVrk2uA2nSttx6O0
sessiontiming.debug.min.jssha384-foxZr1yLIdgErJjOApDCQ2bHMZZwppNCjxQmQJaxgIBOFVBIyycYXkJfVUdllGN6
sessiontiming.jssha384-6XwFWs7BeyAGAr1AMkOqllXd9i6cuSdw10187UDz2B4sYzDrrcm9Yx2JRQoXLFof
sessiontiming.min.jssha384-gz8otMNST+nFWx1ICpQ1wvFGryMy8B5TAN5zmuWC4fWTQjkHht3K00nx5YWEcccn

To find the integrity hashes for older SDK versions, you can view our SDK release registry for the Browser SDK here.

If you use the defer script attribute, we strongly recommend that you place the script tag for the browser SDK first and mark all of your other scripts with defer (but not async). This will guarantee that that the Sentry SDK is executed before any of the others.

Without doing this you will find that it's possible for errors to occur before Sentry is loaded, which means you'll be flying blind to those issues.

If you have a Content Security Policy (CSP) set up on your site, you will need to add the script-src of wherever you're loading the SDK from, and the origin of your DSN. For example:

  • script-src: https://browser.sentry-cdn.com https://js.sentry-cdn.com
  • connect-src: *.sentry.io
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").