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.28.0/bundle.tracing.min.js"
  integrity="sha384-GVaBBYGuaNuY8QXk8YojAIgLouf6OZ9bSBQRZ69jdPLVgNCZr6yFpW5vU/yXHXRb"
  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.28.0/bundle.tracing.replay.min.js"
  integrity="sha384-5c7zydvXVcldrwZ5+MVUwVALe6m065lXtj/5jNCxaNR7zMHF2INojPudNLr1OpJ1"
  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.28.0/bundle.replay.min.js"
  integrity="sha384-HPRDb72LisHlzzgnbGgFbpOzKDmzEVWhACFXQEL3xdDsoPjtQK3ZGFVvERZzBj/Z"
  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.28.0/bundle.min.js"
  integrity="sha384-UEYQHY4EIgg590E479enuYMIM2UcRnHwxOvFJXKPSZgRV7QWrgjHQLjjwKlToWHT"
  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-wD9u1ZSpmisRQV0zz6/m72RT6oCB5c5eGBiFN57912NzDRmHdHxizqfaxsFVVfTL
browserprofiling.jssha384-tsPe6+RJA9FHhSZpES6MdkDe/NcfprX1Bw0fLkUaGpnYUXvDVBh2ksfxnhujWuyY
browserprofiling.min.jssha384-nDapGH+PmUc+8cWekdrlbg8+oe/EI+BtXzK4kGYjiAdDYnzrHjslEVTZ+qnTCfyk
bundle.debug.min.jssha384-OwgcWxXIAsP1lOxHrjek/c1VyaUFlHcJtsJV8UFKlPJojiHkfLr4aXY3cJ/+h0Fl
bundle.feedback.debug.min.jssha384-Zn07S75iLjTV+wy2kA9w8W+6yp3mOnSQeaENJTrfRJav1B25MuoA95iYhYjMx4Ff
bundle.feedback.jssha384-WEZxfuag9K5gBs598Ar6CWlBn6tZM237mfzK1yrouVHmSNfw35kPrnl8N5chz7PN
bundle.feedback.min.jssha384-MG1eFPTOK63DwxRAyFXmon+UegUo1r3pGHz1SNoe2qa6Pj1m9qp/9PJEeyTbX52X
bundle.jssha384-izUpVBkwnvP89dA7xffPv1VpB7ZemwzKggmNDSAUFx7HTreJY6mCLgzGb6JjADxr
bundle.min.jssha384-UEYQHY4EIgg590E479enuYMIM2UcRnHwxOvFJXKPSZgRV7QWrgjHQLjjwKlToWHT
bundle.replay.debug.min.jssha384-degRsKoTe8n99HNqopRHDxDyvqiTR/RA/43tY5Da2umaMoytKhu+ghYmtqwhnfvT
bundle.replay.jssha384-6K1iPfKL2H0X9m560QD6ozSXZ7z4WXXen8u+zXXM0KZKQPj2ZW0M/RGLvU/bs/Fg
bundle.replay.min.jssha384-HPRDb72LisHlzzgnbGgFbpOzKDmzEVWhACFXQEL3xdDsoPjtQK3ZGFVvERZzBj/Z
bundle.tracing.debug.min.jssha384-ZdTJeXutSYMlLbia/npfpCJTu+SyEDjYT/cBzJ+AUaQNkl0ZjZecbSFq0yEvueR4
bundle.tracing.jssha384-NIemS0SYiGaD0h12KWA7OozKuG6DUPmcKRqr0U1AUK9POBape7GUYT5F5u6qQ25g
bundle.tracing.min.jssha384-GVaBBYGuaNuY8QXk8YojAIgLouf6OZ9bSBQRZ69jdPLVgNCZr6yFpW5vU/yXHXRb
bundle.tracing.replay.debug.min.jssha384-yChCfnJOa+UoRM54ZklU7XnU7CG8zuuZcOdD7gOCK1qaqqUN2fMDg42Zz/oXueMK
bundle.tracing.replay.feedback.debug.min.jssha384-mr2kzKUSBXobzyVwbTZGDUYCjkHFsCXIlGZfl3dDNl+MVBxC7qG1gd2TZHLeiTvh
bundle.tracing.replay.feedback.jssha384-KnPzjMI7GcNItUWbf/YduiNQCJ9sRVrv9S0GBhEqlb1F9FLYKVeiLb8/tIPhrjEE
bundle.tracing.replay.feedback.min.jssha384-3UagbRMCdV8NyFQ5iio/tkLs/aUgqb1VmfmFFJ0xroUDtVYjwU6GrA+OX/s+RSEk
bundle.tracing.replay.jssha384-Y9Bx6SVF9NimIFErGdKZLlD7VHXaLW589oXhiGhlbsHVKkepJI0sW+GtNLpitZ+r
bundle.tracing.replay.min.jssha384-5c7zydvXVcldrwZ5+MVUwVALe6m065lXtj/5jNCxaNR7zMHF2INojPudNLr1OpJ1
captureconsole.debug.min.jssha384-Dli6INgGF6dGecBM7SU9lkbtWKTAXakXDH+Itul9fih4kvD5LQFgQrmap4XTy3dV
captureconsole.jssha384-WiUmO5nvEwmS5K+G0KjYnYKsMbjLwkzL8SCpHPWQkQI/+YR99f9RRTeZI6m6vxBD
captureconsole.min.jssha384-c0Je5eYTMY4KQsZrJLFQRW9JTFeUyQonVzlMp0hQxyCEyQ5Mu1l2BhpoDh7frgZu
contextlines.debug.min.jssha384-lqDHgr5cEySl3ACj6y8OtHQRtVkyuKYtw3kilrgq/RSMgZ6id9wtxEw+uhSqmjL3
contextlines.jssha384-fe9v2fNcNgjzGSjpJ1Tm+CBGVoMVMhn4jHKcdZYbvLXTJziXyUfK9xFBtEDGYeK+
contextlines.min.jssha384-Gr3aQFZsAyRWfn8ztsI8vuoaDOgoIXOfmku+4sPmzCYDn/FAE8+Ci+oyF68b03H+
debug.debug.min.jssha384-mJAX4B8dQqpFwEV/T1JVz8GP+7qjrmffo4b8t47/madxl0CIfacmTX34OxQ+dHjW
debug.jssha384-IOF2ZZmFvBUvdn+h8e6M2wn9A/26d5agaMd6J5L383Nj9HPlv0OshUILtQndUvHZ
debug.min.jssha384-IzkSq3f7rETwHXu5n3hEcXemfrMqr6tSUVB9qbblSZnRmbTvrhaOEC78KGJAej5F
dedupe.debug.min.jssha384-mLhYnc6S5KNFRtO3i6etn1aL/VZSjDV0WbNS8rs54Hqt9iJbQU1KSqPEX6Fv2tqS
dedupe.jssha384-Hmn/MqcsVY05biL5gWec/gT7QoCiRO30IJ5EvvwKnGWmIVpsw7n5/8R6uZh0En7M
dedupe.min.jssha384-KQE23naxK9BBWbZ57vegr37f2GWQDORnDUgfRZ1ryCrqJlqqQQ7T2MVHyY+DHTTX
extraerrordata.debug.min.jssha384-CW3kpO9or9uUfK+LlzT/APPFmwl+ySvD7u58trEX57rBLYdECd3+p0UcL9u52H6L
extraerrordata.jssha384-0Rsp8EvMjZxH7IEY2vwY33RJK80h88pG2bog5vUqb4Xwxndragp9D2K5eUg2Huyt
extraerrordata.min.jssha384-N6SCDY3SZmmvISnmM5YhDYLLHdSXE4gxiMV0f5r+L+SfKHLP570Y7vaQfzcFzk6y
feedback-modal.debug.min.jssha384-NJnWvmOl2Upta0rZFudPBs/XGfReyUShrK8rGhfS2qShLfOiEsmthiWkZ0px08AD
feedback-modal.jssha384-JqMU2cuupNJP4EidugK+mEobD6bYZd/BhYf7IlPnUuIsPaTnBhrZ1kPBe1SgNr6F
feedback-modal.min.jssha384-7jv2czx/UAxm6S7+cXOCY85bdLFQNHWBS7Ga6y8+iL+tj6iPV8EFl/Z4eYjKuCwr
feedback-screenshot.debug.min.jssha384-sEhyZk2LqW/bu8s3gwboWVvfrWVgBfB7D7spaE4cWWIHPhtGQQgriV4WylUStRzj
feedback-screenshot.jssha384-JpTG+UKenh9LujEluN70RxO/Iy2f2wn28hnWSEhliRdJOPWONN0I9rgjaPdPEaHa
feedback-screenshot.min.jssha384-1ZWB2YIN6r9vkZfaUaeKZp58v3KnzSqxlA3euP8OT3quPBhIMXvCr8VXtdC2Uo6P
feedback.debug.min.jssha384-D6VqP+4xGn9A5IAdVMkctjFO087mYsuKW/R0QniikpiVqJsAzg9w6FpgGWowDoid
feedback.jssha384-32YOpAPqoRnLCnUSNGlRB2uh7H+Ar1ipjPrBVRUvhEKcjPZd/wqk8uf7IlQ2OPwl
feedback.min.jssha384-A1ubvhDTBpmicz69uruDMDIWPiFmqeMOyHCdZrGfHFqzY2DXsKr0E8JUMfEdGk8n
httpclient.debug.min.jssha384-ZqGA6+4XeSmWZMsJAmW2woVMn389ohn7uJYZBYVZXv5JIU5O1nVHTD8qUI7FuBfU
httpclient.jssha384-WHt+TdpcfqHNmxKu4/kbFhouEzhPY9B14wuusOP6uol78XoJubPyJsJlNQTw9fej
httpclient.min.jssha384-i6hh1XYhPk80V7SU0gDSdmZevkkFcQSNb/EnVFeba2cWSXLSW0rQRDcB3RqUpBx0
replay-canvas.debug.min.jssha384-x4jyeJcUaF4Dog9pmAhTgLlk48RlWdTplugpRUglOUm/VyE19Klg2C5KAHMctr+T
replay-canvas.jssha384-NztRbNh/q9+8Zvrx9V8HZg10Rg5Pb0Zp2XwP2m4FT0NvVT0NpF3Ow670BxhJcLht
replay-canvas.min.jssha384-hBAM5YtyFdKDTHrdqMtipwj0MCC+/cfPWfop9gRH/3XlqrXZsCOtBGzKIius6U8F
replay.debug.min.jssha384-NE83TTCCt3J4QfHz8m8jgxqU3vgSVKeOm2im3d+E4FzsKWNoNTzketVzrUeEVwHG
replay.jssha384-4LN9vxS9wzpkHCWXrKZD8CIzIdHDF8LG1LMISIo/PmlrbV7c2OY4DoxblbHPTtIA
replay.min.jssha384-8UvxXXNn8nK1qe7Jc6pb8nzf8BU81lBEOWt2WGFpowXYKljspz3W/y9+LV19taeK
reportingobserver.debug.min.jssha384-StnfzNSPqDLzsvJXecf8l4/IUVX4+AV+nOg36D2negj1HiKNovCLe0owww/tsYvH
reportingobserver.jssha384-AHdlf6wAyThcuAbZ6t22esBER5OTIT4QtbSQOef/KVS4jDDJ8Cyx0Vy+v5ZPJ1Ix
reportingobserver.min.jssha384-0/LOzBBwWSaZf88iZgZEbkZfZ3exNsOusSFaLiy/+QsAkbGpg0unViPpfyZ+TsrE
rewriteframes.debug.min.jssha384-Uh9oEK5yJdBccrAsTX5aMHNE6uKKZaVSF4RSsqvHZ0zZ7B2dLivYQ6z4bggq0EIL
rewriteframes.jssha384-Brqx6+d/0NV6JHY/Yp7xah+mijgZFjQSNYQm2hiRT8QIOQuGbxEIkWMNCG5QewFH
rewriteframes.min.jssha384-q5CPbw1YRWnAnWpcQy1kJlaq4r4MGTkQQnzAq3maiK23dPvuxXwsYQz0XmMQV6oY
sessiontiming.debug.min.jssha384-Q4ajrQ8Imm7PYiC1IXLftn2IPNvKVGhSX649pc3xvgaSt/DsRX6aExDoDI0c/jLC
sessiontiming.jssha384-gzVZUc65YPOEQS8P/KLTqeS+RgDoGV3/b2cYac7XEdio3COUVPKkYSSp1aS2t+te
sessiontiming.min.jssha384-GdiSuI9X8+BIDDEtRwnMl0Gpe6yNdjh7SYLXVgi5rolV5CsV4EFDZsooRmV295RD

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