Cordova

Learn how to manually set up Sentry in your Cordova app and capture your first errors.

Features
  • Automatic Native crash error tracking using both iOS and Android supports
  • Offline storage of events
    • Android: Offline caching when a device is offline; we send a report once the application is restarted
    • iOS: Offline caching when a device is unable to connect; we send a report once we receive another event
  • Events enriched with device data
  • Breadcrumbs created for location changes, outgoing HTTP requests with XHR and Fetch, console logs, and HTML touch events
  • On-device symbolication for JavaScript (in Debug mode)
  • Ionic support
  • Under the hood, the SDK relies on our JavaScript SDK, which makes all functions available for JavaScript also available in this SDK ,including:

You need:

Run this cordova command to add the Sentry SDK to your application:

Copied
cordova plugin add sentry-cordova

This command starts the Sentry Wizard, which will patch your project (you need to do this only once). The wizard helps configure your project by:

  • Linking your Sentry account and project
  • Adding a build step to Xcode to upload debug symbols for iOS crashes
  • Configuring source map uploads so you can see your original JavaScript code in Sentry instead of minified production code

Initialize Sentry as early as possible in your application. For this, init the SDK in the deviceready event:

Copied
onDeviceReady: function() {
  var Sentry = cordova.require("sentry-cordova.Sentry");
  Sentry.init({
    dsn: '___PUBLIC_DSN___',

    // Adds request headers and IP for users, for more info visit:
    // https://docs.sentry.io/platforms/javascript/guides/cordova/configuration/options/#sendDefaultPii
    sendDefaultPii: true,
  });
}

Make sure your app can talk to Sentry by adding this to your config.xml:

config.xml
Copied
<access origin="https://*.sentry.io" />

Let's test your setup and confirm that Sentry is working correctly and sending data to your Sentry project.

This snippet includes an intentional error, so you can test that everything is working as soon as you set it up.

Copied
throw new Error("My first Sentry error!");

Or, try a native crash:

Copied
Sentry.nativeCrash();

To view and resolve the recorded error, log in to sentry.io and select your project. Clicking the error's title opens a page where you can view detailed information and mark it as resolved.

At this point, you should have integrated Sentry into your Cordova application and should already be sending data to your Sentry project.

Now's a good time to customize your setup and look into more advanced topics. Our next recommended steps for you are:

Are you having problems setting up the SDK?
  • If you are experiencing errors and want to remove unused architectures from your binary when submitting the build to iTunes Connect, you can use the scripts provided in Troubleshooting.
  • Get support
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").