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.10.1/bundle.tracing.min.js"
  integrity="sha384-JMBa2dSUFXDZ4Z6mvNuyQ7Ew6BjsdclydsUnfnBT8BqG7wSXC5QtMUZEBOKDfTUu"
  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.10.1/bundle.tracing.replay.min.js"
  integrity="sha384-6fVUAtzHt8FBF5jJphCf2e9HYPwKwl9l6OhuP3RGMELplwuUwgO2bKVpLDd28wbb"
  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.10.1/bundle.replay.min.js"
  integrity="sha384-ruFZ3TAayxXYJ/S+yl8u/f51J0wBzgdTlkCXQsCKjhLlnjt8yEhBz/lwXxWV5PDP"
  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.10.1/bundle.min.js"
  integrity="sha384-u3VMvTEMJpbTLbBm+pNrTlAAKUYsVC8kDW6C6bzwCDYeUUmlzGNWXUfWSxwASPz0"
  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-Scek2NI2wzGjkDdF0dSbCTHLA6kEySN3cSrPhgFQs2L6/M+7cL++5pxGOsFmwOQW
browserprofiling.jssha384-0OucPyFLeOc5OGKEeeIrY9WF/eURchGXvWj2aDQ7I8za5W2XeYDDfl7IEbU9j0BP
browserprofiling.min.jssha384-ie8CrpCF4lqu78QIRMG0OWf9luAfMsxGGBffTyFZVTW1/EKojx47wO66dQnP83yb
bundle.debug.min.jssha384-J2DwvS15rwB8CjqjZpQ4CqOur2pmWPRpIQNV/elvuj72V/COx4MYSQ0P2UOq+XfP
bundle.feedback.debug.min.jssha384-VjNalfrGX3wF+A3EOfzApPodtm4sNyjXwy6hxVL4AXpiYWmcSX0HevNIkM2kaqxs
bundle.feedback.jssha384-MQaHFyOr/cD1Wa+MtxHoI9/lZYQGBLvbMC/esAdjOnK4ThybVU0l7MmuIzqlBsjl
bundle.feedback.min.jssha384-b4ilEw4+yXCzz63ZFJDrT4FqnTLDno7SSUCMYnpFijUs3sZ937RYGQ0zY96UPMx6
bundle.jssha384-XxpAo+dSGsxAvI4qCoqXbTAqrnRrqixzdSAQ5hrghD/H4GEKKzeQoP0spVkOuapX
bundle.min.jssha384-u3VMvTEMJpbTLbBm+pNrTlAAKUYsVC8kDW6C6bzwCDYeUUmlzGNWXUfWSxwASPz0
bundle.replay.debug.min.jssha384-xd1XgZq+icsgwAQdCp0NktaS2+mVOcqQXtvKQQ9ukYTUfW+W9SlTvRpoF68NDo6K
bundle.replay.jssha384-eXwVA25TtIhpTxb92kfciV3K1ihoO2/DwT4fmEOPYE1cytc7F/agwJhnhXNr2WR9
bundle.replay.min.jssha384-ruFZ3TAayxXYJ/S+yl8u/f51J0wBzgdTlkCXQsCKjhLlnjt8yEhBz/lwXxWV5PDP
bundle.tracing.debug.min.jssha384-B+ZjsnYlnfqsqbwIklKDmL5szjRuuANeYSLRhakxALNiUAQ4xVUyOGFwDtyFQ3kQ
bundle.tracing.jssha384-F+csNLksNiehEB+ZkisRSiZnGAcKYckBQfD4+tUJH7d6qwPWGtqdxKjfghqdcje6
bundle.tracing.min.jssha384-JMBa2dSUFXDZ4Z6mvNuyQ7Ew6BjsdclydsUnfnBT8BqG7wSXC5QtMUZEBOKDfTUu
bundle.tracing.replay.debug.min.jssha384-OB5TfcWtNY2UGKBeMdYwVBmRfoeczM29x4ZmKnL9SNc9x/eVz1AbW8YWI4q/5oOA
bundle.tracing.replay.feedback.debug.min.jssha384-Mc7ZobpMUn7XeEaa0p8jmkeuz7KX09T7Vb7qNeIK5ANV8tRpTsyw0xaZCwxfEMRJ
bundle.tracing.replay.feedback.jssha384-52eogrOBWofZB27jgPSDFSJyiiMYf1yQXACI0O4eLTPl66ZmKJ7anoObmoFUjdjH
bundle.tracing.replay.feedback.min.jssha384-uYCBeRgk8sjP+rPZYUwIS9VZ6AK8wyOvkk2pSu+xWMFtCpFfbmHM09At+YOj5EK3
bundle.tracing.replay.jssha384-K4czCW/BlsKvajeuStDHmqCbcEvBTKQ4otC9Kv955CW2+E0PJe6PCzc8Gr+Eu6vb
bundle.tracing.replay.min.jssha384-6fVUAtzHt8FBF5jJphCf2e9HYPwKwl9l6OhuP3RGMELplwuUwgO2bKVpLDd28wbb
captureconsole.debug.min.jssha384-C6X+pAfmwzWDtXBEj5ZizQJUEOn4QO6c/xqMDMs5MRlj0v9TcND8GlaUUpKhVlw2
captureconsole.jssha384-D4k6ehHhc+NAhXbWFgRPZ/SJovhD3fuk6nUpNXJyQAy1LfJpL22bAhGYCnMDy399
captureconsole.min.jssha384-Zq0LIg7GiUpcv7IY6y2EmzuUKIEP7ENHDmuRcaiIGNVpoXm9CUGyyHRXsLjii2xF
contextlines.debug.min.jssha384-jfEgJ2UhC+IJFOCmuf7BW9l1ZBLYn/ole96lx5JezbSu5dPs0prz0z/Uxyx0/8xD
contextlines.jssha384-+pFK4A2osfKEY80SpO1WKRcHZ+M4/HoNJyPEKhI1NlCcXP3CMYUEf+eU+c265S27
contextlines.min.jssha384-8AQk9nQ58HRLb5Gz5Uz9K67w8H5DEuUfmtWu8nn6QaFku7819Q3ejPQnmprEaf0/
dedupe.debug.min.jssha384-MCqgyjIwVaq2eHwTHNHYAZb2RwXKuWSPYLTBA/KUTTY0sr4/hSMgjiRuF2DwW23M
dedupe.jssha384-cbfxKhHxCeK54Zvq8XRtFCPV+IuYtz/Gs52/D9TIM24LaBX5MSFSmCTKmuR7P4y1
dedupe.min.jssha384-+oCeVXYY91p3B2L9g4OefIy62L19C4q3F+opdEerHsFFrlT6F8cHe/1nopllSVli
extraerrordata.debug.min.jssha384-mLxFN0n7eL4Yy50jnbu3ftRXH9/BWrlrPjk/0Z/G5uumZhdAPEFtpBVlc9pN5WcB
extraerrordata.jssha384-UuDcgVdQXZ4zpIJ5lihX6zKCA8y66AJPd3IfPmMzS59baIqEhJ3H1luO5/mWhhNo
extraerrordata.min.jssha384-61ArbzG/KfVnNDH701oGaTAIsZzEI9SfPXY3hKCQ/D2g9IW3Y5RkcUV6lWBdbobm
feedback-modal.debug.min.jssha384-b1eCl+/+DGWaqjMxFPIbQv1fpNZxSp7IsSJZIwzfQbiMV4UT88guRgzpwisWZuYR
feedback-modal.jssha384-xvkkhjv4teAyk/0YNCluo77uCSIyB57dqQNNCKvthdfSgGGrX3lSvU08z4DudQkb
feedback-modal.min.jssha384-Jafy6gXgvEaLyLAjk94gyB+ZfLv7n9hDKXeMk/khO9rGhyKUm/JPDmymQ7nYIEqZ
feedback-screenshot.debug.min.jssha384-JLaAMTIYDrFYsIEF6dW0Yydq7S0XRPLOkohgjInvg1sMyxxdjfuQZvSN/4hWw0q/
feedback-screenshot.jssha384-v+MW6fNX+dlXMLU6rHjD+uuOtUdJ5Vcr8ZeiZrAuDSg3oPVTptubBDpmtKa90VyS
feedback-screenshot.min.jssha384-2kUw/0Scs3YZoO9r9ZB9Slchk79vpgKEcc5Tk6J3RYpiqkvKznxuD+wmizwHAKZX
feedback.debug.min.jssha384-bCJbDfoDmhWlyCGRQFbUoKH7IsYxoVedE0Vel1ESzMN9cs/1ANDnc9C+ar2hcsbQ
feedback.jssha384-70XPuc8CiDHZ0KTbOtkLdpzInEcEvEhRn0rMTDrVcZz0dVcnfnUfofQy1VgqTpgq
feedback.min.jssha384-N+Y5FIHi5FhE9E9DbBTSKdGSKo7WIcZEljtIk0Fke1r6ok42w9a+niiP8qq+PRsG
graphqlclient.debug.min.jssha384-babi80vtiwS7LzuDStRFjwyMbQk8NiNliebxzBnOXZ7FmEsyxmk6DNUVQBR84gMw
graphqlclient.jssha384-R9aKJ5XgwK8j+NJkI8dKNMIoOtCxlxbAaCZ7xWII87/mkiEwFypxIuKxNuzmXr7Z
graphqlclient.min.jssha384-xcA8ZajJ8In2G82izD1eLLCplhyu20kBSjx5HEVn1Hw3b2QNwCoDQ2Fd2p5pemnV
httpclient.debug.min.jssha384-3GyjMGV621ej2x5KFy6f8f0opdq8uJoTG0QvvRZBzrhu/UwtIur7OhC35abOJYQ8
httpclient.jssha384-Rv6HiblBtu/ppF7QU0d2ktnXscxj9qwsVh5zstl9MKgvQ1W3YVb1AKbqp6RddvBy
httpclient.min.jssha384-Y8OkTai0G0sNBXH9EkH2RU47i54KkCPyJNSIgcuPAXCwYhXuWaz4OhjgCzPjI3n1
modulemetadata.debug.min.jssha384-bTlUrR/8oBc6Hkl8z+dKl4s1t1DcY3frrwZg+H7Bi/djDwrT0pvScsTdENmj4+Q1
modulemetadata.jssha384-/w7aowKfNcPQLwQQsfSYI/Ek8Ll1N79H8cxvUW/58qofIqZ6XrdhcUgWWs9UUoCz
modulemetadata.min.jssha384-gZUnqtZOEZqbHzZivz1MH9PAtnI292sBWff4g6RW4szFhGn6zvsklp4VcPqvxzOM
multiplexedtransport.debug.min.jssha384-QUlpFqeeUz6MIK1qOVFYRwkHRS4x3xnZA7LS9qlhDoqbYjRt+/JRR1KeHuetUSi5
multiplexedtransport.jssha384-DD8klazBt+j6k++WW9n88oUJ7CwRyHwsaw9oK9DevHs4r2/WOahKlanjy+H03lj0
multiplexedtransport.min.jssha384-i9uFLZq7xIPP8GskJxejboaNXY0GBXoLNYwh4u79fQSpbdrUaGChIFf1zcYK1omy
replay-canvas.debug.min.jssha384-9vB1mrY/9b7eIyhhqu0hSMayjeHeLBiW1ymdzRCq3H5HMvMlF2PHLzoBEI1AP5C9
replay-canvas.jssha384-tSfn+cdo1K0czc5LNrk50MiR1rf8wn2LY7A1shkleJXJ9pWwMTzokRPVlUS0Pg6V
replay-canvas.min.jssha384-K6DouB3WK8+NMpHaYq7w4kInnVIyl+7cugDD5EIhmzTi2hULvr6GJ0iZvS7oOu8k
replay.debug.min.jssha384-B4FJUH3vqySQt12scd+5Mqm1/UluFmewjZ76ruK5hISs9WmxSCJVPx8O3rRTyPII
replay.jssha384-y46HrMWwc+ukagi5TiIA3EtZXc3K3wDN0em0lM3gXu1U2KjmVRRzbCJgaNZ0RCHl
replay.min.jssha384-48X9x6gwLjLsEBDXOlVbnrrHE/lAtlAerr5LZS1btxkTfxrdYTK6yWyZmwEQyApB
reportingobserver.debug.min.jssha384-vOTMH/plTp14f1XUS9bTNquYbaunnT41z1MlpP9uCwcgj+W5Qs0iHreZ6g9EcNGJ
reportingobserver.jssha384-u4Epp8Bey/UJhLLi9F6Azwt0j43GTWjkjQHtE5S152JmVNFh11QZVv5xAjphKySf
reportingobserver.min.jssha384-ZOUxiy3g1bRdqeEX0FQLo4gnyIkqyNY3Sd04QNAhspM/yvi0BtVCiRlOIVnF9jUV
rewriteframes.debug.min.jssha384-d1G5oCsKjohQsoa/P2hX65wJAbTP6xy5ZkCQudk5YHlRBlbKKDcAKQKwlds5oMDo
rewriteframes.jssha384-dHagGlV31BVRm7fw97DvffR40JVFjWF+ipG6yO17Dz7U73nb8+FxZ2BPozOGTpUE
rewriteframes.min.jssha384-1XKOT2lNoaSv59Ym4TWiSegHfItJJ/oGdjVdt48uQ4f3BKN8cXi9ktbnwbN73+v2
spotlight.debug.min.jssha384-xCpRbH51Qvm2uI6fZGbBep22film1x6UbG62cPhqaYAaptP3GpNhrjrqEM4Zysc5
spotlight.jssha384-GdCGOjmqeXjkuic1KRD0GNgiPMYmLBk2vMVZLi1xMWsHUxFQNl1OUr4CxlNho0RE
spotlight.min.jssha384-aLBRrAThSUpAga7XtcKda2DhzVQi+HXliwRrrSM2RKw/N7MADWmpWAak3t/W+E62

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