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.
<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.
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.
<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:
<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:
<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.
<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:
// 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:
<script
src="https://browser.sentry-cdn.com/8.40.0/bundle.tracing.min.js"
integrity="sha384-RJuJafS05CMMBWS88y1Fr28yxGBOps2WX6X+OqAdiPkMK89AqBLQVSjaVi8yUoKi"
crossorigin="anonymous"
></script>
To use Sentry for error and tracing, as well as for Session Replay, you can use the following bundle:
<script
src="https://browser.sentry-cdn.com/8.40.0/bundle.tracing.replay.min.js"
integrity="sha384-Lr3KOzFTdBt9fOkpyrnvfLyOgSFPM+CwkAsLzDu4iQlIST7yYWCzGJ5FTwrcfBjo"
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:
<script
src="https://browser.sentry-cdn.com/8.40.0/bundle.replay.min.js"
integrity="sha384-4vlSF8fpmj+9rK1OrWzXmizmIk4rDBd2+aH9A8ZSg9Cvcef43WKvxuIKb7jXn2aN"
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:
<script
src="https://browser.sentry-cdn.com/8.40.0/bundle.min.js"
integrity="sha384-nggeAmqVTUejZLHwH4xL5xehxXjuQbRw9CBDduGWAg3aG2ae+Bq+ff59/858SfHp"
crossorigin="anonymous"
></script>
Once you've included the Sentry SDK bundle in your page, you can use Sentry in your own bundle:
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 (namedbundle.<modifiers>.js
)@sentry/browser
with error and tracing (namedbundle.tracing.<modifiers>.js
)@sentry/browser
with error and session replay (namedbundle.replay.<modifiers>.js
)@sentry/browser
with error, tracing and session replay (namedbundle.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 theRewriteFrames
integration, compiled to ES5 and minified, with no debug loggingbundle.tracing.es5.debug.min.js
is@sentry/browser
with tracing enabled, compiled to ES5 and minified, with debug logging included
File | Integrity Checksum |
---|---|
browserprofiling.debug.min.js | sha384-eOeZL2rOFCEUk4Zsb9ZeK3UVD8mOrieEZNlcMF7JiU6TxpJ7Z17XmmsaDTkK4liW |
browserprofiling.js | sha384-XlSP3Hv64i24zLWawhdeLoNploPErub83oPCXur9U8UpibFMefI+uQVcRrG6ZZeE |
browserprofiling.min.js | sha384-nXWEd4noah9ECJGWFPWbZdK1NTuvta6QVG4iWVrLT6VIzv47u6tpxm8oJjdtisCi |
bundle.debug.min.js | sha384-XWeEpWJpUw1cVpP5a1PTsu9akVc1uw/8HO7+nrNuOQOg0PSBLX3RqQLkGZ3ABNzw |
bundle.feedback.debug.min.js | sha384-Yxj1fi+zW9lkhegZ1wQv5b7nc3UF2embejhvqwz3mxGHDFAZo4zdlBpBQOaLTkc8 |
bundle.feedback.js | sha384-+wRiD46C4LHiKMVNNA1Umtcyv5FYjGBqqbxpdTD2oS9mzBv4nqPwA2Svrvy7iVI0 |
bundle.feedback.min.js | sha384-vy4JETM1k2Q2PLNnmkUXR6iJx2C7k+ZUE61w1rha72ctzZMoL4ng0ssCsob0Ix/6 |
bundle.js | sha384-h4PQV5GxxtIuW5hyo/cdbBZTdK1QWD+UTXi8KraK5PKU3vgtNMi5ZPBihXo8Yi/E |
bundle.min.js | sha384-nggeAmqVTUejZLHwH4xL5xehxXjuQbRw9CBDduGWAg3aG2ae+Bq+ff59/858SfHp |
bundle.replay.debug.min.js | sha384-Q5hh6E5AVA0BN5/Nq7cU0EthFbG47Fu1oq+NxxY6Vq2ZHf/ep0RmpYMQSpTxfrlB |
bundle.replay.js | sha384-kvLq4k6wsxBw0Ms9IaW0wJaAbxfabm4kOY0TSqQ1hI2LzbhZfiJn8i6MhymYVnuz |
bundle.replay.min.js | sha384-4vlSF8fpmj+9rK1OrWzXmizmIk4rDBd2+aH9A8ZSg9Cvcef43WKvxuIKb7jXn2aN |
bundle.tracing.debug.min.js | sha384-H7I8yRp7vdNI4sFcrisD+AFkYyQIt2G2ol/JK8C1r0yLXunbzVzi8QffT4jwhzLE |
bundle.tracing.js | sha384-3LYZ98Q7SUHxdvmxzcKMcFNYF3WU0ZG5Mz6d3WRDgUHvELkG4udmkRj/Wz6xMUci |
bundle.tracing.min.js | sha384-RJuJafS05CMMBWS88y1Fr28yxGBOps2WX6X+OqAdiPkMK89AqBLQVSjaVi8yUoKi |
bundle.tracing.replay.debug.min.js | sha384-vcheVAM3dQwNm20mKOwLxckfQLkyTuBblpuaWmW2D6u8SAcPQN6xUpjgXhk6s55a |
bundle.tracing.replay.feedback.debug.min.js | sha384-P4+2iBMaCEtkcATpbXljYkTbIRwPypJw+zwxyK3CbLfh1Y4Q5sL8gbbeVxAZiQod |
bundle.tracing.replay.feedback.js | sha384-sxTlLyuHGyPd2qqM4T0AwVrFVu+6XtNMuwDWvWJkLdG6ia33my+ivwGOpl7nmEPc |
bundle.tracing.replay.feedback.min.js | sha384-8mo2k2A2YzCo1hdntIc0rrE/WqQMv+0PhEUAgQBo1I/K1Q3YiMl/vD3cV9Kv9GbB |
bundle.tracing.replay.js | sha384-oKnTyz62i4mIill1DdZ6tFM5rzXdU3dJpCDX9eJo8itPu76GYKvzW3V74kflHrQI |
bundle.tracing.replay.min.js | sha384-Lr3KOzFTdBt9fOkpyrnvfLyOgSFPM+CwkAsLzDu4iQlIST7yYWCzGJ5FTwrcfBjo |
captureconsole.debug.min.js | sha384-bC1b1Xppti6xPuz1ZYefo9rLrD+er8oudS665Xghrug2fojMRv59xQhtwacFjLu/ |
captureconsole.js | sha384-/h9jplIkkcAtg7VD4aWbl1COAlnYkb+5IQXlfNVdqvZd/KsGQbF92Iv7y+r330u/ |
captureconsole.min.js | sha384-tClSSLcWo2Yw1SrISs380LTbWD7/rmHa9m6uF/c+vGFhH2DdS2N4yglJJ2cwuypy |
contextlines.debug.min.js | sha384-DU0JiTYzYi8IY9fPCwS9qa0+KFUlSRbzmy91dy8F4vTPqyHFGfSgVeXj8EaA/rCr |
contextlines.js | sha384-sVRPs0OtyD4t/+hgqRmbxqhnsLcxpXmPgZ9ZHUV63avRTQy/khOkBFG0UrDhgiuJ |
contextlines.min.js | sha384-ADSsO2+sdc5PrR6vFSHM07uWvnbdJNnqGWnSQ3hA3WuFGM+srg9yucNrPyHc+/wp |
debug.debug.min.js | sha384-vTh7Zf7qTrICPyYL2Ds1TG368v9inM2rI7bDQhfZQePoYZGm149zldD1DosJRZOl |
debug.js | sha384-sd/gUrAjps798ljGbmNLPxIpgT6xpwzmSy6IX/ng+ikz8DMcGlIdBBLvqpa3jrFL |
debug.min.js | sha384-xdpkZKx7CpI5+kLMhxGW4Orv8JqXgURF7DOZXEqBeWpuA7G1seO4LwDUd4orDhmM |
dedupe.debug.min.js | sha384-gvvr+b0WNfCYAV32kxe2JNlbyUFGLtFXpBTKvUbw1slyAMeJpdvIaH0gp4PW9Irn |
dedupe.js | sha384-drFgmIKvmqj/z01RX77Ug1GB5ldxLA/ZjfdCjcQ1UmAkAocuyDKad6GdOtVHN0G/ |
dedupe.min.js | sha384-ctpmDFw7f2rIRgCkAEtj5eHN/X68y6K6m9nULS+UvoTp8O6d5R2KfUzsfUXve1VS |
extraerrordata.debug.min.js | sha384-Ijn7mqb3g2hiHgCQwj13Ucdhqe3jqCWmLgHL5pRKmCeK+LiEcZ+HllP5+FDwhnVZ |
extraerrordata.js | sha384-GGS8UWBqCJXX6ZF04UCwvMQdQ+AeWfAYGFFD0V/lQblhv9z3lH1Dtc22Lj8Q1Gcz |
extraerrordata.min.js | sha384-eQctOp1AUNEVgTk3MohArSZ/41Jk+4sYPC1DiaZJ2TgLus5INdGp2CSBlXyz/vDZ |
feedback-modal.debug.min.js | sha384-mExfXqukbjI9LQJdHi0/E8t9evFSBWLreYcXVAmXsyAkCmXNNm/Glk0RoZaZOJIj |
feedback-modal.js | sha384-Wy55tj4Vdno9sKz1XNl4DRW8sEhYNQjzbkwoIRXCv9DnZFtLEPRycPko/CBUroVW |
feedback-modal.min.js | sha384-2H0QtFAdbs6cQ0jkCC6H+N9XfR2Krbd1jicpacRPrJ9IF9Ui8qQCKM/J0ye5dpqk |
feedback-screenshot.debug.min.js | sha384-z2s8Y8cwUCUPgRfjxiZtk3UV2f2O1GqX0eM9xby7BYRXFchmL7mtscD1nen/x7XI |
feedback-screenshot.js | sha384-w/GyqpM1HJPWpTXG0fFa3Ccna/8U2NtCeL1TZ9eaPYk1AXm7ToByCZJ5Co1/lqaY |
feedback-screenshot.min.js | sha384-xZf29Q1Oo8u72te2Poyw75i2wl7zX+KDoq58id1CeTpEodcy6pxd2lw+PIOvhTS0 |
feedback.debug.min.js | sha384-OsURwYyV5AIUWO/7uUna7JpvA0UMgAt8BuLzHyWgSb+T/kXRdk3s8Dw1MB3VhiMr |
feedback.js | sha384-6LQXjjLpratYjWD5/FE16tuXpXneOm2S54c4+7fsnhbjboqoXLzeH9K+TCmi8hTy |
feedback.min.js | sha384-UPHRCdFW96jONsiLlfyumkwKYwVGpUioKEYadtXZhp6W22ZFztdZZN9AnU4iODko |
httpclient.debug.min.js | sha384-wE+XnMfOqAOwaQqrJGZhvD+F7hmg3Ta/0voCDxKfjpbsRjewsfkfAU8rfUTwQTWX |
httpclient.js | sha384-4cZMyxzwFlmgekxc5y3vR1gcbNAMIjZuK+tX4EtHYpmoWxewhdV0W/jOQaLr854N |
httpclient.min.js | sha384-WCJlLdNddjROyKzyBMHYz3pQQYkOgULmEP9kSeiK2VICRyZJ1ihXqhZmxcYb7I4w |
modulemetadata.debug.min.js | sha384-Ci2Ssb4IoGLnvrMvcsxa6F1diWSFqDzfcGsdWVrX6dsNXbd39akUvP4iCwym8Ou0 |
modulemetadata.js | sha384-rFgOp0sCPVc+HEGGlgDkp1VcMliCQg0Zjc3/okInwnXwTWWwjRvSvxrif28EvA7C |
modulemetadata.min.js | sha384-273hnxt6uqP5W7D6yFqWwdlTP4mHrt9cPYCm1DRbN1H1gHrmYxsVqrIiGaXB8qRy |
replay-canvas.debug.min.js | sha384-Qq7uDVNnnvSOF0+aAACazp3VnAYb0q3yW9gc1Wk4eFmQAS1i0ST3jyetWGTo+4Oz |
replay-canvas.js | sha384-vblOcOLOmH+hOk7ffiDKWz5XR3m9aM0QlMEFHKt6KJUTKYgI64+g6mrMPNGIzYK5 |
replay-canvas.min.js | sha384-+DaXd/8z9vb17ZqH5u8ZfjactLdiPxIiq5fIHqIfxAKSbNjvAIim6bUOujHaAqI+ |
replay.debug.min.js | sha384-486j7y4yTbP/Yq+ORY6JpXlenHfceQh/se4PCqsmFcxnyaja6CJEuboTPTMCL7w2 |
replay.js | sha384-FDRZz85pWROGerqzQl64XsFLsmFoW8imRRt6W2k8MUUhr+tDjoorpHpXZ5lTKvcG |
replay.min.js | sha384-2n9JJFQonw+0h0SyoAOeatRLcd95Y+qAZKJFfyQB0wBYO9ru6EMdspSBPGvSO96D |
reportingobserver.debug.min.js | sha384-mI37jicPPK9h39c/asgaLFf+P1XSfKhxNhYbT8wtVQafemMiSYxdJPJky6/97PNP |
reportingobserver.js | sha384-HwlhhJ2Xtqgw3DRnMdCK9bjphV/s1rtHabl89R7FsOEhATWaaIlhDaRGS2nDS6uG |
reportingobserver.min.js | sha384-veDLjy59RacTXgI8IEdE71mUxyRx3PTHtPDdxCbVGlYSD+mUZHBpxVR7OPkiU87i |
rewriteframes.debug.min.js | sha384-hdsbi3jVyAGT6+GU2MO/P+a9ciJSMiFhPQqtBDwwsAym5LYY5/4RxdWcCfW97FEr |
rewriteframes.js | sha384-ZuGOvhvv4CCKli5Ab8ijKHlKwKh/A9tuQJHdpu1BElYV7JtSlUS2XBXW0CMNVd12 |
rewriteframes.min.js | sha384-mwIbSVMuE/kR6oiLahnbuZkADQbia7b8D5dJpevgdBn7Gc1H7VFS6S6Sl00EtmDZ |
sessiontiming.debug.min.js | sha384-2M8uTceRrbfnuUf+rSn1/A7ooY6b4kWzdav32ljat41qu/JfWGik5fXP/lU4c3hA |
sessiontiming.js | sha384-xCtISE2jgOjH5z9KnhnnV+hu9aR/1vS4+pS4b4Oig+3NMb9Kkf8xgIKm9Ko8J/YE |
sessiontiming.min.js | sha384-TTM9tN1XZSAW7/mx++Pq8gfiM7GZE7STER2ysmOdNNEM4Dp2+Gy0jIdM5N7vgnN6 |
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
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").