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.8.0/bundle.tracing.min.js"
  integrity="sha384-k44lY8uqQEhMd4ooGw0nmkdA2/fFjyDaW5GQr2tt40u3FSyP6nnMO/W1VlxG5DYN"
  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.8.0/bundle.tracing.replay.min.js"
  integrity="sha384-yZuTSiwKZPO0RZq1I/RK1v9jvxfdTPuqeDZywEE2rx1eMpCdMmp0Nq27QxSGNm6r"
  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.8.0/bundle.replay.min.js"
  integrity="sha384-D0NumRPQAPNrBH3+KoBABkxKRsLoLNROic4tbqw1J5cQYtPD/MZt0tOx/dsPjw69"
  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.8.0/bundle.min.js"
  integrity="sha384-5YkuuW9IA82TqjH/PwfVIlf3EmtBVdKR3DegMDNGxlBEzutDKYzhDKeBQhgPzxQc"
  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-t0cX/YHN/MNQ4O31ga2sN8E7eLdkUYLU5y5O3S3gavjVCO6bsgppm5Egy0IhHsrD
browserprofiling.jssha384-rj1ftF47dyymNJ0T/Elj478pe9xh/VFnw3oxcwm29srvcwwsMXyteJ/yKqdC3GXC
browserprofiling.min.jssha384-z3+b5PQL3U386wIjpI1vNdWMEVLenn55GrTU0ccNgveW2NQ5kok3F/ZrprzVoZjS
bundle.debug.min.jssha384-Xn7zLzkphb78c8fC5M1Oycd8vg/hjcFxuNv74PZoNGa/sFLqUDjikRh+Vz8hhMZ5
bundle.feedback.debug.min.jssha384-WJeEXwtCZ5W8YkKVqN7KVdxzQbHvyt6jeyX8Xs8mHap0XTM70ajaTxUlUYrVOsKc
bundle.feedback.jssha384-sdZZ0Nck3YR8r+1y2Ifpeu9tBxKKFcWh3IIKtNWG4C+ygqZvkWv297NXQiRvUUH6
bundle.feedback.min.jssha384-BqR1JL220rWjYEodXUqj+DdqC9WtoiZTzdgoKZ3JLg4euuDF05JvQzZ3eZ3BT2N8
bundle.jssha384-uCm7T1sPLimyJGwRTnGv+j/yI7uOtXzvKeUawH3WveDIcfFrvd62TVEGIt5Qwm9F
bundle.min.jssha384-5YkuuW9IA82TqjH/PwfVIlf3EmtBVdKR3DegMDNGxlBEzutDKYzhDKeBQhgPzxQc
bundle.replay.debug.min.jssha384-Tl+wGlEZLguCl19N1Z9cUAMnyjaBgo1sbG4n3reCU9l/cJdf7s4R2V+SPcJGQqEH
bundle.replay.jssha384-rR2wZZ1q89d+81ZB/fMx3zdVVlP0dSYGZ9BJJbF6KCtZ7o51ZcWTf9KEVrDNNr1x
bundle.replay.min.jssha384-D0NumRPQAPNrBH3+KoBABkxKRsLoLNROic4tbqw1J5cQYtPD/MZt0tOx/dsPjw69
bundle.tracing.debug.min.jssha384-wxyxEtEwCdviZhHAkfzwGDn3vw117B8zDLpU5Q96H0SYaSWOjNKqqfU65VScyG0h
bundle.tracing.jssha384-7oS87su/B5FuHGgnJxKUjRj0FKmwVQGoRgyQrThi8TyO+wXpAYN4dk9RuWHCKlaZ
bundle.tracing.min.jssha384-k44lY8uqQEhMd4ooGw0nmkdA2/fFjyDaW5GQr2tt40u3FSyP6nnMO/W1VlxG5DYN
bundle.tracing.replay.debug.min.jssha384-5Nndoshdzco7fYFCPSTWFGrHuqqMmKIFspPlsP8aZWN7uc6dnkll4XoD4jzjVYfE
bundle.tracing.replay.feedback.debug.min.jssha384-SXY2KDD61HX/5aXcbHl2prnNl3N4IWUDb3B2O2kTt5LYPcwFpas4tj3sgQ0beJSX
bundle.tracing.replay.feedback.jssha384-1OJ6NfMixkVd5wFNH7OB8G5Zma5/C68ZnLBlv+FIsPuiUAzoSpLaLrk8iexAUvlT
bundle.tracing.replay.feedback.min.jssha384-MB9nhgJ+TD8KTTuxq/IkYzYCmZDUZ72fc3ZURLDMi5HOCseYYxOkQvwafEtGFea0
bundle.tracing.replay.jssha384-Q/FhUJYoJl68/SkyOshKnDpsCgbR0zVZKJ7q3hu0XakPowX5Xayu6PenZ6RSTWJT
bundle.tracing.replay.min.jssha384-yZuTSiwKZPO0RZq1I/RK1v9jvxfdTPuqeDZywEE2rx1eMpCdMmp0Nq27QxSGNm6r
captureconsole.debug.min.jssha384-IGbVNPUtXSyPJnpZOZPj9wQghioa8LO5LSWgQf2zcgd6ADUIy2oMgmPuOiGb3Idh
captureconsole.jssha384-0tG15ZzBgPQ49/VYEJZuwlrV2nSD4pSzW/uVih6q698Dtdr62Xb22yykpybTU75p
captureconsole.min.jssha384-S8sybrU8ZsHKCVIoBmyHWd7+NwXVXWVjEXW21faRGfxwnlPBouZcGSnVATaZG9SV
contextlines.debug.min.jssha384-tBkXYGHhsSh/BSY0D2x+tBDANkMzVjPoJfKK2tvckfzng5PwKBg5CRzEFpfA2Rrt
contextlines.jssha384-qcTMLJWLQlRMB3Wb/eNYOW3n2wAhgLO0gnSJMzH9VieQsH9j4AFl1JNq7yzJkln8
contextlines.min.jssha384-qQYtLhwiiwnRHnsOa2rDbjdCpsEeG+9v04E7mEyUntFgCerrGbX7XUTo+lP1SDHE
dedupe.debug.min.jssha384-lUOLOb74bPdL3cMW4Gp3Oe2Wrg1vKj1+gk10A7NNVdHPpS/uhrOPwhLogctt4CoH
dedupe.jssha384-YG1jebsMxaB4Qc7FXByZbG0a0BEoM+KriZSK2Otoy5dlZ0bEsbhPxXt4mA7nfeuk
dedupe.min.jssha384-JaYyOxuTfazgbKz0DGJwSeidTM6teSm9A5NWaJNC3R57PXSormUF5pUcc0u68QDu
extraerrordata.debug.min.jssha384-P8mLldckFkVYEn+NGFL01CJrv33TKVTzXXPltTadb85HZjBTFWRnrdw/3D84qYgd
extraerrordata.jssha384-0z8x2fQSWdFuDMcwNYuZihqdY9Vp9um9KxkObso+uoLJIepmQcI1Z2a+uQSN67RS
extraerrordata.min.jssha384-vHFu59sG/Q9nySmf2fh0HePUCnrs9HXAaMXew3/tJPslq0lrfkZsXlVu2jLucKNq
feedback-modal.debug.min.jssha384-Miuy01AQZdBISPiYMO33PoPO1OuLUusHAd79xpVdPjLh3CzEbaog4o3Ud9mTEMSY
feedback-modal.jssha384-AryLCAVL308ez1oh1cQ+cLOg5Ob4f8Sn2RwHd2EJ07aPHfeWRoyeLMqGC33p+Psn
feedback-modal.min.jssha384-Z+HP/VTHIP8nYEJ1BOrt+jdXtzDoKB2E18YmRtbvnyI4XauSUAyOgzaf5W/a3BZv
feedback-screenshot.debug.min.jssha384-YoLfFtTwte5pZUAs7KrABJWXhwFOqWrrrzEh7NSXhWoY24Yf4Cg2QFqi5l2Y4JFb
feedback-screenshot.jssha384-+q85EM2lyIHfUTq8sTQfBSYIF/3JWp60FsLqBHpcjCm5VdatGknETh1yieOu0bGj
feedback-screenshot.min.jssha384-Bln41+FPKoDLqKCGn8NY4wSd+uGQYjYxEKIgRUD8zZWuX6KL4bFpcMk7eZoTMAoa
feedback.debug.min.jssha384-o5oJbkynjEF1aIGv+4uybJC9umfzG8aa6/1be+zyj6lSacleU2N0xMaosbc1CK+L
feedback.jssha384-F/fyVPzzV7rylAY7AZTMXk1hSxjmOMYomJxeTQZ9bWiR1rV67tRnHAMA4uI013zE
feedback.min.jssha384-Cfg7+XM96XeEZ7xzDwIsKN5NAi/xFJnLJoHAkPcrJs8v9TLqwyR3j/MbZ6E8dNJs
graphqlclient.debug.min.jssha384-5d3yC0LUVX1kAV1CMyXpE2fB+Aw0jUlpiuD+t1pOeB8JYrG85e3oupEn5FCwr3xO
graphqlclient.jssha384-GFTayck9bct7PNEfOH3NtRrVb+bgoh/h7sDOnLyHYohLn700kImBFpXJTPvAI5ty
graphqlclient.min.jssha384-y61Kq3JW3UHbTdlEQosmy1xccCmX7GWvEgCt7ug9BAYRQeEFjk+U2z1Ry9iNXd6s
httpclient.debug.min.jssha384-1+mxppL636GHU0+HtatAdTFZl0r1AcEZ4rr7eOKWTJZvRbLBe6seMsBd2Ll50syR
httpclient.jssha384-qhQ6xXgn4JMrs7O/QBmMuh4/gJvAemcMCu4zGh6aemJ8mk/iOr5GZomQC9z8J6Ke
httpclient.min.jssha384-Nn3F/xq8zFz/s3YaNDCyCrvtKhi+3z5K6jFte3xZ4v2WiuhKkTw1ybfcCD2dvTve
modulemetadata.debug.min.jssha384-RdqyMpDDtw+dVmtxF4YRMoaYA8SbupwkJCfKy5JRpbM0i9L5C4C40DCcsJaOyxu1
modulemetadata.jssha384-LYUDEyTaGHu/ytdzCe92cv0EYw+JF/KH8xwqQq2MwK9kXhFJtn5tDemwpUeLh7uT
modulemetadata.min.jssha384-JWYV7I0qOfrHcivtmBHaQ4bfI9nZKZHNddtR8BJl7MaWPwEYZU8nYNQldNVSu+Q3
multiplexedtransport.debug.min.jssha384-gyE0JAouTugYe5xmfEm9zRTZlvr7tBtF6N/RqlDVsRwuDY69OmHN3P/7yJ7548t/
multiplexedtransport.jssha384-t7OurTKZ1EYNtxmLT1FW2CXvE21waRx/IA0ycODTwmdCgipBDiATJzKs13K/7cwl
multiplexedtransport.min.jssha384-/pAEz9GwWiw/kydjM8UVKvCYmYx0HLmPEzfLNo0OsSeCQcHSiao3KXJqqLVC0nBj
replay-canvas.debug.min.jssha384-IxW1+knSIiVgE2BiQUQKwbQzIAuPDb8ANr55mF3XVRpI43U8jmZqMULC4JKDyOEm
replay-canvas.jssha384-5NzbdVNYK97Uv2vpaaNdrvhJb6aHwohDzq53dSMJN02a9fX6vRWUR0puY9sHqo+s
replay-canvas.min.jssha384-ofVw63pJoPamWkamEE1w1MWkFiGNbi0vF2rq+aR8tbHcpnMpJ4FLOo6566Nvoeso
replay.debug.min.jssha384-nL6wK/TeY5CD+ACo4TVxVF8GANNHQvCYUTw3ZvLNwYuYPjenMFJV4EFhNflo5lME
replay.jssha384-1Op60jwl8yfdHd0UPJD0ufIPWF5ZmUMHO4DAUPWC4NbCE0vlHE81ljvPTKdvMuZM
replay.min.jssha384-VKs0+S6j4pvHgiKHPSEc+Vf8xMeGtTjw04Pe5M6pDzyUE5+nBPDlmQ4vrtxpqYqv
reportingobserver.debug.min.jssha384-TaYcrO09AcdQv/SrbxJyY8rQI0BQZAqY5u/ElFIpP6HVelro/1rLybDDPSXn+OpV
reportingobserver.jssha384-8dwtTe6VXhxDbp9PeiHSRTI7Xr3pmD5vj83EjfrGEgrpxZrKjyzH2muOU3Xj+ZB8
reportingobserver.min.jssha384-Z7M/XlA82BpOXYDvdl8x/6PuAdt3+3/UM9IpWpz4282HuhwwpmxrKX7vg9xh6RVc
rewriteframes.debug.min.jssha384-O51c1ShoZE1Eh2L06MbNrBMgSEjwEOm9MQ2cb8RIMFh56m0hyNHrL0zEBOK6JDoE
rewriteframes.jssha384-+nLrhwJyZ+v2FTLb58LcoXVUCfHtJdqQ0tglOTmWf2yvoGb42BD7EtM8yf2P41ig
rewriteframes.min.jssha384-uHzHdRZaTnF0DuGkhJ/h0fzS7vE/FroyBLhAbTxqz4Hit6IK37RI7vBGeBd0Is66
spotlight.debug.min.jssha384-OU1foGa02/2WwxfPDkuqsrCbh9jJT196WfabicXhNbjxaiYWx0O7h085lYPuY1OC
spotlight.jssha384-/zcZ1yMKo7fTwTJ2kJHJNLqSIslCsNVFm0NJ31dIHxzV/LeaM1hGuYO40gwm/gcq
spotlight.min.jssha384-0HC+V6KXixBsuiNn0ArFXL2Fz+aRfCObY46BBljnCFMbhoNNIioclY9hc1JgW/Tt

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