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.51.0/bundle.tracing.min.js"
  integrity="sha384-XIEWEzaAwD+xZJDyliHkEUG6EJEGwiEJJYGH7B8SstCI0Pa8pTYaGuUj3Rt/4yng"
  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.51.0/bundle.tracing.replay.min.js"
  integrity="sha384-DulooquW3C+xZEn0I3jpaZGefuX4TQSKK9QIIODQaijckMg2g8P+n7k4PS7pY75o"
  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.51.0/bundle.replay.min.js"
  integrity="sha384-8DbbLhN8VV3cCy3YkuYvFGVJx0SX/TeUiG8zok8PbiDaJGf1mKecEBkwwQ4TilS1"
  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.51.0/bundle.min.js"
  integrity="sha384-EOgbBjVzqFplh/e3H3VEqr1AOCKevEtcmi7r3DiQOFYc4iMJCx1/sX/sfka0Woi5"
  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, and for each version there are three bundle varieties: unminified, minified, and minified with debug logging. (That last version can be helpful for times when you need to debug an issue which only occurs in production. In a development environment, it makes most sense to use the unminified bundle, which always includes logging.)

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-/5dyYlYkRtqQlS1CE9WUL5hQOseGORWsKrYzUs1OhmFLv9O5zxS/wwjYe9d4P0xg
bundle.es5.debug.min.jssha384-xS85sib+lUf9q1ikSm7+ElSKBtOX2ooIIs8sm1AE78adid1zqMxktYmkbcSDdabv
bundle.es5.jssha384-s5Mus41B4zldnJwPAhHdJQLB93M3O8fK9bFr4Lo06+iIcG9zxvmS+yN1e4BqOiMj
bundle.es5.min.jssha384-0QdUX6SSfCTqJM6Cwv3+2XylpsryQZzqDSjVhWbKkpp6dKYTTere46jtQB36yoV5
bundle.jssha384-9ndCTIH/lKUlSXHpA864bu0MHYHfwL5I/zI/AlDwNkz9u+M6iXFN9yt3hNF651ZG
bundle.min.jssha384-EOgbBjVzqFplh/e3H3VEqr1AOCKevEtcmi7r3DiQOFYc4iMJCx1/sX/sfka0Woi5
bundle.replay.debug.min.jssha384-p4ZS9MgluEat34lIZjuhmSzreOTRqlI6XQuhswEC8kBTGsLHB+qOFLYpPfnHWG6H
bundle.replay.jssha384-cTSwqS0+ksnZQyFF/tqg3VzUe7BVAgc8t67mx6FUQTjwHioVBTERoFhkB2maWKQu
bundle.replay.min.jssha384-8DbbLhN8VV3cCy3YkuYvFGVJx0SX/TeUiG8zok8PbiDaJGf1mKecEBkwwQ4TilS1
bundle.tracing.debug.min.jssha384-auglHANicM+T6L1AMYtVsmQRWky1M1d543k8C/OOIRdaSUQsxKVYsGDPA4w/d3WP
bundle.tracing.es5.debug.min.jssha384-J8e/lYqWB+pSGBDI0tDVm6zdEz//FuBWorDTzorsWBPPWLnAAzlZArIVs2i5+Qdu
bundle.tracing.es5.jssha384-wh1mGfbfcub7d85R/18v8Twr7UHRzqEh5lemPsWN6wWHlRdXfDMQDhacq/46QwTd
bundle.tracing.es5.min.jssha384-yJhwO7xKoOaqO9Dh/dz7n4SbmMfbWye3XE5UdEawYbZqKq+c+6z6epQXwLvtwm9a
bundle.tracing.jssha384-77po+CHh3AaM1ilJPHfKRQJh4qljNrM2pEvWcImpoYZANhgVK1t3fA9Wa9uT5cZf
bundle.tracing.min.jssha384-XIEWEzaAwD+xZJDyliHkEUG6EJEGwiEJJYGH7B8SstCI0Pa8pTYaGuUj3Rt/4yng
bundle.tracing.replay.debug.min.jssha384-3qbaOZpOC27dua9pSh3RqMBaSqXZcg4nS9KMgR30aboYxLjsB+1zPdLFPqu+bba4
bundle.tracing.replay.jssha384-NNgLSE9oy4sKJgIx0h4V1NfCWdidhZrMaIQCkVcNT0fwawDX52BHMl7ooKJcwdTR
bundle.tracing.replay.min.jssha384-DulooquW3C+xZEn0I3jpaZGefuX4TQSKK9QIIODQaijckMg2g8P+n7k4PS7pY75o
captureconsole.debug.min.jssha384-lbbziNgDLey4rL9dzTiocSObhBvynmccEjog1VCT/dCb7tXlfPODY+vcblyVPY6m
captureconsole.es5.debug.min.jssha384-P7BqldWCYKcqMUTy0IOivKmo60DLnT0qb/wKInu1IVcEn0RXtP8j7za7veTN+0dY
captureconsole.es5.jssha384-jrFCbfheIwSCarR72R/9cFFgOim9U4o7nn5je38JUh4Y7IZJhTopDY9MaYUoz4Yc
captureconsole.es5.min.jssha384-4iGVYmng2sq3nI/7ztpkf2wANWEfIRYVTEOTnVrGcs3UlxlSlEqFnfItIZaBMz8e
captureconsole.jssha384-xRI6b3forgWsMWGz2A79L3FgsvgQu5ditRwt2SioLwXqAUpkQAKYQ9ics0DTT2Dp
captureconsole.min.jssha384-wnjVkHRZUz4ZdCjFFaFqsxX15reFCrGxyJZObl1PpDZwda49LpfaNQwQsjZIxX7c
debug.debug.min.jssha384-6FenyO790tazM49EmFE7xALSb/OVMoncbbaXXNrbSlpz0HIHvb0ap4BWIV6+Bs7B
debug.es5.debug.min.jssha384-iYLbsrA3f4yzWWEE0Eci6u/m+hfnQHvxb1dpAT015x8+YCUApcjybQWz4+QTmlz9
debug.es5.jssha384-keEdgrk0QtHTOTh8jRFLpy+3Uy4Ho2jzgt4x41VSOPpf0gDFAuLnpvJmT7zrVFdN
debug.es5.min.jssha384-EYSl90ewk0zxCJ0dYUrprsJBNLSdDO6xM3F+rcfBLoqoXr3aokQSLY4/y1gRnYs4
debug.jssha384-pWalznnBhnsMVq0KqFW+vAO8nPss16U1cKjO/iPZyfw7IWrE2z6+PzYrePEQvP6g
debug.min.jssha384-DOlJsPT6xJY0oThWlkC3FB6W1MwoSp6yujsfytaRzWweHOacOvcJskdRQ5Nddu42
dedupe.debug.min.jssha384-hwudUE6O+BvUaNDvmDHrKeCb1Wgr51CfvRy8ywuH2PGXF4IWeoeLedgiRFnxMzZS
dedupe.es5.debug.min.jssha384-C//mYQaQiJzcu/+3QloFbTLt5jel1H1jC6eka3PZuGZKw68nT4i4pzZ5kOsRYMit
dedupe.es5.jssha384-opMBrFP+rUtX8yuDn+hAGplmjF12uioeQeHd5JFxwUfOHqxtbzkWYE5Z5PXEq6y3
dedupe.es5.min.jssha384-/nkRBujd9MKlgyEPymSyqiG2BkXwfEsRfSGF/tEcCKbZahxjO3OvCqd1g1jgJnDa
dedupe.jssha384-ODYfrOELtk6tjjUd/2fCs2AbKpThvM8PRbo30ulk51qiHeckC4io73HNteLLQO7R
dedupe.min.jssha384-FjQv+JkBRYPW31OrZ4iizKGueiBZNem6IBh8Qilg0xIVCL5pPnGrJUnFMUYF0K4H
extraerrordata.debug.min.jssha384-AtifCdXyquvZUB7s+HGHtrc4zc4tP8bXur7aBRjnneuloXBjbp0g9j8teMynLZz1
extraerrordata.es5.debug.min.jssha384-QE3lwkqbyuT1CVnY9KZXxHW5RXsxH/IR8clDxHQeCf7Z5kUWOMEawhXIcsBJo+Sy
extraerrordata.es5.jssha384-MOxHSR4c0lrEiTcMb+MN/jqspJhB4V4qeNc/TislUBYjxvErWUU8VOXF06+xzpcn
extraerrordata.es5.min.jssha384-F7Rihiq5Z5Y+Ko46DnP9Rt48ancfP4Vab9Wfbwk4T4N/c0CgWJ/GVY3LyPV3ay4X
extraerrordata.jssha384-yEv/Fz2m6VrIFTB0CP/5bQYp4QgTGf1T7er8iIx62pwc/6AK2gM40qbBQjAXvSIj
extraerrordata.min.jssha384-fclwlZ3a3spndC1+e3RuKOFk9a6y1b1AW0Xo+kiWDY2ahOf74EB2bu8cmAEyBrts
httpclient.debug.min.jssha384-Id76UcPKQkrUkVKEAatrU7nET1hvzU2M/rF8IcgHjR3ug3rCiDwuEtFzC7Ho4YTt
httpclient.es5.debug.min.jssha384-PqP2VpFzdEZVXodQ2dpUUz9NN0dqrULKOI8GePjjtnpqGKp9s60VgofFbtsdf7Ug
httpclient.es5.jssha384-gT7Xz1vr872DhQmKrkF1D8ThgV+jnRIkyTFfVtmDbWOGyci1IV0jpk3amyF7VX6D
httpclient.es5.min.jssha384-1814PJa1JS2ZmGOTeMKWMon+FsKENagfnq6neMNsjEQkjp0owD56MAp7fHff0tz5
httpclient.jssha384-3OyolDGHSA97R91D5/mqRyIS5AhitDKwWZs4BLWmASFModbe6epro5Pux/Pbimkz
httpclient.min.jssha384-XjaIkLV29A9fJY1ZQ9AWpi+rSTPK5/XtDou7EKQZZDbWqL3Mq4vxEOiwPVbxVmhV
offline.debug.min.jssha384-CqoeNmu6LRGmkynnE0mup5KWe0hFnjXDGqW2a7v9eLaqJppY2sbjVS1SvYfUOsFH
offline.es5.debug.min.jssha384-StGRi6b4doFgmzXLQ0NDwKqBbmKUgPCQIypBL8SdP0c2PqIaOMxpfc434QWlMWb2
offline.es5.jssha384-U2quOBYmAafCODzkIw5ZefvUTRpNK0zW3TUmPiL//Mab3QrTIfdtfDWLxqIB2z9c
offline.es5.min.jssha384-EWp9D6+7+baW9fwApGDY19kOXdz3TNYh7nT9LjSy+4ofWx2OgCgFhlvdjQBa5+je
offline.jssha384-t1CwfnF+1MNOPTEDD2BD0cq9TZKWg24QvK/TAk445LYvwNXQQze+hZpAy/3+zQc6
offline.min.jssha384-ME5DGqTDnMtxofz9GZHgkP4ZLuamWfvLFPMIbTAP4tCCyNn94DvttyaQsgXTGtYO
replay.debug.min.jssha384-gHC0zSnSeiQ5J+D22rn9eLwtwDE3Wb4LWbRdEC7hVSxVOKzaCmfhDdY+tt7uKNap
replay.jssha384-TffY9TlS+AN9Xuv6MoBU/XQ/Cdhab0lSNqdQR538KZT11EqDP4R8I4mX8IblNs1z
replay.min.jssha384-0yNRo51htqTv8Ry+iObIgHZode8Sq9Rfk+Xev2J36wL7pXp7UjWDGSXhurWHpd4s
reportingobserver.debug.min.jssha384-ZI99C1m89WGriGCBn//AW/s2WiiWZljMsB819JQ5eaDJ+jXz78OFcBx4msIqqdSq
reportingobserver.es5.debug.min.jssha384-dOqftRGMfimNa8bZXZPyMvJx/l0lO39A0snHQB6DJvs3I2Su5VgTAwrShyKOSv7o
reportingobserver.es5.jssha384-UvRfxTV+Zxo2g/C9z83c7xOkw5z/eD7D4sXzo45cYpORS6rROqLi2TYcsoUpc2kB
reportingobserver.es5.min.jssha384-zmjcKf3lBXa1XPD87W0uMSVz56txq6/w6M3Fe5fCl8hLaCdsUuyjti9J08dkOI//
reportingobserver.jssha384-fXKaVZk589TI7Ap3kCawR4o1yjKfelB3y0YIT0a2DNAQRt+nyomw3g9Z730OVqCU
reportingobserver.min.jssha384-dhdFuAMCYWQLxXzMHyDktVKKBZ6XS/URuMzYkvjzncVujZ2zZm8UgfMW+WPENWk2
rewriteframes.debug.min.jssha384-UVBsayU8wKEypTYuwq7HucCY8GFU9Rh/BFnCedty2fXiBOo8TL6yr1qOTgkuFfIi
rewriteframes.es5.debug.min.jssha384-++7lHSYJhju9tka95kJLbc/tgVo7EopJS544/P1KvKCsN+LMZWZ4uUXV694sV8qi
rewriteframes.es5.jssha384-dTMz4Su8D0nvSVZYCO2GW4+CtTVJRRL52317YkVu+qAWysXbx+4iFvTY8xnBpqx/
rewriteframes.es5.min.jssha384-nSLFUnvEqTjQONMfgYakRys512hG7sp77H1NDFWNkPpZ25M9eBezdJvJ/5AAH77A
rewriteframes.jssha384-g8zqWydacs+7ffK4dNoaTdRWlFjSyS3ZEF0HAmN6vUckZmj7pkUxvuv4kaz/Xnf8
rewriteframes.min.jssha384-GCqgnoeWYFinzDOIZEFDmbQJMtK0RPiTWAW83IZWW3g0hsOCjWHoUtJ1GcfL1ppk
sessiontiming.debug.min.jssha384-euNgpmOj3aLjtlyO0jQlnfkjoh38IC3huphnltSEaA22wMnmqvRKMjZOr6gLBObJ
sessiontiming.es5.debug.min.jssha384-jaiPqMfDpGSm+S6J9nPkL2bU/P6jDUAqrChCbPOMghL3QMcQ+ELxMiHkUO5z6oY0
sessiontiming.es5.jssha384-qdK/725Y8i2bTCW4jelGAhvZgozDHIKZL2YDrsVoxBFw98uWGgKveZI1UyAcNTPV
sessiontiming.es5.min.jssha384-bj164CzlIl9M5WCU5AyMw85gKQlqHvmjSSPlllhYJwXLX8o7+M0dn0jJc9yOQw1f
sessiontiming.jssha384-+IUf2LG3YkV+/g4m3nH6mgNWlfCTGxkbN/yiZnNxzzMd3TINGQmAfmPvNUae4L5G
sessiontiming.min.jssha384-L4pBvHTNr18JW9tNxoSuRu4naYXxaRjGaThVv5NK7GXJtvkpYGHwMfoXt4O8glCm
transaction.debug.min.jssha384-M1Zz7cR2727cU33HU2Dq1PbDxbMIJcVgkFlsRAzh6vD9lQaQ7GDJ8jpFcn7Lfvt5
transaction.es5.debug.min.jssha384-ZnxkU9wzVsauqudqAo5YJbmYxdG9t5DJnmqt31A0BvcCdpMfVkO5JKOMdeBZHglb
transaction.es5.jssha384-vkaP/snJ6dvguNiMkJxpMCasj4afNyxoGt+tqQlBfldCCervpRBsoSTn3eNBHs14
transaction.es5.min.jssha384-ojkPYmft0Doof7yCl+VRjTK66DH+BQQ9LVcO86EaXIXLNOMDDQh8Zi5st3XxvND0
transaction.jssha384-7tsL4esX6V2rPtRvq/o3EJFycabVNwrA4hKEXdOgblGBN3OHlEEVOncJX/SYsTTn
transaction.min.jssha384-2V+hWvv+/Gu0HzmzBZWgYTHHnq45cdLKF9fdVN4nLfdFr8e8umtu2ThDg3JVYB0h

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