Issue
Is it possible to record and send to sentry CORS erros from browser console?
Applies To
- All SaaS Customers and Self-Hosted Users
- Error Monitoring
- Browser based SDKs
Resolution
This typically depends on JS and your browser, and not Sentry.
As per the CORS errors docs:
Note: For security reasons, specifics about what went wrong with a CORS request are not available to JavaScript code. All the code knows is that an error occurred. The only way to determine what specifically went wrong is to look at the browser's console for details.
Therefore, it looks like you don't have access to CORS errors programmatically from the browser. You can turn on the optional HTTPClient integration to capture errors on failed fetch/xhr requests, but that creates sentry issues for all network errors, not just CORS ones.
Technically this does allow you to filter out the network errors that you do not want, and just keep the CORS ones. You would have to use Sentry's filtering options, namely SDK filtering or Inbound Filters.