Recommended way to initialize a @sentry/browser client

I want to instantiate a Sentry client that does not catch every exception on the window. Previously, I found out that raven-js exposed a singleton that allowed you to create and configure a client you could call:

Is there a recommended way to do this in @sentry/browser? So far I’ve noticed the BrowserClient but it did not give me things for free such as the browser scope.

1 Like

What you want to use in this case is to instanciate a Hub bound to a client. Anything that can be called on Sentry directly (such as captureException) goes to the default hub out of the box but can also be called on a specific hub:

const { Hub, BrowserClient } = require('@sentry/browser');
const hub = new Hub(new BrowserClient({'dsn': '...'}));
hub.captureException(new Error('failure'));

Does that answer your question?

Or as an alternative, you can just disable the global error handler:

  integrations: [
    new Sentry.Integrations.GlobalHandlers({
      onerror: false,
      onunhandledrejection: true

These were both very helpful. Thanks!