'Global error handling in Nuxt.js using onerror on other methods

I have a website which uses Nuxt.js. I want to implement global error handling when an error or uncaught error occurs.

I have injected the below script to head and also used it as plugin, but it does not work!

<script>

 window.onerror = function (e) {
    console.log('### Here I am ###', e)
    return true
 }

  window.addEventListener('error', ...)

</script>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source