Receiving Too Many Unrelated Errors from Chrome Extension

I’ve included Raven in content.js script to assist in reporting bugs caught in the chrome-extension I’ve developed. However, I’m receiving errors on every page any user uses the extension, event if the errors are not related to the content-script.
Is there any way to configure Raven to only catch errors caught in content-script?

Same problem here.
Sentry team, anybody home?
How can we restrict error to errors coming from a certain .js file (aka the content script)?

Here’s what I found:

Sentry observes errors through two global event handlers, onerror and onunhandledrejection. The former captures uncaught thrown exceptions (e.g. throw new Error("test")) and the latter captures unhandled rejected promises (e.g. Promise.reject("test')).

The errors typically come with a stacktrace that includes the filename of the script (or page) where the error originated. The unhandled promises do not.

You can use the allowUrls config option to filter out any errors that don’t originate from your Chrome Extension:

import * as Sentry from "@sentry/browser";
import escapeRegExp from "lodash/escapeRegExp";

Sentry.init({
  allowUrls: [
    new RegExp(escapeRegExp(chrome.runtime.getURL("/")), "i")
  ]
});

Note: this will pass through any errors whose origin is unknown (like those unhandled promise rejections).

Unfortunately, I didn’t find a way to differentiate unhandled rejections originating in my extension from unhandled rejections originating in every page the user visits.

But you can disable Sentry’s onunhandledrejection integration like this:

import * as Sentry from "@sentry/browser";
import escapeRegExp from "lodash/escapeRegExp";

Sentry.init({
  integrations: [
    new Sentry.Integrations.GlobalHandlers({
      onerror: true,
      onunhandledrejection: false
    })
  ]
});

I ended up using both techniques for Content Scripts.