This version is old school.
Please find jQuery plugins on npm.
jQuery Error Logger
by Dean Vaughan
A simple jQuery logging plugin to log exceptions and send them to your API instantly or periodically. If you opt for the periodic option it will store the errors in localstorage and then post them to your server based on the interval you choose.