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.44.0/bundle.tracing.min.js"
  integrity="sha384-3m5VvE0YYRz7LnO9flhfml2hfJNz8BhKo9DRmC66QcGrTrssgYjUN56iBZBIx7eE"
  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.44.0/bundle.tracing.replay.min.js"
  integrity="sha384-/D6GPrp3W9EX3MA70S6PAg5TogPOMWjFi9SeCfLLBZmey38Xu8ad6i0pHgKvAgCk"
  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.44.0/bundle.replay.min.js"
  integrity="sha384-00L9DBeQCDowXp14Yi/bWKwj4gWl/4yPg2HKkxPHR8W3fkKmkaBugAKxypnmkiTj"
  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.44.0/bundle.min.js"
  integrity="sha384-6n/7hg6zA4gByvRlXnBK6Vwvk2JdYJJi7iCssV5u+/ZeH6LvUii6cjJNOvlT3j1Y"
  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-IOo+4QTdmj0X6XAEJUMEUmxXewBfe7VcDdphTIXaZ6LJphCt+n+jrQeSY2xQ2q+V
browserprofiling.jssha384-R5B7ANqCz7S1A1cpbO5k6MJXK0giO/kP9zeK3PMMNEj411VO5WMDKe1JV3Oi3gkg
browserprofiling.min.jssha384-xZTUyB4rDBf69Af+mjIQOxUCXC2lNa92P2TRCexAmTFJmzKS3UQZX+Nuqg60oGRX
bundle.debug.min.jssha384-GrWL1Nl37xAVcV0bte1+6C0KA9EJjO6WM9bLc6Sm/K063SMO+aqNo95ndKqbCa7w
bundle.feedback.debug.min.jssha384-w8deL2ZVGD4hgdrGmspOrJdtcgFmBwErU7x1l4oyl8oAre+8Foyr0DbwtTXuIMPA
bundle.feedback.jssha384-lhnJeKj9k4GtO7/Yd8oIBqjJ/flcqvv0YCbQRrsnmRPU4VV70U7vXbDIKAyu8GCR
bundle.feedback.min.jssha384-zOyqTPtPD7bBNQoPQbc9tdIS4TYy9YZIJVpvLSa1Q8QLu954fobZYiHNL0T+FP7x
bundle.jssha384-qUq0G3D3vvgFSku0g7p1KMfaqghLQCAFviDGE+bT6qbxKTF1xlt9iZ32ODrjYUtE
bundle.min.jssha384-6n/7hg6zA4gByvRlXnBK6Vwvk2JdYJJi7iCssV5u+/ZeH6LvUii6cjJNOvlT3j1Y
bundle.replay.debug.min.jssha384-VIlHqFj/rWNk8teJ8MU8RXwZbqwDuSbfgye3xYde4sQVRGzAS9y2Ysql3ZydmqxJ
bundle.replay.jssha384-FQtT+TycXWQt+ayCeMnsl+ijqfYMfUhDigVbZ/2P51xpG1TleWK0xptBiQ3eQwqY
bundle.replay.min.jssha384-00L9DBeQCDowXp14Yi/bWKwj4gWl/4yPg2HKkxPHR8W3fkKmkaBugAKxypnmkiTj
bundle.tracing.debug.min.jssha384-j4ebf6QAYs/ixtCOr0m95W/B1IvVZDMynz6M/c4SY58eLvz8i+QCdHzSY3tWfp42
bundle.tracing.jssha384-MAQDAdcp1bEutWgyr16ymCfAsooHiRcwx7MtCUii/8Gmsjqw/kDofswWPtqCjoyB
bundle.tracing.min.jssha384-3m5VvE0YYRz7LnO9flhfml2hfJNz8BhKo9DRmC66QcGrTrssgYjUN56iBZBIx7eE
bundle.tracing.replay.debug.min.jssha384-Zv6vwJ7dtCXL+9TEJioaMLJU8RvF2m2zyM7V5y4fBx2ZfM3nzfRCbYAsZq8uja/o
bundle.tracing.replay.feedback.debug.min.jssha384-B3STMJTdSkb/VF1I5bUZ5YnHzcDIid4CVRHKt04rekhYcKQUE/Zpo4wFUUlu+Xiz
bundle.tracing.replay.feedback.jssha384-YKP7aFEgX+27TqKVY3KM2DU4S5InDI69qq58Kb3TVMEqb8mB92u3WVUAW2U91tPs
bundle.tracing.replay.feedback.min.jssha384-f7cG7RPm7hSGp8GwmJOpKYQJf8TJ75jBj/mxQ1TRqQJB4lokoejsZSB/HCWE0U9t
bundle.tracing.replay.jssha384-re2AAHe1HZHMgvd8HZ1nlqg+25ilalOpbCW4OhFy+RFUHBraDzD4vKdwKg/03DW6
bundle.tracing.replay.min.jssha384-/D6GPrp3W9EX3MA70S6PAg5TogPOMWjFi9SeCfLLBZmey38Xu8ad6i0pHgKvAgCk
captureconsole.debug.min.jssha384-tKTGOmBsHHZ1/xbBEymEPmch/3DosBmfx9eG5MlLVUwORcJaOsBEL+W2vd4TKKwg
captureconsole.jssha384-6zkpu6D/LuAIeVs5i+UzUu5On1/mL673cFBXN5dVxxrhlipSlG2kkrYEUv8orO7Q
captureconsole.min.jssha384-qaGWdxQxevMsO6ZEpcvpuXYFpmid+aKW6YdBqCX01Jm2xNHw99/4vVkgEI7IzI6D
contextlines.debug.min.jssha384-QJCmPe+zZMxa+qYe2Nf1eDMaum/uyPNB287q8jkCN0xgnyxUQ2r0PN5yn5wvtrqy
contextlines.jssha384-xCzaK8aqBJqgktkP2k3doi/jyslxYwr9hzqmpHyHq/L6A0V3ub8XVrChcxIB+aXA
contextlines.min.jssha384-8qe4Tu6iuQSPzchuoP68JZqNuVfkO5Y0s1dfhAX9bJDvua6RYO0w4hx4OejirMoG
debug.debug.min.jssha384-kC9HSDv3uFjzc3NHvCAkN18HSeTNsmst1jTjPZ3QreHh/rFFlCRyz0Rmil1wi/1m
debug.jssha384-sRFYlGg9FzY4C+hs/wD4Hrwvta10rWQUjfAw3rm8jOMeRMsOemlM5uX7jy2go6q5
debug.min.jssha384-2w/DJieliRv2gFGIvpjwiG5yYZy+dklfpmAL2XZur3oBUV6lkBt1zxiKL4UVwxu7
dedupe.debug.min.jssha384-ATHeyXCLvUrbzpKcXox58BikzQ7m0DLJd4wFy03oI9R78KVH6TOPZwpFwMPb4p7w
dedupe.jssha384-HS6/pyXJqvUm1b4n93v3oVMEeT3Hc0GxBfgv6ZlgRhxePRxkB0rgzitM/Rps6n3J
dedupe.min.jssha384-SyjtHWZmzXa970YaY3PCRuAz76y5gKAB1DCyKDtc146qBz6CGwWcmPoG5MvyDchK
extraerrordata.debug.min.jssha384-76HHYH1j5kF77fvsKU/+UD3+FKldjUqDL8ynvOml9zjhcthqizX11ytQ6oBNo0kc
extraerrordata.jssha384-vZr234Io44HHV+d/iPh3+60CFqjkDcxVWKAFn9ZtXvGBPqR7SZ+W8Vdj8dNXP7u/
extraerrordata.min.jssha384-S9KADRLj7BYnr0Hze+bqjz1DSPPTht3vvVqoI9+FTpkMKzfNnuSP4/l8WXt+qf5M
feedback-modal.debug.min.jssha384-g260suDEvGB3GgbI1RVEoy8phyTptS+jfSLBvv3giQhZK5V6/4v2JNjWfvX0tG5U
feedback-modal.jssha384-UBAFNCNH2bT6COEfEyITpXqDTGAoDEA6F2ii+EKAK/NWrMdGUZ8YCbTep6p4ckEd
feedback-modal.min.jssha384-OjSm2TlNGSnOwt99inV7gTd/PcWksflp5VvcP2NNnNt0PeWTv8/VgeOCFzlC8/tS
feedback-screenshot.debug.min.jssha384-pyMZlQlvSCGCkUm7clicxdNwF/49NXBMbONhqVqmY59rerIMp5vZQpPQq6vWPs2I
feedback-screenshot.jssha384-AqkulSehWwchLhYjR8C3D5UuVdJcQO4XdjfmmCSRpoJKoALpl5tuLVrVChxNJAPK
feedback-screenshot.min.jssha384-o9aw3+p9aYl41RBD4ncFh/vCY8/QDlB3nwMfrNhJhdL56xkzBlDXTaEmHydJgW7J
feedback.debug.min.jssha384-TbcvgKLxiTtpCacXwQn+5Tt1Sdy55jaEVEYaZ9U4p+HYm+nGFPSA7asfdL/GRtwk
feedback.jssha384-MwIR6wSj4Z1mD9RkPemzc7TrkvZTk5qa2Ty1KtrG53RYmPQreTUhfaqFLYPwkB0c
feedback.min.jssha384-K7NEwLjU2PxMTK9ezOO8niPtj+RgjQ3xTu6i1eVLyTOyEQhQh2MOMdhJ0g+YO4nX
httpclient.debug.min.jssha384-EtZTcWDJjUrlpdsQQ8Kdv9jfmiKu3ZLiPRDE2xkR86+edVEe0vTvTVp8gxZicGc8
httpclient.jssha384-/eHg8ZmzyWREQj7Is/3eaga/xAE685TWI1M3M9bx1u3+ep3RbiToxO/OkcCBwlih
httpclient.min.jssha384-sGtF2PbKq468p1DjgwBSUPXmSCxMm4pHQUuZzP5J3aDxTd1Bo/+ztgxhSlkvnEuh
modulemetadata.debug.min.jssha384-0i+JJqbiV3ZUet92AqbSxJeVoSbJuBqSumHZIn4VIVONiEkfpFEjqSQPwjjf2KUJ
modulemetadata.jssha384-JJnVhtOs6aOG/d6I3hMOTxBfQPJGHlMKUnUTDEWjn4EgVVWwMDLgu74lz/0OyByA
modulemetadata.min.jssha384-CHg44iTls4Q9aMgs+rVY/entiym6vfc266NaBiel48lJi2/n6dvI66VQIspTtFt/
replay-canvas.debug.min.jssha384-SuiHUdMQgkftF9Rricqn+jKdG/YzWoEhdXseoP6J0jbxA1C8opQ6bvRXKI8pHy3W
replay-canvas.jssha384-F5gwHT7DL3Bg858UDZbpIrgr0X+1eKzD84GNQWWXzen+4sywE3Z3kfR6lyI7PQdB
replay-canvas.min.jssha384-54Jc3eRYczTS3EgYxPjtt9Ss+OnUO/mShTX0wiPt+PXSjvnUF8oW6rOk1oTRNicH
replay.debug.min.jssha384-feaUT3y+fFkjfQvomrUnsaLIzzNQ692okjU6Q275Thh0S/1UcXNQyfs1R5kZ0YKq
replay.jssha384-YiNsMeQEcyUVUa4rb/R6Rkx/oLuzK4tW1dxmk0XJfyqfBfnB+QkA7JXO1bpa8jFR
replay.min.jssha384-NGN5CTeLip2xD01mhY2I35ROF0Og1I0X8vgaL7zJB9okBoqL8fK4XYHBpHJXx5dN
reportingobserver.debug.min.jssha384-RZU6BUYvs2QjdMBiCjx528EanEhqegzQrQHN6htj8USkiFaEBiMmiT2pY2FVad5R
reportingobserver.jssha384-YEglUUY5atiFsPgp1XITu+c8fqx8sxfTCBG83pHG8NKvyUJXakQz9LFiMfFw2KGO
reportingobserver.min.jssha384-yOccSUbiUB4dK+oAJyn3FZpJXg0Tve7Ygz4hiG2OgxsJUFfu3NpFZLZzBQN/QGi3
rewriteframes.debug.min.jssha384-205uFpuyfeExI8NLpzLFE6O9IKuAh6gs8t3pEO7AbzedOBdHwRYyYzI/0UTMeyRY
rewriteframes.jssha384-apr+cupaH0Kph94/QW7wBMG9yszl6HfSZ3dEeCmsDlJHRD69ZsxHKMbPTCxnXr+C
rewriteframes.min.jssha384-84/Tm9TQfK1oxa5oJ8p/8OZJGWn18uuZAFf0IyAw2oGIxHE+Wm/kCioCDtVyT4zP
sessiontiming.debug.min.jssha384-xbg5xhJHog9gbQRWzu8tWy1mgsuMaaEDLm+YENWP9vdHodfKlRdbHIh88R9oQNk3
sessiontiming.jssha384-88SV4EIxSPylH3Z8kVqfVdxwLZy9z/YgJvajp2cvXXlUPlZjiTHGVd1sEikyN+hs
sessiontiming.min.jssha384-CNu9G4/ofsyu70NL07FzKraX75vz2H/8yH//Mj4eSJFm+ZAhKhfxPLO9BG3azCqg

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