Closed Bug 1642147 Opened 6 years ago Closed 2 months ago

preventDefault does not work for unhandledrejection event

Categories

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

defect

Tracking

()

RESOLVED FIXED
154 Branch
Tracking Status
firefox154 --- fixed

People

(Reporter: evilpies, Assigned: jjaschke)

References

()

Details

Attachments

(2 files)

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

From https://html.spec.whatwg.org/multipage/webappapis.html#unhandled-promise-rejections:

This algorithm results in promise rejections being marked as handled or not handled. These concepts parallel handled and not handled script errors. If a rejection is still not handled after this, then the rejection may be reported to a developer console.

Firefox ignores the standard and sends spam to the console.

Beyond the console spam which is annoying, this actively hinders automated testing: generally if an error bubbles up to the console / test runner it's a failure, here if the system makes use of preventDefault (generally specifically to test error paths) the test will fail on firefox, and requires significant alterations to the behaviour of the runner in order to work around the lack of a behaviour mozilla itself documents.

I kindly ask you to consider this mistake in 2025.

I renew my request in 2026

Assignee: nobody → jjaschke
Status: NEW → ASSIGNED
Pushed by sstanca@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/22142cab1d26 https://hg.mozilla.org/integration/autoland/rev/57b47548f41f Revert "Bug 1642147 - Respect preventDefault() on unhandledrejection for console reporting. r=edgar" for causing devtools failures in browser_jsterm_await_error.js.

Reverted this because it was causing devtools failures in browser_jsterm_await_error.js.

Flags: needinfo?(jjaschke)
Regressions: 2053953

Sorry for keeping you waiting for so long. I hope this works, if it doesn't please feel free to file a new bug and needinfo me. :)

Flags: needinfo?(jjaschke)
Status: ASSIGNED → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → 154 Branch
QA Whiteboard: [qa-triage-done-c155/b154]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: