dom
dom copied to clipboard
Property to distinguish whether listener is passive or no/event is preventable
Linking issue from interventions WICG repo to keep continuity: WICG/interventions#63.
Summarizing:
There is no way to distinguish (from inside of the listener) whether event can be cancelable or no (or simpler - if preventDefault can be fired) - unfortunately cancelable property, which is available in the event object doesn't give any info about that (at least in scenario of passive listener).
Proposal would be to change a bit conditions under which cancelable is set to false (to cover passive listener scenario) or to add to the event object a new property (e.g. 'preventable') which will always go along with the real possiblity to stop the event.
There is also another solution here - to allow implementers to run preventDefault without console.error being raised at all or with possibility to silence this kind of warning message. For more context please have a look here: https://github.com/WICG/interventions/issues/63#issuecomment-380232353
Internally in Gecko Event objects do have a flag whether they are being handled by a passive listener. We could expose that to JS. It would be a rather ugly API (since Event shouldn't care or know about the listener), but perhaps practical?