0

the exact HTML page posted below will invoke the unhandledrejection handler when running on Firefox (observed on 78.12.0esr (64-bit) ), but not on Chrome (observed on 92.0.4515.131 (Official Build) (64-bit)), why? both browsers are up-to-date today, 2021-08-06

https://jsfiddle.net/vt6z9n5g/1/

<!DOCTYPE HTML>
<html><head><meta charset="utf-8"> </head><body>
<script>

window.addEventListener("error",function(ex){
    let msg="error handler invoked! addEventListener";
    console.log(msg);
    alert(msg);
});
window.addEventListener("unhandledrejection", function (ex) {
  let msg="unhandledrejection handler invoked! addEventListener";
  console.log(msg);
  alert(msg);  
});


(async function(){
   let foo= ((await ( await fetch("/no_json_plz_i_want_an_error")).json()));
})()//.catch(function(error){ throw error; });

</script>
</body></html>
hanshenrik
  • 19,904
  • 4
  • 43
  • 89
  • that is odd - chrome implemented `unhandledrejection` event long before firefox - maybe there's a bug in the current release of chrome - it'll probably be fixed in the next release – Bravo Aug 06 '21 at 12:52
  • 1
    [Issue 1219363 - JSON parse syntax errors not caught by onerror and unhandledrejection - chromium](https://bugs.chromium.org/p/chromium/issues/detail?id=1219363&q=unhandledrejection&can=2) – Andreas Aug 06 '21 at 12:55
  • yeah, coz just having `Promise.reject('bang')` in firefox and chrome triggers the event – Bravo Aug 06 '21 at 12:58
  • 1
    @Andreas haha you could probably post that as the answer ^^ – hanshenrik Aug 06 '21 at 12:58
  • The status is still _unconfirmed_. Might be the problem, but... – Andreas Aug 06 '21 at 13:03
  • @Andreas - it's definitely the problem, because just having a `Promise.reject()` does trigger the event handler – Bravo Aug 06 '21 at 13:04
  • [Why “unhandledrejection” can't caught an error from JSON.parse()?](https://stackoverflow.com/questions/68356441/why-unhandledrejection-cant-caught-an-error-from-json-parse) – Andreas Aug 06 '21 at 13:11

0 Answers0