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.18.0/bundle.tracing.min.js"
  integrity="sha384-oCdDUQ/+Aj0VJ9fi4jeZTENsQ35fqB7UuVtGKNxY6Q+eI25KAXKVab5ulE3IygL4"
  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.18.0/bundle.tracing.replay.min.js"
  integrity="sha384-iZi3E4k4iT0C1fBrlJJGnCFCKiE/zZNcS7BHeMPcz2smbXO4aGy21u1ydpedPOem"
  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.18.0/bundle.replay.min.js"
  integrity="sha384-gRDJAYYebCVmiY1Ew6s/YYHtzAVR8dx3Y3wzW2A0l2CdbucfpVVcjE+eIgEiavMy"
  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.18.0/bundle.min.js"
  integrity="sha384-+q1lbsdglIESjnGfX7P1JBjtuDSe6G+R74U6bW5qbb1Sy2ySJ6qZ9Yx4xGB8MXBI"
  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-qKGTGIRIhn96JTN1H7vmbGrHc6tN5RK9xzaBkxaQg+YOAfyYY41pY6rkW+0XgM5z
browserprofiling.jssha384-1yHSe+gdjXg5B5naCJcsztkDYIdB7WKiJWIKZ7LJMTDMbDUubz9nE31byakrvX5S
browserprofiling.min.jssha384-aDu1kQRNv4ea8fBL00Gqq0drOEfyvCuQLctQn4aP7GYxJ0XKqZsr2As4qKeNYTvj
bundle.debug.min.jssha384-s5R9S0nqrTGyn//tkwSMGw+16nL07+tMtw3glk9cFzqtaL75ne7u6jPmmyULa6La
bundle.feedback.debug.min.jssha384-a5LrygAdfT5B0T4qm3nTVSL7DXSPRczD+8Zw450zRWzpn5CMXndHY7d0x/4CetLR
bundle.feedback.jssha384-x+XtmBIVxDbrjH9y9NI58SGzn5O9JGhnllZHInpgkWPkZmY9O/sijr82RJaPruj6
bundle.feedback.min.jssha384-LUpcjU2iI1Za4D3ucwmrCiprPDwK35SSkqJ93fOIM8qXpMHV4pNirRJSXjHaGAHE
bundle.jssha384-6fAMUivnB20EQO5sXq0N3OzCJsYuBU8Agc6ANQEgIpqUyTkQ20kp/xMUKdUv9MSd
bundle.min.jssha384-+q1lbsdglIESjnGfX7P1JBjtuDSe6G+R74U6bW5qbb1Sy2ySJ6qZ9Yx4xGB8MXBI
bundle.replay.debug.min.jssha384-Nb4cILRnHmSGTapw5sZAXeEZLnGLiHlCbMHhmv9b+6Bp8z8ZAt8nNKZH5Rm69qIA
bundle.replay.jssha384-RWtiemJS1sUUQyo95DLvJJ4XzoJWDDEIPZvhKDKKjfjvd1Gm6o9zNmFDUnzrlvnD
bundle.replay.min.jssha384-gRDJAYYebCVmiY1Ew6s/YYHtzAVR8dx3Y3wzW2A0l2CdbucfpVVcjE+eIgEiavMy
bundle.tracing.debug.min.jssha384-8IwB2m5HgZ3AQlboLmM43V3jhmu0aIhmfiSIlhAa7Bu/L+o43PS/Fr3OfkhRYjuO
bundle.tracing.jssha384-38ZfjW+JkmtAfkiGkZY57dkglvRLSHDMLfxBfK7SCg10NFXTdy9q8iGN53HPccjU
bundle.tracing.min.jssha384-oCdDUQ/+Aj0VJ9fi4jeZTENsQ35fqB7UuVtGKNxY6Q+eI25KAXKVab5ulE3IygL4
bundle.tracing.replay.debug.min.jssha384-hvkT0aGrzFVx7Yc7ZyROfNb3+OknhB0kk3BJoBeFyVIvThdnAn02w5QoKCaVdiK8
bundle.tracing.replay.feedback.debug.min.jssha384-ax9OhjGDNtJlu5O+zkTH1uCeb5FxGxn0RsOu6ANWCCDOG4rP+5ZZIczUOKEfq6nT
bundle.tracing.replay.feedback.jssha384-BpO5E59CFFjP56CV41NnFQEcz+AKA02fYW20eskuNPnfHsQl94aLHB3CGbhroaZm
bundle.tracing.replay.feedback.min.jssha384-AjEie096M0si7Z7evQkKpGRBFXtrRj0v7pb1FTQau13fhSYTdtEgfW85kTIrWdBe
bundle.tracing.replay.jssha384-wgg9ruEzmGyhcI6ZRT7wxTFt8qlRtYVFR0BQLp39GPwmyzg8/6Uf6MO56ZxcYTXJ
bundle.tracing.replay.min.jssha384-iZi3E4k4iT0C1fBrlJJGnCFCKiE/zZNcS7BHeMPcz2smbXO4aGy21u1ydpedPOem
captureconsole.debug.min.jssha384-yU5slkJOqjvI765KcCBk4ey2knQNJP/yZXqgOQLQuWJE7mU3j6sj2JVw8hzdhioh
captureconsole.jssha384-ra4pquO06PLuubkepDjfL8//72fKEQHLCCO49BJuxinWzNGs+L7LKsm8Gk4HEdDS
captureconsole.min.jssha384-MkoDKF+5P/9846SG4nuDbD5rFaouCummgOL4JTCXaMTKQiBlPSI7apcxLJ47kD9s
contextlines.debug.min.jssha384-Zc99uxbUt3hBkJ2VViB+BoXfgZcEHXxSaoQUt4/zG9dnPwf7NJqhOkD8v3JOfmjX
contextlines.jssha384-ZZ1JPPKvHuupEUqEz+IXYWOoGpJcppYwfEccTxpUPYRUbkURshZjA4bLIXtfkna2
contextlines.min.jssha384-lO0r8eN36vmbN6o/1P5CF5mxbga4GhbOZp4szHOePsoeeaJlIhiq4O77fOBbn6Yc
dedupe.debug.min.jssha384-Oo4OF92D4Oim8lLcogIdCCwvqLEP9eVpVezOC19+6U5P8aR02o6gMavXIPXLFUo9
dedupe.jssha384-ujgNcrtThPWnxnf4eLtjb9RS2Z7xxfAy5G9gREsTu2TmLvTBsQyTYhT6uwM9ITTd
dedupe.min.jssha384-pRBF95voixpP+H86Sl0ObcsXCLsLaY5MwkIeOhz98QXnbi1pf5SfrDg4Axb8XCL5
extraerrordata.debug.min.jssha384-CmtCFr/mavU6B8M0q8cf0s8aDi0HO1J6NDvEkUI16IRGzWO3OFvgWUEX1vs5Nhlw
extraerrordata.jssha384-NaCHRTdswRDqQW2rp3OgqmWe5YDi4pxdBe+z+gtWr9xF0BBf/nqVdStQsN5XRAom
extraerrordata.min.jssha384-Zw7p6hyDF/dRgyb94hvhnsX5WMkf68kqfvFe7ZelzWacH8rWM+cdccY7hqUWzUEo
feedback-modal.debug.min.jssha384-yx13IJ3wEXXpWOD2/eqsPJBzfcYSr4Y9gEiO7yG3mGJ6K0o77VFzLOuPTsR5hLlY
feedback-modal.jssha384-LhHOk9pbQ9tRG4YhmjoPPvfWbw45Xw+BsFbR1z/EKtsb6+Cg/rbo7jDYDoEL0/v2
feedback-modal.min.jssha384-6AJBrb665qM/YifLWX1PoSUiDzWOe4ZBjV9Zj3UwP+v03+FaAOru1zPb8wOedtxt
feedback-screenshot.debug.min.jssha384-4SDfHHXN8gPUqO9Sm7gnhL+5XNOyBPZl42IoGgtOkuwR3JuERbXocUeHBqJvXBBi
feedback-screenshot.jssha384-uqjMYvpHlpxCPNicD7IF4P90Eu8fwBLUWSTBgQ7nzo4GkQILQMnjlNDSj9/hPVj8
feedback-screenshot.min.jssha384-OB3NC6PhnZjeRzzAc8FM09r5emGQ1TbDRbKFArYz7KlP4384eNXgd/8a4axlkUio
feedback.debug.min.jssha384-C0MS+qF769XdCI0BU6GUzU5vP3Ukz4+e0ANjzPOaL/vdgnx6thAI9qh9fcOK+a01
feedback.jssha384-ilfRX5iS/C8/SWBYiPJg0VEy496BCmgj5WNxtKvIPSIAmqmgpdbpYtHdjsFjH0Xn
feedback.min.jssha384-IYTBs/ZuOGBx4VkWTgc2kjiJiLVAB9LXhaK8/XHEqhiC4vEde+kaAll/6kwqK5aS
graphqlclient.debug.min.jssha384-JDatMfn8cERRLFuVwRZcNkiN40Mzc3Dgr294UL6pzp/opYEV8is7hcirtBsIR57J
graphqlclient.jssha384-z90KmBxYZqjnzv8bb+oJzARJ4RFbwqS4EdYROOITK7RY1EUU9SuOTsc13ttrPYJ9
graphqlclient.min.jssha384-X6HOEeMWDOv8CAM60q6CZ64ftBXNy/qAg6dx8JZM5Ey3iAS603SyBk9oP4N8S2/S
httpclient.debug.min.jssha384-cPSdOQ9pHzrJUYHm0wis8msdsGqCHLhOt00rTwxTbeaUU9lIUNPDrWOTZ19nwTb/
httpclient.jssha384-Vu9k1/M8nawOMRATxIRYXzdNYkTJ8EjKo9wYlEmhw23aQglfshLdUMjU2ng8QJW6
httpclient.min.jssha384-k/rlaphwCzeVHw14Xh6tQtWyC1y9NZAGHTdtsL1UmNplnzDeSqZgInwJ7hnc2md1
modulemetadata.debug.min.jssha384-vGEdwXlS3iRprr5aOEhG77hJjT0d9pdPaapRb7MO4eOwLuvrMEePLfAnCC2wTeX+
modulemetadata.jssha384-of/YJYnSocvs2jbFH9LBSUyhci7yXkSo495JwOmxIWttK1HTfH4v6ew9W2YA5SYG
modulemetadata.min.jssha384-thge5pnrjrQcORQrohxYw9DrRqFNou2hd8h2HkVaCzwAkYSzBpiISaEcjB3Brzfj
multiplexedtransport.debug.min.jssha384-9F0gVcaK/icVoDpoAxBM2sazUf74y3BiFFg9atwO9VZleOg1pjX1W7W1QNSV5USR
multiplexedtransport.jssha384-P0zLksp6FLizDI6YYWoByxNssohYcb+X6w5gatfKns3WebKgdF1GUWCdwLh3dxcj
multiplexedtransport.min.jssha384-W8FQ98GwD/7pX8syYDnNU8Bk8O8Fd45tRuGa7t1unKfFXL6QbKa+ftD5/k4SP8Y/
replay-canvas.debug.min.jssha384-6QDFOyK/UoeYsxgcAYho3j/VRNGQs782cV4WfJ8ARzEh/panhb6C+ByaR1G6Ig+2
replay-canvas.jssha384-dZOC7R/vCvacx8sXx5sCqAtnuebdkq5L+dySiOPvCGXC9N4W1iAgKb2lP8mL93QC
replay-canvas.min.jssha384-U4t7O+K6nPbA9T5FGui/UmhdhfSRxQoLnr/A46s4ZRkn7mnxTbhdoUcyG2N7CQk5
replay.debug.min.jssha384-XG0LlsPI3Zu7k6VpJcxDQFaYr4k4aFGz7b9nK+QKf+ti0LsQlCZsuET97Cjfii+5
replay.jssha384-tQwIT7ndGeZlWuE17yvgPs3+8Xt5Ro2eG1MpPZYaUMdSnGha76o4+rsSgryC05FX
replay.min.jssha384-P+ur7SHrNZ1RA7T3w79t6WPcGRuaph5FwgxuEKE2QvWNo2LDuvDGjzQ7i2HBTVIy
reportingobserver.debug.min.jssha384-J8+ALB9iAQun397F4z/TVTSq6AG3bKZoNN8CP7gTbgZQTBPDdL8cVLpryTo8lHtq
reportingobserver.jssha384-KoudPFJ+IQ1j+y4kOe92rfKie5x94/HU7txicVId6hjyFbD7Ut9ks/wPxiKIGYYo
reportingobserver.min.jssha384-XLD8JHfovIcK/hew/YNwizf6vxuI/D3xfb5raIxw/LUuzD54tHpx3bg1Gs6CvBXt
rewriteframes.debug.min.jssha384-ghdHe5T57ieta1mclPr290p9/TSdDxsNqB+7nUw4v8jcXLrWxTjzKUK621Ohd5Tt
rewriteframes.jssha384-WGikdBBKaVurRRtwI2XRzz8lahtm5qrr5CpIL+V6V9EaEtOmf8AHHlacLGmQcgtF
rewriteframes.min.jssha384-N4IO1R+tCFdHtj+VZGHsaGl9QnmXfThWjGVllQv9t/FtJTECoMLqGrXQMvP8fDxY
spotlight.debug.min.jssha384-+na04QusoAjOd1czv91WZYUdjM5dvX+8IEApP2RRZS03kd1Eg6a/ldG8SB892bRv
spotlight.jssha384-dsF8No1UVQ5w2hC6zubaulnGZqXVQaOMzmCK1NY1Kz09v5qTL4taeBlzBmAKk+Eq
spotlight.min.jssha384-W90NjxCIzJ8MByGBKcPCJXjW5xUA+Krz5FoLnkLrrqssGCCQgDDPsC+4WaxFMl24

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