Skip to main content

[JavaScript] How do I filter out third-party errors?

Issue

I want Sentry to receive errors from my own application code and filter out noise from third-party sources such as browser extensions, injected scripts, or third-party widgets.

Applies To

  • All SaaS Customers and Self-Hosted Users

  • JavaScript SDK (browser)

  • Error Monitoring

  • Filtering

  • thirdPartyErrorFilterIntegration

Resolution

Use thirdPartyErrorFilterIntegration in browser-based JavaScript SDKs from version 8.10.0 and above. It marks your bundled files with an application key at build time, then filters errors whose stack frames are unmarked (typical for extensions and other third-party scripts).

This does not drop npm packages that are bundled into your app. Those frames are marked as your code. For URL-based filtering, use allowUrls / denyUrls or other SDK filtering options.

  1. Use a bundler with a Sentry bundler plugin, and set the same applicationKey you will use at runtime. For Next.js with Turbopack, set _experimental.turbopackApplicationKey instead.

  2. Add thirdPartyErrorFilterIntegration to Sentry.init with matching filterKeys.

  3. Choose a behaviour (drop or tag errors that include third-party frames).

// Bundler plugin (example: Vite)
sentryVitePlugin({
  applicationKey: "your-custom-application-key",
});// Sentry.init
Sentry.init({
  integrations: [
    Sentry.thirdPartyErrorFilterIntegration({
      filterKeys: ["your-custom-application-key"],
      behaviour: "drop-error-if-contains-third-party-frames",
    }),
  ],
});

thirdPartyErrorFilterIntegration does not work with the Sentry Loader Script or CDN bundles. Those bundles are treated as third-party, so almost all events would match the filter behaviour.

Did this answer your question?