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.43.0/bundle.tracing.min.js"
  integrity="sha384-WjzSxI4vkfFEvLKQ9wKDdGh11nmGTkya257EFEFxo2ihTKUyQIu6EZp4i5vcny/w"
  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.43.0/bundle.tracing.replay.min.js"
  integrity="sha384-RZEjPqh7/5Hc2V4CeCQJg21X4trTPXLORmZ2+2uTU7MpK/tengvIdbxdkCcWs9Pc"
  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.43.0/bundle.replay.min.js"
  integrity="sha384-ZzMd6XL30tOI6wiDrgRqijayl7Rb0pMZZkvJDDCEF6d7UzWwdNzMZwP0igI4poBg"
  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.43.0/bundle.min.js"
  integrity="sha384-9Vx8i2VuyhZfQnBvvHjZZgMTfmGzV4C2WixkGM0uxmcy22GFXn7CB7RE7V6E8Tth"
  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-Lt4AKgT4GMOH3qL5e6w3XvFptHh0LViWvCm8kL5hfh5xHfODcWMb9PnReMqxVV0O
browserprofiling.jssha384-5tXFSc3Ms/ZHgIj7sfh97wiqBnHM7WdwvGYo/1AzV7DvEmFx77ZXcX1MLJle1qmY
browserprofiling.min.jssha384-W8lL9yJiutY3XRaF6el7liCBmNItif3mx1fblb/nuOvvzTTXI9csEYFPRlH6dAPj
bundle.debug.min.jssha384-gWxTU1VzdQBS7LVQdQ5ljVFgPa0K37bP9/oEHp9UJf/8MCCWHgOgAsaorihGzuMq
bundle.feedback.debug.min.jssha384-Ft7sF+NYvmcO5ocMckvEJCW40TNB7IFe4x9hekY/P0sImSDxT03T7eHez+eI9DyE
bundle.feedback.jssha384-7dui93AZzs/Beni3nFN20u9ukgxOtG9xPz8SKpdvDxn3xUstQU33zZGQxT9Ccti/
bundle.feedback.min.jssha384-Ttp2AW7Jfp23IwAWHrcxj/nHrbPTaNhrxQgKlQ3OojprORO21MShwfMHXMFhI/QW
bundle.jssha384-9ZmQh829sdaVb/hktv+FPrNeShOJdFHKk3CKxpY+tFAbzrD4CW5TwMbdp0nKsa5L
bundle.min.jssha384-9Vx8i2VuyhZfQnBvvHjZZgMTfmGzV4C2WixkGM0uxmcy22GFXn7CB7RE7V6E8Tth
bundle.replay.debug.min.jssha384-2TY+WjwcBCdt/XAewC5bt6Ktn5ZM9HIkWkrJ9vFamvND2wzz540uY/xlZ63zpIQ6
bundle.replay.jssha384-TjoCoSJ83SGB+75iJvjMcgLoPKpaFKf86TzUv4PEMhBSe6U+O4+/xMFYbSfgfAsM
bundle.replay.min.jssha384-ZzMd6XL30tOI6wiDrgRqijayl7Rb0pMZZkvJDDCEF6d7UzWwdNzMZwP0igI4poBg
bundle.tracing.debug.min.jssha384-pmFni1cy0LmsAV276sNDqMvi6Duavau96q96zAKw2tcBc1oNmxcoaHSDYrR57gWL
bundle.tracing.jssha384-9B/K2x53W30dC4K1HtoJWkgj+mx1ECu4zCREnfMagAjXJi/tdbB0vYIE7uwQ6Zxc
bundle.tracing.min.jssha384-WjzSxI4vkfFEvLKQ9wKDdGh11nmGTkya257EFEFxo2ihTKUyQIu6EZp4i5vcny/w
bundle.tracing.replay.debug.min.jssha384-pxUEgR0WunfpCB4QZQ5uA3UIpJ7HkhFE1gL1q1CDHG/jw5GPzeqUItZ6tG+nGeB+
bundle.tracing.replay.feedback.debug.min.jssha384-jS1sTAnALnaoMzy36Dtj57sCvBkFqakoLb7aQ1yN5E0nq+1Ip8dyoHOZck+a2edu
bundle.tracing.replay.feedback.jssha384-G6i1cZaqNPR9pAFclEbApd7QFkp1mZxS3UmzgTvPjUZ/CiEeowzdobx+gCd1B5Pa
bundle.tracing.replay.feedback.min.jssha384-php+GUqr1NsEaVpCYemxrVwm8CxbdY0O681ksxqDB1Mi29m0lb65pDeSBHZgQdJm
bundle.tracing.replay.jssha384-DwrOe8ISTDZ3KHhKp8ceKJF/wsHxPL/bGAVVnbfZWnHrf3ns7dTrAEBtr9xCRRXa
bundle.tracing.replay.min.jssha384-RZEjPqh7/5Hc2V4CeCQJg21X4trTPXLORmZ2+2uTU7MpK/tengvIdbxdkCcWs9Pc
captureconsole.debug.min.jssha384-SPP39/M0D9rrcECGZEmp9HxnLtgae0D+7Z6FZXzizvBO4OcwxSrGphZ6pIMAQfZs
captureconsole.jssha384-nejvvjhqnJzfH9iyrIYa//8Av9vNnPzigtRff95xB//g2gHLuVv3NlUC/lEWO1ex
captureconsole.min.jssha384-eYLhudrj4COyCqtRuNSKuOKcFAc9BXonEf++gPAjjHu+kYEMQj+rAOO9+8C4jbG5
contextlines.debug.min.jssha384-pXX2mZcdtGG8xWTy1V82xqoE+0x4Ad2ppiW4V3bihO2OPwUAlCKERdVhVCPKTWe7
contextlines.jssha384-jY3ZE5nRgQZJdQ0/NBQoIhgiiricLlvlPSbjA1hu1qGyvr++evqgs0kXwjJTgH0u
contextlines.min.jssha384-p3wIFWcG4h3k61kz+9afUlSZSLInXmC6jFTKFkNhYR+ncpCnInA0MQXKRMcyE1Sv
debug.debug.min.jssha384-vvhOc1O7jWQ0t01huQ8vOtwtI2FedgQBqkZcYQD69293salf/iYMnngUnYteQJ7k
debug.jssha384-rfQcBpFAbFQxck6+SzO26cWKKOgXvhoIP//q/2Pz59pJTtnnTho8LQK0K6SCck7m
debug.min.jssha384-OOQFlZcto9lJoPhL/YkoKBkc7YkxtEgEE7/BH5/dFy8I1i7uRblLB6uwl01JvgCi
dedupe.debug.min.jssha384-elI/n0EsGRQWVs4/1DHjmdENiQM8ngfsyEuDtKCHonTwhnCMq7hUUcVrtVdSgj9p
dedupe.jssha384-8uyxsbt563noG3YxYsEV0UUE6JZlwUxArAqGz7lp7PUiYq81Bar/JdMjfmKaf3+g
dedupe.min.jssha384-/OovZfG7/NzBOZPiCMptS/4eaaEVQVqnwqNHjWfdE8yiHRbOGZBnGo28zkGAf2HG
extraerrordata.debug.min.jssha384-ZtrFx8IxXAA6yI02MRPImi3hqIKoq1hqmz7kPbxacSd0vmNzX38veUVOGOPdqPLx
extraerrordata.jssha384-g3k0TuATy3QpnDOj8k4HAK4WeU0df1tAD4vPVqJhJKQwtV8/X9l4XLsqMFgabf7K
extraerrordata.min.jssha384-fah5upfESZNOrUq3GxYusVLPUOFASZqrE6V6SNYuC2mlIg8jUSGLQXeNRnp/iwHo
feedback-modal.debug.min.jssha384-/c3a8VNQrjYMh/tzGQCJnmteJFlZEM+gudT2C+CKEKT4Mtk8dB6paFY5JuMvVJpW
feedback-modal.jssha384-xU6J8Sf0yy9mDwjICUafyfCQfTkGd8loantEzaWnlGWMlPA4vM4HzTwmYT7rB+/8
feedback-modal.min.jssha384-SUidQZgvmQS9u/NN8O12pUbO0DHavEzqHAi55ngk/zGs6fO61lRLoqyFi5jKagcK
feedback-screenshot.debug.min.jssha384-v7BKsrSdTVJhiOTuGI36jZeYp8HiW5AbZ8igkNBHaLP4P0IV+fkVKkMJWN6SJhGS
feedback-screenshot.jssha384-pEIYPiKx22TMoFAIBfgn20ZHJ5hHvWVwv55MSMpYbpY+m4smcYp9VQUBRIusgE+O
feedback-screenshot.min.jssha384-luuUAhM6UWB9FwV0fg719CHGilo0P2IcCKgpVyy1v4x/HMmoAEsm37Khqdq9ugmh
feedback.debug.min.jssha384-M6jb3HdXZkbTyCHyzW78TWr9ufw92G3MWLlKqntYLxQhs5ghtADnO2x2ZuLw6pHC
feedback.jssha384-TRRt0JofHDgUu08TtWrOVjthXi8+ULIHqP3IG7zT7D9nf1Kzttma0Tw0fZMqmv0b
feedback.min.jssha384-AJ3b01bZDifMOV/rqTZLAVSluI+xeMmmmzaLAcN44G1OqRpGAxL6t7rMDRF1TPfz
httpclient.debug.min.jssha384-j+ele4gUETYwvXX/JXb7d8k7I1EVzpxYYw9HCCuv6ZejO8TklSEV6I9TjD3GG+Bs
httpclient.jssha384-hooEnaoPgC3QOCpacHEAhs3eDYM6c/8TsPB9FeGBVRNgeKOfVOpeH39baCWDAx5O
httpclient.min.jssha384-HpjjVWPl/JUewKWi886GmFpVB6j25hnKDI4/DGV0AdF6IR4Mz8AOUVYdBoZl1kYm
modulemetadata.debug.min.jssha384-0EQd0mnIc9uKo/tFQW6HXkfgPt3pyF0SptjMHbqSqeSxA0RHJLUbnZzjHiO0HExN
modulemetadata.jssha384-oEAJd8Zz+AIP+il9h5HIEV9hQy41dmyPk1s9I+aMkaPZyb9h6wDcEPRaYErc6+IV
modulemetadata.min.jssha384-oqZ2XQ1eKdctQjiE/FYWE0ii7NS8dWCmFs688Qc+NtxC8PJAEl1yFj3mJJomYmm+
replay-canvas.debug.min.jssha384-uFNPkIN/Dnk/N3EwequG8iUh8FELb5Nj4QNekgOUlZW3V7FGL9p4oGnlBJ8vPr2e
replay-canvas.jssha384-PmYLIpk2TGNi+GwSVHrGXsHIh7k131LWJaAR4EjJuYdy1cSjjOPNYaSCKYu/FsX5
replay-canvas.min.jssha384-+EPVh4IryGCN3bG735nai3sPx6UixffRtjEyjqRZxRickAHE8xW+LdhRdtGrUSF9
replay.debug.min.jssha384-BShKrBeH+i1SeQq9Azcc2e6yW7/Qzd7IHoDQAgfLVIN/3+wP8ToVbza5zFnj7GcY
replay.jssha384-NSb4JjBeSofojL4z5mFibLBijypwZ+ZuoGtKHmq/mg4JiT1lLN8Sv1kjNtR2L6Aw
replay.min.jssha384-AgKU5IYTXNkQBgQNq2WdaxXhtVmwYwMJvxftjcOop6C6e5N5nWKI+lIql9curEhF
reportingobserver.debug.min.jssha384-epu2YMr9mOaR3Md7L9pRLf/fG1KLQbbOaUxgBJl00JP8lFX9hbpumrPPxK23uDP9
reportingobserver.jssha384-VQX8cCswJ1pcB0vsUP/VH3n4R9S89DG4nhfaEvIlGFbIzwvitAbOY9pvzmZ5DvKa
reportingobserver.min.jssha384-WckVIP66sb6snIxZUlVnCoDRN76oMXfDs3GI/2bvMj7YXAiNoy1P6yBwzRmYGPD6
rewriteframes.debug.min.jssha384-igjxXC5FIOgPqUxV1m8m8QM/7C0R0BpsvK3cgZOaNOgip2ASeuindecgge4JOYnO
rewriteframes.jssha384-VpAgyU17WO5mHzpO6HSB/O6wTn89U76QQPOcB1PXhv8ovqNPx2NNzJFnj4r6dnAF
rewriteframes.min.jssha384-b+Rs+dHLxo4ff5Ep3zRlFg/evrupkXygARIaTJJ0tpOJZ2rbUXT4UmQ9GdD1PCO5
sessiontiming.debug.min.jssha384-LVxjml5bVbwOQqgblm36gRJ1SkksTmGngXfgHXUqyPN2glw+HUotdSr84Lkhmc1l
sessiontiming.jssha384-6nEubFH3es6+MVSfbtyDNm+rTmpc7ZpHvWEYQMnvqsNDjh5fiWFFC4wH0tzWmYH1
sessiontiming.min.jssha384-o6+xGUh2IB9r3K1lrFq4w8sLtcviyd+nA8oDyHsRhe/8UWFMrzoVOzI2YGdLXfpB

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