Sentry in chrome extension


We are trying to switch to sentry right now in our google chrome extension, but we hit the wall right now. We found out that there is probably no possibility to have details of errors in content scripts of extension because of cors. I tried probably everything, and have no idea is there exists any kind of hack or solution to reach good errors stack and message instead of “Script error.”?


1 Like

@tranotheron – offhand, there are definitely Chrome extensions using Sentry in production.

If you can recreate the error you’re experiencing in a sample application you can share via GitHub, I’d be glad to look into it. But as-is there is not much to go on.

@benvinegar is anything special required to use raven-js in a chrome extension?

I personally know individual organizations are using it successfully in Chrome Extensions, but I haven’t personally experimented w/ it (yet). I’d just drop it into the extension and see what happens.

Basically, if you run into trouble, and can create a sample application demonstrating the error, I’d be glad to investigate and explore a fix ASAP.

I added raven with out of the box instructions

Which didn’t work. So I did this

This works, but not ideal since that means that I need to do this in all other methods as well?

This is an extension that works on sites like ( Let me know if I can provide more info

I dug into this, and it sounds like it’s a bug with Chromium and content_scripts where Chrome doesn’t trigger the window.onerror event.

So, this means onerror – the global error event handler – can’t be relied on. So you’ll need to use try/catch … but there’s good news, which is that Raven.js automatically wraps async methods with try/catch for you. So you just need to do:

Raven.context(function () { // wraps in try/catch

And you shouldn’t have to try/catch anything else. Any error in this execution context will be caught/reported. And in cases where you have async code (e.g. setTimeout or XHR callbacks), it’ll be auto-wrapped by Raven.js.

Hi. Thank you for help. We will try that in next version. :slight_smile:

Hi, we seems to have the same problem, is there any news on that, or should I encapsulate everything in Raven.context ?

Because the problem seem even more painfull, as it seems I am forced to wrap all the callbacks I pass to chrome.runtime.onmessage.addlistener .?

I use Sentry in my javascript. I use it by doing Sentry.init, but I don’t have the Sentry.context function. How can I use Sentry.context? (I don’t use Raven, i just added the Sentry javascript file to my Chrome extension)