Out of 24 errors that appear in the console
of my page in Chrome, Sentry only records one.
I have followed the documentation and ensured that Sentry is loaded and initialized in the <head>
of the page, after jQuery, but before our CMS vendor code and custom bundles:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://browser.sentry-cdn.com/5.8.0/bundle.min.js" crossorigin="anonymous"</script>
<script>
Sentry.init({
dsn: "https://...@.../..."
});
</script>
<script src="..."></script>
I have also patched Sentry as described here to copy console.error()
with Sentry.captureMessage()
, so that I am now seeing three messages in Sentry.
But I am still struggling with three types of errors:
Uncaught TypeError
- error in a JS file coming from our CMS
- some very particular
<img>
srcset
errors
As regards the srcset
errors: I have already added onerror
handlers to the images. They are called in some cases, but not in this particular case (the srcset
attribute has a space in the filename which violates the syntax); admittedly, this problem should rather be reported to the Chrome dev team than fixed in Sentry.
I have tried to capture these errors myself and redirect them manually to Sentry, but none of the following listeners even catches them in Chrome (sorry for the .join()
, just test code, I didn't beautify it):
window.onerror = function (errorMsg, url, lineNumber) {
alert(["window.onerror", errorMsg, url, lineNumber].join());
return true;
};
window.addEventListener("unhandledrejection", function (e) {
alert(["window: Unhandled Rejection", e.reason.message].join());
});
window.addEventListener("rejectionhandled", function (e) {
alert(["window: rejectionhandled", e.reason.message].join());
});
window.addEventListener("error", function (e) {
alert(["window: Error", e.reason.message].join());
});
$.error = function (message) {
alert(["jQuery error", message].join());
};
So: am I missing anything (some Sentry config setting, other browser events that I should capture, etc.)?