1

I have this error handler but it doesn't set the textarea:

window.onerror = function (msg, url, lineNo, columnNo, error) {
  errorBox.value = msg;
  return true;
}

function throwError() {
    abc.abc = abc;
}
textarea {
   height: 100px;
   width: 90vw;
}
<textarea id="errorBox" /></textarea>

<button onclick="throwError()">Do something</button>

UPDATE:
So here is some new information using the example.

In the example press the Do Something button. It will show the error message in the console and the textarea on the page.

But if you open Firefox dev tools and type in throwError() in the console and run it it will write to the console but not to the text area.

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
1.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231
  • When I use the console it allows me to change the value using textarea.innerHTML = "hello world". But I changed it to use textarea.value = "test" and it still doesn't work. – 1.21 gigawatts Dec 05 '20 at 20:19
  • Please reopen this question and reread it – 1.21 gigawatts Dec 05 '20 at 20:20
  • So it seems to work in some cases. If you throw an error while the console is open it is not working. I've added an example. YOU MUST HAVE DEV TOOLS to try this. – 1.21 gigawatts Dec 05 '20 at 20:28
  • 1
    Thanks, the issue is reproducible now - it occurs in Chrome too. I think the issue is that the console is a strange somewhat-isolated environment, so when something throws inside it, it doesn't send an error event to the `window` - kind of like how userscripts and extensions are somewhat separate from the original page. If you throw from anywhere else other than the console, it appears to fire the event. Injecting a script tag instead of typing into the console would probably result in the error being seen. – CertainPerformance Dec 05 '20 at 21:05
  • @CertainPerformance thank you for reproducing it. it will be ok for my scenario in this case since it is specifically to alert the web developer when dev tools are NOT available. Sort of like a check engine light. It / window.onerror doesn’t seem to catch network errors so I’ll have figure that out next. – 1.21 gigawatts Dec 05 '20 at 21:23

0 Answers0