1

I want to show an error message if a error occours inside a script proved by an user. Example:

function one() { consolef.log("async"); }
async function two() { consolef.log("async"); }

one();
await two();

window.onerror fires only on one() but not on two():

window.onerror = function(msg, url, lineNo, columnNo, error) {
  var string = msg.toLowerCase();
  if (string.indexOf(substring) > -1) {
    alert('Script Error: See Browser Console for Detail');
  } else {
    console.log('Error showed in browser view');
    document.body.innerHTML += ` <div class = "alert alert-danger" >` + error + ` < /a>. </div>`;
  }

  return false;
};

Both errors are shown inside console but only one() in the browser.

Edit: I was pointed to 1 and 2. But both suggest to use onrejectionhandled and onunhandledrejection but both functions are not supported by Firefox. So I can't use these functions for all users.

0 Answers0