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.

Using the Loader

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, Performance Monitoring and Session Replay is enabled.

Source Maps

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

Loader Configuration

The loader has a few configuration options:

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

SDK Version

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.

Load Timing

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 Performance Monitoring 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.

SDK Configuration

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'll need a second script tag, in which you'll call Sentry.onLoad. This script must come after the main loader script.

Copied
<script
  src="https://js.sentry-cdn.com/examplePublicKey.min.js"
  crossorigin="anonymous"
></script>
<script>
  Sentry.onLoad(function() { ... });
</script>

Sentry.onLoad is a function that only the loader provides, and - as the name suggests - it sets a function to be run once the full SDK has been loaded. In that function, you can configure your SDK exactly the way you would were you using the CDN, with one difference: your Sentry.init call doesn't need to include your DSN, since it's already been set.

Copied
<script>
  Sentry.onLoad(function() {
    Sentry.init({
      release: " ... ",
      environment: " ... "
    });
    Sentry.configureScope(scope => {
      scope.setTag( ... );
    });
    // etc.
  });
</script>

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

For Session Replay, the defaults are set to 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.

Limitations of error-only capturing

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.

CDN

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.

Default Bundle

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

Copied
<script
  src="https://browser.sentry-cdn.com/7.52.1/bundle.tracing.min.js"
  integrity="sha384-muuFXKS3752PNA4rPm9Uq6BLvOfV4CXyr9MHDBPvozOJJUWLKkogEFWOIRoVps43"
  crossorigin="anonymous"
></script>

Performance & Replay Bundle

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

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

Errors & Replay Bundle

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

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

Errors-only Bundle

If you only use Sentry for error monitoring, and don't need performance

tracingThe process of logging the events that took place during a request, often across multiple services.
or replay functionality, you can use the following bundle:

Copied
<script
  src="https://browser.sentry-cdn.com/7.52.1/bundle.min.js"
  integrity="sha384-SIBkgMrWpSupYecG1cwv4ikmRELrt0F1+YjTu9KGe+iNfI33btEd5twUdaOjR9zY"
  crossorigin="anonymous"
></script>

Usage & Configuration

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: [new Sentry.BrowserTracing()],

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

Available Bundles

Our CDN hosts a variety of bundles:

  • @sentry/browser with error monitoring only (named bundle.<modifiers>.js)
  • @sentry/browser with error and performance monitoring (named bundle.tracing.<modifiers>.js)
  • @sentry/browser with error and session replay (named bundle.replay.<modifiers>.js)
  • @sentry/browser with error, performance monitoring 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 performance monitoring enabled, compiled to ES5 and minified, with debug logging included
FileIntegrity Checksum
bundle.debug.min.jssha384-fH2mmec4RbhUTj8w849skUr60ZfBjUo/KcT+5mh4sC0KGGnqST8yNg0Syh1QUUEz
bundle.es5.debug.min.jssha384-LpBdhngDcCDWv2redhtdzueO3Dk8wH7FHd/qQ2ebSwdUxEkZXnAV+v8wHIrvDgpx
bundle.es5.jssha384-N/Cp6OIAehUB3Z9HFR8/Bfu36yy+6/5JQ6vbNloVLusYXjhIF6OtZxV7Vuo4pBoP
bundle.es5.min.jssha384-rseUUzFhgCJDN5GsqmcKmKSn1Q4CotVH6z3aPDmoGiefICU4Cd9pBWbYgvFFvwF9
bundle.jssha384-GgVtNvCcXsjh9l5vgiaxxGOtSduvHQOCreAkINcl1t3hINGRWCRxTjc9rctavv/D
bundle.min.jssha384-SIBkgMrWpSupYecG1cwv4ikmRELrt0F1+YjTu9KGe+iNfI33btEd5twUdaOjR9zY
bundle.replay.debug.min.jssha384-JziEyxyFNobuzhJ75esyrOeuJS/vHKD/3XzZGiiWm5Ts949CvU2AAZZRxSwSlsv6
bundle.replay.jssha384-Sfi8eKxZmSE5zsky6m2q/7h456WcvhtNx2b/dFnf7P6rIvsbZYF2vZrclFutG2xb
bundle.replay.min.jssha384-nm7VsnYcHLSpFP9vgP3/WzOm999jvt5v7Xh1HTy3z4qIz1QAdOYONzMuMOcXIJsG
bundle.tracing.debug.min.jssha384-FEDFOZ+fKo8yL7Rkh8kSiyQieJ9OgoiOngRk3OQJP4TCHbpnsglB3UWMCIxZpwKA
bundle.tracing.es5.debug.min.jssha384-0QGCUcrgTPFoWxLXdVlCNEbT6cZdE+NMKook4jvcIjuVTUJTSPtSzUl0arE0rWjE
bundle.tracing.es5.jssha384-0QkeBJcbSnfAe3rD3d8q87j6coHHAXJq4l4uEpfMj5tOHVf9d+5zWWzfkvkWMs+o
bundle.tracing.es5.min.jssha384-OhrYxCaFsoYaAU6CvO78DmdL6U7Ye22QBheazzeYEVGUDPvIIFCQptOnyINvxhEo
bundle.tracing.jssha384-iM1D0lOb+TPv9yNBh4C+SvQgrscYtz6L3K0rNJOXvQm/lXlY5yEBbGTuolDrX+Vy
bundle.tracing.min.jssha384-muuFXKS3752PNA4rPm9Uq6BLvOfV4CXyr9MHDBPvozOJJUWLKkogEFWOIRoVps43
bundle.tracing.replay.debug.min.jssha384-GJSQB3xOwsmiqsaGLZ5nq1kyBDP4ipwOHmM0UjAakdJhwRs77SADz4Ho9BRdI+JD
bundle.tracing.replay.jssha384-Lma/BE6WigbBpFv5LtWEnGCF+pmYFckn19/t96c404rNhw0Ki1Hb9ChuUiWiuoNy
bundle.tracing.replay.min.jssha384-YgiClEn7Yex1oOo3VtORwt20J7gCMKhYLSHAcBU8wYyZY8rIZ/YtaRxrwL5tWL0Y
captureconsole.debug.min.jssha384-DxdEwje1VWX2nbD2oNzYf9ve2Ca8BrzxhbpvHwMLierD5IKndK5FdDlE8qz0NwLu
captureconsole.es5.debug.min.jssha384-lR1Wm+4mf+hKT3v9gl9bs1wsKeOKwqA7Bj1c50Sztq60EIbhW1owIyGE5NQO3r2Z
captureconsole.es5.jssha384-5g48tPUs7xLuk47AsOfSOLGY6MCBFnQkyxFAqrodE36ljodd3AOQa/H7CTphZJLt
captureconsole.es5.min.jssha384-neuVi0XkciSVrV+daVdpLGdPUBWEmgfyrObOrehHXxBONz0lNdv1nORnrxpu4Lkj
captureconsole.jssha384-kWW1NZHS+Mwr/roPg9uMBk8fvpmAvomn54N/kchsjO+qBbx0r51du5ZnSi3+HSOl
captureconsole.min.jssha384-ve0IwiexMahsk7sfwRmxtfZ7yHvu+2Wk6u1rswwiS+6zzKPBo8akCubz2W2LjsT8
debug.debug.min.jssha384-CmlvbfZlxbhIcc0h5fEzEGzSiMNRNXN+eAwX4CMXG8iMNcQJUHkkGFEd9EkrUIoL
debug.es5.debug.min.jssha384-kVTuglmzhgOF4ZFe/g7eFx7mZbfIABeNuqHWIO5pLZ5d2wQfeMGFgltUYwFuS2fX
debug.es5.jssha384-W521IAuAZtMyvuMZAYtMUuk08916CVsCMx1le0tXZDEuJwdFqabS2q16aEJBEpQb
debug.es5.min.jssha384-yMvxoWnAeGt4fV+dtFPM2IO+sctKg6DanUvMli4YjuZaheXM2SCvqauJcsrHyTpS
debug.jssha384-wKyCLEi3KqbqX24LA3rU8DIVS+1cLFlwCbIGA7cjnsqMqClZ3mKCrpIdtsQtYl8z
debug.min.jssha384-K+dEllaF7j0NkNwetNEkND1OYAhz0xFPDyoV7dYWhQhPgF3U5roAn5INdyKmWNjZ
dedupe.debug.min.jssha384-hXV5nB5whz3yGlelNWay1VOplBYUAjhdB8j325MsDoVWMldmSFsyJpDAmG4tohZ6
dedupe.es5.debug.min.jssha384-SuFtnBC3NnxLLKDPEoTaz3RpZzSgD0B2BT4JMzYMg0/c4bCH70ROOqRQ1J1wVRU2
dedupe.es5.jssha384-lpNEr6Q9+zXVnlODr7Yfxfwpp+/TRzR4VOOGlyRu2h3K4WfHTZJWwkpM4ujMFLk7
dedupe.es5.min.jssha384-K4M3qqfR09U/o2UOV9gmikkUzjerat9LZQd9OuvC/tuYqyWw0DZk5aqCR5AWutT2
dedupe.jssha384-cUbcnKEdLXpWT7hJGbJ+sgbb6IKmoY+3oYfmghsRfaHJT9lBlztge1zM6JQNSI6p
dedupe.min.jssha384-DSvGS9vH8kncgWfrw9l7ym8n1hifseH7/xIlAuisl5NNyh6n27QZ1zs9iImW5qHp
extraerrordata.debug.min.jssha384-SaFmlxXjAdVbrYF7sTV16Aj8Pyt0MS8ah+//92n1VBsIa/riGbgqS36igX5AeBAQ
extraerrordata.es5.debug.min.jssha384-7O3SeW1AgQN7prOO3tMyhUIQEupDdxhtDNb+Hjdq3504PRw1/iManKHm3aVsV/0J
extraerrordata.es5.jssha384-opUFb/AxpueG6JI/eOB5QhJud5A/pp1X/OP/lLFXgsgaUjKOuOGf65zfHxSuQyPY
extraerrordata.es5.min.jssha384-ZPVTFWIx7HUq8cDsVLpycm10BpBTXE+e7dqweUE3/+tSXrsvolzvP0vygajReaAh
extraerrordata.jssha384-HdMyR8zw5l/wBCmCavlPFxj4xYapDSg64DRA7vhHlXF5R4zPMlL2ymT9EgeWJtGW
extraerrordata.min.jssha384-QSxN+vex8Qsro0O9xJ6e58Vqiv8sG+A03YoeiiVTwcC8QFL/XBQRgYF1Jn84ZG4e
httpclient.debug.min.jssha384-saTMozIq/GvUH+xSMaDrKXqf7b/QrXeGpQmn5HUuynReu7Mz/qNmRJl+kZCNmsP2
httpclient.es5.debug.min.jssha384-VWQSalwxq8cuWAvxjPzXDwWsB9qVdbIG4Fkk0UGWrPbvE3pMzkdgPmgGjp9Yx4zx
httpclient.es5.jssha384-IXdC19uVObyUW+WPzCgnB3gvOIugTxM4ijud8qOzvQF8d6rh0QqLaSAYfgyx4qNx
httpclient.es5.min.jssha384-h9PCGVrPoApiyo98zu5M/E/1KCXp31zVzy3sia7qh1Ty9r83DY7I+N1cIuse4ZT+
httpclient.jssha384-tMFr1ou0BfsUlaOe+Yyj/aYU2xwAFehoQPSkfq0tf1eLHjW0A6khPND/MNY/vgss
httpclient.min.jssha384-3J6ZflGbJ6A0qHyLqXC/y+VnIRL0qg2ZRBCpqfdtYkSluiUa7Z/IEdwaQmUuMtR4
offline.debug.min.jssha384-fMGdfZeZbcMKnwmOxWmkOo9/WE3B5qp9d+SyPmdQzQVRlFM6nxrQp0TOxfikFF5L
offline.es5.debug.min.jssha384-ioPQrrw1wbzU59nRzZgHzEfukoQOeKeitt3lbOtRoJ8YQC4dJbJ11BYnY4MHz9kH
offline.es5.jssha384-LvA6N/vV5TTJoOhgWGQuwp0LZCoG063GLdVQX6jEtgscfUl/yPpK7rMUqfiwq9Cy
offline.es5.min.jssha384-NwxEVkpjXYrXJhlRZSlHO4fYndpmy2fmIrZh5uJhSD+bJfjVlfnhAaLarYkagKSh
offline.jssha384-nz8preKqrJzPWENdf9D+dZLZ2zGsg2w3cWlJUXo9+lcgbynKHrVrmN85e1cux3ox
offline.min.jssha384-7OYyq+FHwvEQSgVFPyMzYdBdr0r8oGkYF0D11gM8WYnHlgE1HXVH1v/Zci5hL3KG
replay.debug.min.jssha384-386USEIqBFPvoUUEl6bcNx04JveRD3n/oZbdvmG0ZIY9mgx/LmoAv2tPIhm8fVP6
replay.jssha384-A3c7QwoI+CYGnfKMYxfDwXVSfIupC3SHwMxLKS1/zWfJuo8JrgWAvAO8JLYvsV1i
replay.min.jssha384-FfOjN+0YNemEQnDx2cVd4aIbF3G080hfMqMK7terKxVX3Rwq8/MfRzIvNf60a2WU
reportingobserver.debug.min.jssha384-MItcphEwFBwzQvat1pwGRk0KPpppUVWIdOk+IA9U/49y4A10WR11M+OPWhJqttIy
reportingobserver.es5.debug.min.jssha384-FYOxoOyBpoF3S+ZSkHavk1cWewkysG9tO4MVpTav7lItqtSOr26Grfr4yU5JrypP
reportingobserver.es5.jssha384-/umOrGua/c5fU+bizFOoqc6Pp/4tZj5rAzKz9fUAm7e8NK9bOb8wqIwlyc0virSL
reportingobserver.es5.min.jssha384-4RYQLIpmAYZmi6lGYzS5uywLQmVt8buajVuv0E/51q6/pc4wlbHFiiWI29UoSZtf
reportingobserver.jssha384-fNVRfbAaLxLdiygEuR0RYl1IYuQJPM9UGpUdL0dtaNSPX+TVKktCuO9GgDJd8KHP
reportingobserver.min.jssha384-wpJ0dcyylLh0Ikki8f/fMtnBQeLY8alxsnMPIEmvCwsU34ZHD26d3fgH+Xz7eA06
rewriteframes.debug.min.jssha384-+5M8U9AcJ3/Tgo9MasstGwFxB0HtG9Dw13Od0jAvlNr4cQ2bKtIXxGWTP1u0uSTD
rewriteframes.es5.debug.min.jssha384-ZAHqNINdIr7CFom+Cg97lpN/7IDiNLMMDuaAtL/Vl0U1rRnOQosRrieAnoclulP/
rewriteframes.es5.jssha384-EcLoSA3va88xR+zgEKRId+PgWam/FiSOI0r0VLjuHmNHBZ9T3tFR6PRLA0OYII/Q
rewriteframes.es5.min.jssha384-/rQw5flGEQrdAe+pAl3HMj+FZncplGJxB97m0MZJePw/oZ5xQ52+CMEAOzdZDxcw
rewriteframes.jssha384-6Tm+XHszd1DDhEq4w+CQud57yfUsz8zCzjHHQo0ixJWLEk/ECM2/lHefsWKK5Osz
rewriteframes.min.jssha384-UCe8UM3s5KhO//EwB8U44FARPgwcMOZgq2AR8S5pPpSwn3MuO2yfQ/3Y/4tzr8R5
sessiontiming.debug.min.jssha384-s4Fuu40XAwnwMKLiEf3TtAPzJ9DZfFnFWCCJmXRhzQMbf1ZFpQviSpIarZzwXqDA
sessiontiming.es5.debug.min.jssha384-ehH5yCyOmMdIgnP3XEMuZQo0TbBBCKXeoGScO+A/rj3+Hw8yy0tUuKUGEXbTfDZa
sessiontiming.es5.jssha384-XUnwPyfLJXonvhWTD/d4jBDknY9AF4oL1A0MBeH980AfcEIgdk4Jq3Xq5h7BYhjO
sessiontiming.es5.min.jssha384-U0kxRHnlpKTuJeLA3Eb+03H65bNdOElRbXOE5A0lXNpARcVzfb594qwt22jaCvXX
sessiontiming.jssha384-vKL4WtASDha6mGnK6jFP95qij9ewP+Ov4c63PfDVInzp3yXHkRlWFnpekqUZNZQ6
sessiontiming.min.jssha384-Sc46myVXjgOyM2mp29Gv2ZijW9faBdKunrIrJGdZk+hZj+tdOU8WGJArSoHpRIZQ
transaction.debug.min.jssha384-kyiVVvBSIp41TBoSkhOKmF4zgf9oNYCzhALtwoEYnj7asBEvweqDX5vnuhotC6Ms
transaction.es5.debug.min.jssha384-mJq5DAAsyDb46fEDW92yfvHYXO+S8itVwQ2fEylanPjgoYT0tjQr0Q2hc1ITs4Mb
transaction.es5.jssha384-Pk3Zr5ajHuEK7Ep+5e6wk2yl9dZpCJlRGbPAoesJMYQ6YBlkFJK/khEt7I+Dk8KI
transaction.es5.min.jssha384-JInzbs56oeluopdZoRX8+KG5EUxbvu8AocFB25rYnUQuJ5yxcgpzBLFsQakYis3s
transaction.jssha384-jekPewCMCybLY0zEPwNQj/uD+uXgB4BMZeGD95P+UEPqztXZT/GV0nqxsq+sj211
transaction.min.jssha384-T/0cyIOTlOGwzZlRL1sBlk0yU6qcwsfPvtJ/f/ggIm5ZoTykUKN/luneWRS54ux0

Additional Configuration

Using defer

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.

Content Security Policy

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!) to suggesting an update ("yeah, this would be better").