I just installed Sentry for a client-side JavaScript app using the standard code snippet they provided. How do I test that it's working properly? I've tried manually throw
ing an error from my browser console and it didn't appear in Sentry. Is there any documentation on the right way to do this?

- 6,763
- 4
- 22
- 28

- 10,665
- 15
- 61
- 95
-
Have you checked out the [usage](https://docs.sentry.io/clients/javascript/usage/) pages in the docs? – mausworks Nov 16 '17 at 23:02
-
2Feel free to review the answers and update the accepted one if need be, others may appreciate it! – Leo Dec 23 '19 at 13:17
-
1console - document.body.addEventListener('click', function() { throw new Error('Sentry Test'); }); - and then just click anywhere – sunn0 Mar 30 '22 at 14:06
5 Answers
The browser console can not be used as it is sandboxed. A simple trick is to attach the code to an HTML element like this:
<h1 onClick="throw new Error('Test')">
My Website
</h1>
And click on the heading afterwards.
This can be done in the browser inspector and so your source code doesn't have to be modified.

- 13,685
- 7
- 45
- 46
-
Awesome! that is neat. exactly what I was looking for. I'm using react Integration BTW, and it worked well. – M. Amer Mar 08 '22 at 19:52
-
This is fantastic. Worked perfect. One thing to keep in mind is you might have to write all of this code in the console. So, you'll need to use `document.createElement`, `Element.setAttribute("onclick")` and `Element.appendChild`. – dimiguel Mar 23 '22 at 23:49
-
This was super helpful - throwing errors from the console directly didn't trigger Sentry, but manually adding an element into the DOM via DevTools and throwing an unhandled error from there was perfect. If anyone struggles with this, try right-clicking a random `div` element and `Edit as HTML`, then add the answer's element with the `onClick` event. – bsplosion Feb 17 '23 at 21:05
-
This one should be the answer, as it's correctly testing that Sentry is reporting errors. – Mgs M Rizqi Fadhlurrahman Feb 23 '23 at 13:28
-
Verify (newer)
myUndefinedFunction();
Verifying Your Setup (older)
Sentry.captureException(new Error("This is my fake error message"));
https://docs.sentry.io/platforms/javascript/?platform=browser#verifying-your-setup
May be worth double-checking your setup (or updating) and config too.

- 10,407
- 3
- 45
- 62
-
3Pasting this in the console doesn't work and I can't imagine they want you to integrate this in the codebase? – Legion Apr 18 '20 at 19:53
-
It does setup correctly. If not, submit a PR to Sentry. I'll happily review it with them. – Leo Apr 19 '20 at 13:31
-
3
-
-
3If you'd like to verify events are sent in prod without deploying test code, adius's answer below works: https://stackoverflow.com/a/67884468/8422820 – smashed-potatoes Sep 15 '21 at 16:34
One way to generate an error in Sentry is to call a function that is not defined.
Note: This cannot be done in the console - it must be in the code.
Try adding this to your code (taken from the docs):
myUndefinedFunction();
If your code build doesn't allow this due to tests/linting you might be able to use:
window.myUndefinedFunction()
You should then see error in your browser console and in the Sentry dashboard.
Have a read of the Docs for more info.

- 6,763
- 4
- 22
- 28
Raven.captureMessage('Broken!')
is a good place to start (also pulled from Sentry docs). If that fails to send, the Raven client isn't being initiated.

- 3,807
- 4
- 33
- 42
-
3This answer is absolete. Raven is not officially recommended by sentry anymore. – Titenis Dec 19 '19 at 09:06
-
Hi @Titenis, what's the source for Sentry not recommending Raven any more? https://docs.sentry.io/clients/ruby/config/ looks like it recommends Raven to me – Charles Offenbacher Jul 21 '20 at 23:04
-
@CharlesOffenbacher sentry javascript docs suggest using official @sentry/browser package. This is js question and you linked ruby docs. – Titenis Jul 28 '20 at 13:33
-
If you can't or don't want to use an undefined function to test Sentry is sending errors, you can also use the Debugger in Chrome's DevTools by:
- Adding a breakpoint in your code e.g. for a click event handler
- Trigger that event e.g. click a button
- When the breakpoint hits in the console, set a function/variable that is needed for execution to
undefined
- Press play/continue in DevTools to then see the Error output
e.g.
1: function onClick() {
2: api.sendSomeEvent();
3: }
Add a breakpoint in the body of the onClick
event handler (Line 2), trigger the event. When execution is paused: in your console enter something like api = undefined
and hit enter to update the state. Then continue execution (click the play button), where you should see an error (ala api is undefined
) that Sentry should then send for you.
Note: this works for any environment, though you may need to be clever with finding your events in minified code ;)

- 10,179
- 4
- 50
- 46