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.20.0/bundle.tracing.min.js"
  integrity="sha384-E/jGYbQkoHuFhzT8i+HtaByOp5LW0Nq0+dZli2TYOGWO7R7Dc033UmOULqcChCtZ"
  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.20.0/bundle.tracing.replay.min.js"
  integrity="sha384-7jPoRXzUJcE6iNl0QqExdtlVm5zp0VuxN0Q/v8+gdviUJf9+h3BKAjtc3pwOWdDE"
  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.20.0/bundle.replay.min.js"
  integrity="sha384-bJFpzla+e1JNQedDJ+O6prDada+YECWc7wyonJYrHWVBs051V1ceUxyC17Q2IoIL"
  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.20.0/bundle.min.js"
  integrity="sha384-H7O6Dw7Q1CI5HrPxNsyBuntQgyosNqQbAPPsaA2uUfE6GaIja89XV5L+H1iCwf6E"
  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-nTsbCv8dvm32sjPFKH3D4g/Tn3vMrMoZg53i+1Q9ENKEMf8RA1fhhmPC8tUe5jvK
browserprofiling.jssha384-YA7S4payPWJOhjTil7APkxpsUmOE7md3M+Wi/qjXnR9ZEpbM0Y520qw6kCCAzjBf
browserprofiling.min.jssha384-XZgEqw9dtu+nqOKoQBTvtYlkMS88Ai1YfbSj7mHL4oixKVqmo8Gol2AVkwQmZMre
bundle.debug.min.jssha384-LRqRTUzHUqhuAy/yhIYOoXjw20wfZxgxLNFuHMkmPgYuVE/gs/sZSPGmcymGcUiE
bundle.feedback.debug.min.jssha384-J1LvvXdvYTh2fN2j+tpA0191xh4LTigmRt1Ri4E5OZt6r53+fhTi5n+LG3uwmPhg
bundle.feedback.jssha384-CiRIHerOOSCB1gVHvpxAOEuk9jFt52kV0PaE5jerK9X/NVTEvyhuTzDzp0ZvPnmj
bundle.feedback.min.jssha384-fufLqll0tDpv6VglIYR664Mm4t/DRziFOw6s5BAt06jm0LzFP/wWKzxlHQ0e4SEN
bundle.jssha384-3G5H5GeTJ3cOOo2qcjeySyNAwcIU2Dy00g2/5rzzvl+abVQsrvwEA5cu/sGU8pKt
bundle.min.jssha384-H7O6Dw7Q1CI5HrPxNsyBuntQgyosNqQbAPPsaA2uUfE6GaIja89XV5L+H1iCwf6E
bundle.replay.debug.min.jssha384-5cFiuljWCQWihV9mkwMbEVjjnjqXphxlH803hjOvVF+JekujHPMAkqeKtPBXAbcq
bundle.replay.jssha384-E0XpR6WkhO0zCR0wQz1XkPboRA+jHYQJLW1VC3Ls2VEBBwn3sDSojQ1t/voyysAI
bundle.replay.min.jssha384-bJFpzla+e1JNQedDJ+O6prDada+YECWc7wyonJYrHWVBs051V1ceUxyC17Q2IoIL
bundle.tracing.debug.min.jssha384-nOwIWGpZrGHQOGJPIb5y/uZOPGaH4OiFvo2dMw1lCZ2C/jTjPbL07bQzjkTcjkPO
bundle.tracing.jssha384-XEoRXTFpQiIiKa8yburuDkl6acamfDOBAMLxd1pWFU2SumWq7DIARed2x/N8/TJH
bundle.tracing.min.jssha384-E/jGYbQkoHuFhzT8i+HtaByOp5LW0Nq0+dZli2TYOGWO7R7Dc033UmOULqcChCtZ
bundle.tracing.replay.debug.min.jssha384-B/pMLeWmgjXGDTs8A9+CPvHX38Xt8M19638wYy3ZqRZ4OFroOTYF1HtTChONUjP+
bundle.tracing.replay.feedback.debug.min.jssha384-sWLqug9GtGv4eD/rj/rp3fIlCFws6jaBpIR+ViY7HMiWKbAVFDCRyRX0p0108Fp5
bundle.tracing.replay.feedback.jssha384-JmQUnHUaBS5jESKDgoAx/wQIizFHwbl7bYaQwK8QVrHRN+m8IjR91Xd0GAzIAWQe
bundle.tracing.replay.feedback.min.jssha384-imy0NT3xD+kxbiwH2ZzzI+fiQD5+3QHW0d34wOt+5gAm9UcwkN6aB8ciE6O10uB/
bundle.tracing.replay.jssha384-rpUAiGtOyG8AHPdXDUUgKBB+XWt6OrNSXDMXvGjDFgkgnb23XFY4X3cpu2s8j22z
bundle.tracing.replay.min.jssha384-7jPoRXzUJcE6iNl0QqExdtlVm5zp0VuxN0Q/v8+gdviUJf9+h3BKAjtc3pwOWdDE
captureconsole.debug.min.jssha384-ubTKwdzQwfuUN03RibNQc0qoFaRnGlAvE3S/NUXgBcmybvs5ocpBlIWlGhufkcWf
captureconsole.jssha384-Nz97D1HI5ta+CGCmvOR1fidi3gElVQHFB/vhOAEYvTRippiP7cDhzPq8EYyYA9jz
captureconsole.min.jssha384-0wkESfmqczgsOwHomlr5IImexCn9HFRa+HtBHb9Grepk0EVA3uJoXPcmu91O0X5d
contextlines.debug.min.jssha384-PV/OQa1nfPWF7DdOBSqK7Jq3NwoENc7xdCzqXS7tp73/xB20TAe6P5P5xFkCIP1D
contextlines.jssha384-iXGs6pS4xbyOGbrA8xaeY5PQNb0Va2Bwd/GOkwbuAwxLRq8jmPG5HS9qB07viXL7
contextlines.min.jssha384-YII85qM/82oxCVyn25h1g+9+0hAVsGHfvRkqaVCFTe1UrwATpqsl/Or1GQmceOeH
dedupe.debug.min.jssha384-ofLLXBsxYyzFoCiFClon/otCHL1dfyzdxrKm8SqsmY0atzI9JQnE5gVKDuXlE23w
dedupe.jssha384-GS/vhKnXvKownGP/TsdChhrwiWhSY3iZ3zJAMamdNRmfP9u+2XmacQUKV6mN2ymI
dedupe.min.jssha384-FQp4j19qITXI/ZqzNdNGfAfJuI/SD/uqj2b7IyE4qcj8g9GhBztRE9yIufnEdNnl
extraerrordata.debug.min.jssha384-Mvf5J0oFKPhYPbSwOM192s2oocdoG5GDrU1hYuXoQeSzsiT9428r9XZSjd0BTP4S
extraerrordata.jssha384-7vjHubiDIGiLd7kvWCizU1w3cc2XwzNOIHww/qao6Spq8AeTSLDaLZsmmEiqO/5f
extraerrordata.min.jssha384-77FBII1Ke8lT+LeBgCSgiv0zIi4xKeaO5Za8no9ulwFE1T8zif4iKdQyS06SHQue
feedback-modal.debug.min.jssha384-sAGU0V+IOQtkzqm2AV8uzAJCgNBQRE5AGkpk+GqmXT80xrTmdJUZW00sBSz0Sf1l
feedback-modal.jssha384-EZf8UOB0Nby4djq1/2XD1fH/4bIxVAaqm12/GH+vcz6RsoSZqSgZpeWQjbCd2YTy
feedback-modal.min.jssha384-YHHcchRWKVveM8u47f1Iiq083+6yZ2YVNyDfLN+oTrGkbX1PgMpz+R6bP3SUWRQC
feedback-screenshot.debug.min.jssha384-e+RGbNnYuMAF9+VAuzM/671G1Y+sIYj1SZV1tFUjHlhkw8MUtmaLtCuymdqaHS5w
feedback-screenshot.jssha384-xluZVrJP8ods0qjy6f+WmCB0el/wosMgl//6bqPghXesk6fbvrSrM6jIHLyPsMIY
feedback-screenshot.min.jssha384-4Rfka9EtBToM0q5Th428wvSvlpP3OIYzuUUe9CQlBewnuBUQbXhFnlejnKqFmksQ
feedback.debug.min.jssha384-Abr0FtVIq+Fb2+DXoOWswzRp7sSdw7Q5yXkYMg3SZfDf5Le6u9dckl1OjjYxXIv8
feedback.jssha384-SEhvTCOWM+JZUnphKp7o1pVFLqVu9ngNfpcI5BBMsEib4gVPEd5UKmiu21AnGQ1p
feedback.min.jssha384-rsjAOQeo4g53QHvRW2k0xKguM9chF+5E2aooQ7QJa/ZaWqdqiFDOszCZZiCJNjD1
graphqlclient.debug.min.jssha384-yX6uKnxCv4Vn0mEZUaMuxOfsp5lcNG73rdUsQDxXLDosMM/lT/0wwKAcJGQe6zaQ
graphqlclient.jssha384-M+RMA+zuE0hgbrVg/byfTPwpxtaKk7F1JBWYYfC2sUmkdMCPEl+hmKbgu/h1fjsG
graphqlclient.min.jssha384-CLGkVDr/Y9swzPDiO6I6/XemFBvWV62LKzEruw880F+DUW6CyagYO4d7tVcsXA/w
httpclient.debug.min.jssha384-AoPPrFhpgHLhVDTIrPK9PWpEYBV0247Lrgp9ampENzx2orW7rFbe1Ad5kqPV8gEM
httpclient.jssha384-93OGBogBRoUYu6AKsaNH0ESMhVHDWGiikmmhwMD+81vszE11rStsmiS0JCG3+npq
httpclient.min.jssha384-HqBonTGiCwyMLw8Hgam/G8tqUE6u+9DaoRQdFydrsHlfy+SjY0tPCqHVIdhT/Od3
modulemetadata.debug.min.jssha384-qL9bLW4EpA5mJsJrFOS4phlOCR+2VVGjAqFJE34rNLzw5DMwBjRHzBOfXJGpFE8W
modulemetadata.jssha384-uRHGw34n58jGUUFoCqUty0QT9jrcdowgiu4jJUkH7nVImwowhwlxQfC15+oiHRZZ
modulemetadata.min.jssha384-u209ooPw/VUa8mJjJhrRtR70F6CeBAjAXay2ybWKIzYQlv9X/jyYC1DG5HTV5E7F
multiplexedtransport.debug.min.jssha384-twGejG7n4BicpV+Xf+XZG2YUwijC7OzQAX2hS6J8p77dxOtNJdsHEaZTMBzr5Hvc
multiplexedtransport.jssha384-wNeYmmX44RcxhY73S0Kfiu0Xx0suAZBIwRZi7wcgknCttLZVED/LJnZoxA9HOdfJ
multiplexedtransport.min.jssha384-fWokLWEbOdWD5rG8TCXplGARO0t30bSRXRIpca2gn+84D2oNWxXKU5AXjB0duZo1
replay-canvas.debug.min.jssha384-HVfgJYpnDxDhdJkici8ct1/iEm7OYLZMO58qWHOePUoNr6Miqb/Tm+gQSrb1QyzQ
replay-canvas.jssha384-RbVnJuyOROOUtoTp9Eh+LmfBfRt/CG62Ug4hfhg3Z07+j3NcmfBBnGnaAK8FQSW6
replay-canvas.min.jssha384-C+m5SzvERKRQsLqJ/v4ktSBC+mQaAxC6Vur2uokt6Y4iUEE29A5fiR1XlAslrcae
replay.debug.min.jssha384-R578P2YvRkeHH3IO4kBSmvpRAXaEVO51UJF/uR1O1alS6RA1wZfqSJN4AhL72Yal
replay.jssha384-Th+OIYPae+0pQvoikUdeghmDUPbkXJu7OA0LinriOrFNzIZSMajSmVNRIOM5Mpo0
replay.min.jssha384-zT4y7ZC0e5eG/kERLpb4k9+spqFT9vF9uJiCLbx8gRthjTlcnslCiU565WIK7PNn
reportingobserver.debug.min.jssha384-6HndtYNZ6XLs/QBfpuMqW4YL8r0lLyc40dZTGyPFKGDE8B1Jn65fF9JzoBgeUAw2
reportingobserver.jssha384-jZouf50zb5LhV/EJbUcdnhbd6yv/BvX87jZmnRoqE7A28gsxGh967urFMsvBtkUn
reportingobserver.min.jssha384-Qii6mr1frgfhDedzkbOYUoTG0lVt+ixhqfbPRiAj43ZJXbRwzTqd3mz+SurPZG8h
rewriteframes.debug.min.jssha384-isLBIos+KcS8K4M+sHJT+j7FeEACz+wk5V9UQ79YmlhEkkM9U/cBamfEDKIxtYvB
rewriteframes.jssha384-mbrG08OMMvR5jvCK/coIsROywLQ1bpp1ZFEJIecBkz6S/y7+Jz0ITBBbPcJYK3hZ
rewriteframes.min.jssha384-H4itZ5+Rlk55n8cI5U18CGk+xwOFWqm0IyLJ3cG0iX5C5OO3KgwjV1rjtWtnOcTy
spotlight.debug.min.jssha384-DqHAKGYoxPnijf60qt+m8ggExwhCFYBsm9XU+rwii9eyH0LDjvAGc0ueTpuDk9l0
spotlight.jssha384-Fveayc0DQtuQJ1EqLBoL0LBJfYo72cLRBmu9RSf2IA7Y9moxTLVqp7SKHJDhrYcn
spotlight.min.jssha384-vr77jFUnNX/pcsMA7bFgVySWVaoSz8M2ppTdEPtAoGpz9MdAJfrWBFYmIlCf1mdu

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