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/9.4.0/bundle.tracing.min.js"
  integrity="sha384-0Rh0kgHbKYfrqJPlzvRAov1DGSCz/dW1ceE2q0QZHSHT35Q3lyhAN6jCNUR2bt71"
  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/9.4.0/bundle.tracing.replay.min.js"
  integrity="sha384-qj/49NHTE0QijJkkgYtWaQ+wOXFmrNq6XoqVS+lerZQ1sJxGpZzWWcwV5XDTmdmM"
  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/9.4.0/bundle.replay.min.js"
  integrity="sha384-vb90i7hwfxer+E4DucPc+lVv/dWMANFuZ/C7Cwt5EPIMoHSnbNr92k4MDfgi6yHi"
  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/9.4.0/bundle.min.js"
  integrity="sha384-lUDS8mchz+Cw11xMt/yUMpDqU5dAAgr9IlkPp4np9kgwJQnj9S2zyflDRZ7jGSlB"
  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-4wQ/EqGe0q6B2x7PlKm2GYEAtFKe02WZXfph/etyA/8KwUJGi4uJ237MOVBSw8xe
browserprofiling.jssha384-yGjaTPiyFM5oaXv6RM6NFo4fZgMvJR+QtaIqTeK0S9DupOXPik4kxoBwYyoYUe5W
browserprofiling.min.jssha384-N5cyavfIy61/INhE1PWOPYPkoeZqHJDbqqA5b95HZ/3/uwtGTRzsEP0SZ7GW4unX
bundle.debug.min.jssha384-tms51cOtCSsQbQPyVvXew5Q4pIA87JliSeGxdcuWb0157ApLKsbU2h6R+3ceUCVT
bundle.feedback.debug.min.jssha384-Iv23XrxMlQhPaSGkNd+1Y/oMmljUDJZOGvYl9aOJIXWiUw7lsFGCjc6I4Ug/N1Jq
bundle.feedback.jssha384-Ij7pdudvkIFf27J2b8trYlqXKYNRFP1qfPOSmn3bdNksgfvgJdE665FD2eQJSci2
bundle.feedback.min.jssha384-wW4Z8wzvzpTp6nfNmzcbd/yV1AlWh3pJoJts2R5/Z0pGjRExo+rZBEkhU2s8c5vG
bundle.jssha384-xG7C1v5q7hm5FyPEkjUvy8RxMPmDPh2rM1TLl/6bxqw700TI2egrELKDE9ArOQsl
bundle.min.jssha384-lUDS8mchz+Cw11xMt/yUMpDqU5dAAgr9IlkPp4np9kgwJQnj9S2zyflDRZ7jGSlB
bundle.replay.debug.min.jssha384-GqRDsprLZoJuFxSkZF94A+tXbFnr/jeh9yDa6eK6ETUAUXv8tFMG5ywLtLN6xbg9
bundle.replay.jssha384-4xNspK53ptMzvAIkQ9vCgCw5RWfSBslndwCF1V6ZuL4DvnDoS94CmxHpEQuiFRlR
bundle.replay.min.jssha384-vb90i7hwfxer+E4DucPc+lVv/dWMANFuZ/C7Cwt5EPIMoHSnbNr92k4MDfgi6yHi
bundle.tracing.debug.min.jssha384-9g//s2uA7Z7bi776nG4Xc9GWglNfsWqMzhaXUBwqeYE+OoiFp7zPncjD0b5yI0Hp
bundle.tracing.jssha384-A7Z6xa/tf99cuT8K6k65vKvOugnWV/2oh6AMM10K0EkVjK87iagGjTb2OmBjtAHG
bundle.tracing.min.jssha384-0Rh0kgHbKYfrqJPlzvRAov1DGSCz/dW1ceE2q0QZHSHT35Q3lyhAN6jCNUR2bt71
bundle.tracing.replay.debug.min.jssha384-cUDdMWeugn/F3c9cPjWH+8swOJhrwTPc6NUeO7wQRhkgTCZRVAE6MF/vVkADYIAP
bundle.tracing.replay.feedback.debug.min.jssha384-oPOn7vzOjUxc9n7xPjrobL2wnq8kLM4COV8RXRf3l4NqXUwHyZE3uduHXylQ6slW
bundle.tracing.replay.feedback.jssha384-+D4i9L7ujhPTt1MrW78TYErvhrJXrwoxRmPKxhGdJhysIr4cp0nabETnQoFNIrn/
bundle.tracing.replay.feedback.min.jssha384-KrzZd4nKkWf0MpeUDoJW09zKdha7f7eM/iFerfvxkekXq2LLms5qTJ0hLmcQ+afn
bundle.tracing.replay.jssha384-mxsOPZS9c7q9yyOvObEU59WUz63SP2HpvKOLFR6ZR+lGEYI8qUsbIjKyyPwiZbrU
bundle.tracing.replay.min.jssha384-qj/49NHTE0QijJkkgYtWaQ+wOXFmrNq6XoqVS+lerZQ1sJxGpZzWWcwV5XDTmdmM
captureconsole.debug.min.jssha384-WqjG/jArsrQJF0wOsebvT7YNxNf5eapz+LZ/hWcmJh7xpSzK5Njy9u+mWGjpfDKa
captureconsole.jssha384-Y/FyTgvSrvYIQF0lijrlZHWKiWNUboWNFyLVY2w0Ib5iHubuMXpwO3hzXD8WXFJn
captureconsole.min.jssha384-+5z54OuEPjftTwP0sK1idO6eV8uyWbQdUWSvv/lqOJz5egIL6dcAql5tm8QcBNAQ
contextlines.debug.min.jssha384-4eAPQsz5Rh+J1JuPaoesY3bYB+DcOYnmLYa6aK8kkqkOe3rF0/oU1qwHmiQGUDSz
contextlines.jssha384-9V5BaRHmTn9h3dWLYAgQ4+uvWJrEgWGhtBRo9v+CYtJBTwMOErWiJ3yFpzYviUvp
contextlines.min.jssha384-b+m2bhKsEs/xLu15eDnEYMhjCypUDPdoXpbDzwza7F0TJog7qO/lRCio6os4yI7N
dedupe.debug.min.jssha384-ssJoL8jpC6MisljnKc1NLOn41BvrOePAczRKGf8qiucenvGdxEetb18+w0O99MmP
dedupe.jssha384-sMFrCSmD6xfMjqRweFEr9odWKDh+4BwI3U7kDZ2q4Ur0VBgwruhbBithJx+yzTaa
dedupe.min.jssha384-M/6ANduPEzHWQ5IGcJuuD7U2KmtT/acOuCqUg1fPj2r7YwH3B5iZHhxMjSEJlEXA
extraerrordata.debug.min.jssha384-bUpbnCUYOGTmGUoKuKvqSEYjEFaVzxNpGdNWpy6Y+ahAT1lg1vo8SqZnGAZkUkN1
extraerrordata.jssha384-pU7laMkeZ9X2On21PSDA700XHM2Tmx5ECvu4uqG9+jBQAToQy23FRGNNWsecVdEA
extraerrordata.min.jssha384-QzHPsflLlUr9d9eooLnmuaxrD1RKkAQDVtTWgH/6pyzxPUn62bLyiruK5OlP1t2B
feedback-modal.debug.min.jssha384-fuxpz3IFrCskVWi2I86D13AscXvIi8iu6QTm0IyAFE5PvY40Svmtx7BGXwxxOubU
feedback-modal.jssha384-9OCXgsaTdonNleCBWC0jajiY13rLD8QhOxeulWYYZ5gxahgsghuS0hq4HOLyBu9w
feedback-modal.min.jssha384-41llX6kYuErDDs5zUzdi3516fxk9irHZ/N6PEk8j0JgmFJfvjNkaoOT4G3CzGE4N
feedback-screenshot.debug.min.jssha384-sLoCfZ7tS6UUW5cP1apI6iRFu5G9n32ltGLTlyhJgpjwC+FxsiQ0UZVo62PIc/Cv
feedback-screenshot.jssha384-Twax6x8+YVupXR63XKdf+gX+OuOr46h3szQI62chhZR2nAGWiiN3sY/HJqoOlWdk
feedback-screenshot.min.jssha384-lDqzMlPSIRBb+QrAtmMbgtVLK9XZ3JqvVAm7VdGfqE584L0YfpKkp1/M9xxkj6Hw
feedback.debug.min.jssha384-/sZVk9hfMVc+3sWSz8jK2bE2TfrLU6DcoGYCgjEqJFnKqxeNU2z8nrpXz27d0LOn
feedback.jssha384-j7a8EGvBmDlOYgAPDca0A0jcYd3Oh/3hLCVrrLoAhYgyCpize3FKbXeKc2F3AIeg
feedback.min.jssha384-GVUcVncqTzqkJrLb+BJhnU7csWZzfVprfRx/0uxCSijGIeQuP9oWnFb5QahYyo9D
graphqlclient.debug.min.jssha384-GY04FYSzmVuxQQ6j0XdIF60VrV0aHggrE3PoeSDFC8GQnzfDmArcZPGkTjx1P9cM
graphqlclient.jssha384-lmUllACqFttP9f5NN5gqYgx96e4r03UMoHt3AVSCevL1z7I8Dp1ExSy3B7dG2K3V
graphqlclient.min.jssha384-cOPl03fHb2a4dQvPwzYY3MPTmVYV5rRy4DAVK+OuvNzTGQvC8CesawsAF8BR2g03
httpclient.debug.min.jssha384-k/5IAKUZzl/XkqEQoRnnLMuf08qKTWuBgtPLLwdYtyQBhofLVY9IyD53uqHUG7T4
httpclient.jssha384-m6QnSGO88wF2ysHko1VgIJrJoA9eSeza7W4NeRHMiPIqYoCwu7hVuO8BJiJpdsKT
httpclient.min.jssha384-z2DOMhY9KsRJuRwowvqvknuQMXmSk9zxLziQxF2PZ6YaAI/4zD/OxrcQXtflvrR8
modulemetadata.debug.min.jssha384-VGlrANwQvop9fK978WII3gklu7KQGmYT1HvHkdWpNFrvl95NH7N4m5yVps8URVM3
modulemetadata.jssha384-8zLknlRdcWDLlnnwdtbhnHcuYd9jLg7Ubvyi6SuX7I/cGcQafiJJT0Xcu42SjC6b
modulemetadata.min.jssha384-PhPHA/9M3qZML3FQOk4i0TUsWiMxpHvBETKuWv3lJyU3rXN0FfICdAt69YP6KJtX
multiplexedtransport.debug.min.jssha384-7q/9UPgTckuPgvR354hnWMe0yuagjyzqIHXH/VWnnO/fafgiSzlrM+68cPufZlqv
multiplexedtransport.jssha384-29w+LdRAyUBc9h2x91zMrGrhT89XE7LTUCQZ74mMAo2aHE0VdWCPVBq9dXVq2M5b
multiplexedtransport.min.jssha384-NQh0KnOy3H90Bjf1nTwdVQqf1N52oFxMiISp5N0eF1wRcB7XiDeCmRgzCBET/Htv
replay-canvas.debug.min.jssha384-TOMWIQSwuucvBhljcKJhAqGXzAgTtbK3DiTfV749HMAGBLOaX/bWVBreH8fd5S9G
replay-canvas.jssha384-Qx7mSgutIcNj4DOBQ+24znS9NkIGdcC1jTBL6CP5ymNDu1LreZjQx/jt8NmL3COi
replay-canvas.min.jssha384-xZh1ya7VVImXBimCt6unfBfjvFG2hZqenN4ZvIM6+vLbb8qsTMRjzkS2GthueWI9
replay.debug.min.jssha384-5o0urdDiu0FefcBomOfXYNhzUhSehWAAWd0z3MVfLER8XdLp5IjLQFK3lN7CykJe
replay.jssha384-Mahro2O0wevLUnvLpMkGyCloiUDQH7b2u7ayLrBtEYOo950xHD4FoD6rvImqnSoj
replay.min.jssha384-5meAD/etXnENaKMwQwWaA9WFVcG/9gQ6d4doUNrjD9dWuMC3ZcnZMhfibq/eLWi0
reportingobserver.debug.min.jssha384-vJD7Rjm8+tiFfU/JDmCsx0trBkTs0dzgjPzsNm7lYW11+nFu395x8CXwfGeWeQk9
reportingobserver.jssha384-9R7YI6NM5pmtrHUDCGTOJ3iuOX6/eb7ZqM+vWEqHCKBYR/3y2UlKDiKoI4GNfZAo
reportingobserver.min.jssha384-jquw070gawPygyU4NNnEpwlRDy3llTj1hwvOTcJI+w/eOADpe1x0xFypvVvt/UKP
rewriteframes.debug.min.jssha384-9lqc2SmQg+emKyr/i4CmvQo/ACuuzR5s/WC7oXa88+855ZXIsvFFqobd5EOFqpyh
rewriteframes.jssha384-lbCPUEnhNlLnRqCD3soQcbRWT7HUb2+S/HApJeJ+fKU9b5CUgon3hiHrMl4Yv7UJ
rewriteframes.min.jssha384-nPCLime5TLjJ5yBD1o3q5YU/Nb4dVa2U85tWiKHsno+ml8TY0LMUchd1XZxUW21H
spotlight.debug.min.jssha384-JyJ0Noqeo7mnFFyt79yekLLOp5cSMd90CU7ER59Cbn0ngJYdHWuOHL8wt4zica+r
spotlight.jssha384-+iTTBxktQy0FYiICNoWJJ8uBY6iaqkiJSLBoSwfEtBH1GQ9VrUNtG2aUFbyO5IIm
spotlight.min.jssha384-PcbFD91SRJcvPQAiWok+LdJqdUGufYbOtLCSwvdJxl7LQ1sU66yCkRqZnWCh5A+F

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").