Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught exceptions thrown asynchronously are not handled by window.onerror #1030

Closed
joeframbach opened this issue Aug 25, 2023 · 1 comment · Fixed by #1044
Closed

Uncaught exceptions thrown asynchronously are not handled by window.onerror #1030

joeframbach opened this issue Aug 25, 2023 · 1 comment · Fixed by #1044
Assignees
Labels
bug Something isn't working

Comments

@joeframbach
Copy link

Describe the bug

If an uncaught exception is thrown inside a setTimeout or other async context, then window.onerror does not handle it.

To Reproduce

Execute the script:

var HappyDom = require('happy-dom');
new HappyDom.Window().document.write(`<!doctype html>
  <script>
    window.onerror = function (error) {
      console.log('intercepted error:', error);
      return true;
    };
    setTimeout(function () {
      throw new Error('oops!');
    });
  </script>
`);

and see the output throws Error: oops! at evalmachine.<anonymous>:7:13.

Expected behavior

Expected to see intercepted error: oops! and not escape the VM.

Screenshots
If applicable, add screenshots to help explain your problem.

N/A

Device:

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

happy-dom 10.11.0

Additional context
Add any other context about the problem here.

https://developer.mozilla.org/en-US/docs/Web/API/Window/error_event

@joeframbach joeframbach added the bug Something isn't working label Aug 25, 2023
@capricorn86 capricorn86 self-assigned this Aug 30, 2023
capricorn86 added a commit that referenced this issue Sep 6, 2023
…s errors in scripts, event listeners and timers. Adds a new package called "@happy-dom/uncaught-exception-observer". Adds a new virtual console that by default will output all log entries to a virtual console printer instead of using the global NodeJS console.
@capricorn86
Copy link
Owner

Thank you for reporting @joeframbach! 🙂

I did not realize that you reported this issue as well until now.

The fix is released now.

You can read more about it here:
https://github.com/capricorn86/happy-dom/releases/tag/v11.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants