UploadWizard has such a mechanism, recording all JavaScript exceptions that happen on https://commons.wikimedia.org/wiki/Special:UploadWizard (using some of the machinery originally designed for Sentry, some custom glue code, and some EventLogging definitions).
Using EventLogging mostly works, but it has some strict limitations on the size of data you can record there, so we can't save for example error backtraces. That's still much better than nothing at all, though.
You'll also find that, unless a problem is affecting literally everyone on every page, it's really difficult to separate problems in code you can fix from problems in code you can't. Turns out that a large number of people use very broken browser extensions, or user scripts, or browser, or entire computers, that throw exceptions left and right whenever the user looks at it wrong. Since browsers' security features and ResourceLoader's mechanisms often hide the real source of the error, you have to investigate everything by hand. And that's my experience only looking at errors happening on one page, on one wiki. :)