Newer
Older
minerva / Base / res / html / misc / unhandledpromisetest.html
@minerva minerva on 13 Jul 866 bytes Initial commit
<!DOCTYPE html>
<html>
<head>
  <title>Unhandled Promise rejection with no [[ScriptOrModule]] for the current execution context</title>
</head>
<body>
  <button onclick="
    Promise.reject(new Error('Success!'));
    window.timer = setTimeout(() => {
      const element = document.createElement('p');
      element.innerText = 'Did not receive unhandledrejection event in 100ms.';
      element.style.color = 'red';
      document.body.appendChild(element);
    }, 100)
  ">
    Click me to cause an unhandled promise rejection.
  </button>

  <script>
    window.onunhandledrejection = (rejectionEvent) => {
      clearTimeout(window.timer);
      const element = document.createElement("p");
      element.innerText = rejectionEvent.reason.message;
      element.style.color = "green";
      document.body.appendChild(element);
    }
  </script>
</body>
</html>