Open Bug 1642147 Opened 4 years ago Updated 1 month ago

preventDefault does not work for unhandledrejection event

Categories

(Core :: DOM: Core & HTML, defect, P3)

defect

Tracking

()

People

(Reporter: evilpie, Unassigned)

References

()

Details

Attachments

(1 file)

It seems like the code add for dispatching unhandledrejection events intentionally ignores preventDefault and will always trigger a error message in the console: https://searchfox.org/mozilla-central/rev/d9d492eda787a6eda66016e6f8398ee759f7bc25/xpcom/base/CycleCollectedJSContext.cpp#709-710

Chrome will however prevent logging when preventDefault() is called in the event handler.

Flags: needinfo?(echen)
Attached file test.html

The error message in the console is from https://searchfox.org/mozilla-central/rev/0e09b9191c02097034e46b193930f91c45b7885d/dom/promise/PromiseDebugging.cpp#277 and suppress if onLeftUncaught callback of UncaughtRejectionObserver returns true. Right now UncaughtRejectionObserver is handled independently with the unhandled event, there is no easy way to suppress the error from event.preventDefault(). However, I could try to handle them together if possible, but after my other works.

Assignee: nobody → echen
Severity: -- → S3
Flags: needinfo?(echen)
Priority: -- → P3

Won't work on this in a short time.

Assignee: echen → nobody

can reproduce behavior on 112.0.2. This break MDN's description:

Many environments (such as Node.js) report unhandled promise rejections to the console by default. You can prevent that from happening by adding a handler for unhandledrejection events that—in addition to any other tasks you wish to perform—calls preventDefault() to cancel the event, preventing it from bubbling up to be handled by the runtime's logging code.

And Chrome handles this correctly (as described by MDN).

I am on mac with firefox 124.0.2.
The bug is still reproductible. Any progress on this issue ?
Is there a workaround to this ?
I am using the unhandledrejection event to call preventDefault() on controlled exceptions. Still logging in the console

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: