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

addEventListener - which browsers/events default to passive #24181

Closed
redblobgames opened this issue Feb 5, 2023 · 7 comments · Fixed by #32930
Closed

addEventListener - which browsers/events default to passive #24181

redblobgames opened this issue Feb 5, 2023 · 7 comments · Fixed by #32930

Comments

@redblobgames
Copy link

redblobgames commented Feb 5, 2023

MDN URL

https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener

What specific section or headline is this issue about?

Improving scrolling performance with passive listeners

Documentation of which browsers default to passive

What information was incorrect, unhelpful, or incomplete?

The page says "browsers other than Safari and Internet Explorer" default certain events to passive, suggesting Chrome and Firefox do this. But it seems to be Chrome and Safari that default those events to passive.

This is also mentioned in the description of the passive flag.

What did you expect to see?

I expect it to say "Chrome and Safari change the default value of the passive option to true for {wheel, mousewheel, touchstart, touchmove}".

Do you have any supporting links, references, or citations?

I looked up the history of the touch events defaulting to passive:

  1. 2017 https://developer.chrome.com/blog/scrolling-intervention/ Chrome says they will default touchstart, touchmove to passive
  2. 2018 Touch listeners defaulting to passive WICG/interventions#18 (comment) Safari defaults touch events to passive

I've also tested the touchstart event myself to see if .cancelable is set, and

  • iOS 16.3/Safari: it's false (implying passive)
  • Android/Chrome 109: it's false (implying passive)
  • Android/Firefox 109: it's true (implying not passive)

Separately, wheel events:

  1. 2019 https://developer.chrome.com/blog/scrolling-intervention-2/ Chrome says they will default wheel events to passive, but also says that Firefox implemented the touchstart passive already (which doesn't match my tests)

I tested the wheel event to see if .cancelable is set, and

  • Mac/Safari 16.3: it's false (passive)
  • Mac/Chrome 109: it's false (passive)
  • Mac/Firefox 109: it's true (not passive)

So here too it seems to be Chrome and Safari that default to passive, not "browsers other than Safari and Internet Explorer".

Do you have anything more you want to share?

I'm happy to make a pull request but thought I should file an issue first.

MDN metadata

Page report details
@redblobgames redblobgames added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Feb 5, 2023
@github-actions github-actions bot added the Content:WebAPI Web API docs label Feb 5, 2023
@wbamberg
Copy link
Collaborator

wbamberg commented Feb 6, 2023

Thanks for filing, @redblobgames , and for your analysis.

It's better for maintainability for us to minimize references to browser support in the main body of the page, and refer to the browser compat tables for that. So as for the prose of this article, I think it would be better to say something like:

To prevent that problem, browsers other than Safari and Internet Explorer have changed the default value of the passive option ... For details of browser support for this behavior, see the browser compatibility table.

But from your description it also sounds like the BCD table is wrong? The table claims everyone except Safari supports this behavior, but your description suggests that it should be everyone except Firefox.

Having said that it does look like this was implemented in Firefox, e.g.:
https://bugzilla.mozilla.org/show_bug.cgi?id=1449268
https://bugzilla.mozilla.org/show_bug.cgi?id=1673278

@sideshowbarker sideshowbarker removed the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Feb 8, 2023
@redblobgames
Copy link
Author

I agree, browser compat tables are a better place for this. I had thought Firefox didn't implement the default passive but I was wrong. I ran some more tests here.

I had been testing a proxy for active/passive — the cancelable property on Event. This "should" tell me if it's passive, but it doesn't. I ran my tests again, this time attempting to .preventDefault() to see if I was able to prevent scrolling. Firefox does not allow me to .preventDefault(), but the event is marked .cancelable = true. Related bug

There's also web platform tests and more but I am not sure how to interpret these

I am thinking we should change the BCD table to mark Safari as supporting "options.passive parameter defaults to true". It looks like every current browser now behaves this way. Internet Explorer does not but it's no longer in the BCD.

Then we could remove the "browsers other than Safari and Internet Explorer have changed the default value…" text to say "browsers have changed the default value…" (or maybe "current browsers"? "modern browsers"? not sure what to say here)

@wbamberg
Copy link
Collaborator

I am thinking we should change the BCD table to mark Safari as supporting "options.passive parameter defaults to true". It looks like every current browser now behaves this way. Internet Explorer does not but it's no longer in the BCD.

Then we could remove the "browsers other than Safari and Internet Explorer have changed the default value…" text to say "browsers have changed the default value…" (or maybe "current browsers"? "modern browsers"? not sure what to say here)

We usually say "modern browsers" here. And yes, I think this is right:

  • update BCD to fix Safari behavior
  • update the page:
    • change "browsers other than Safari and Internet Explorer" to something like "modern browsers set passive to true for the wheel ..."
    • delete the note
    • remove "in all browsers" in the next paragraph.

Do you want to contribute these fixes? If not, no problem, we will take care of it.

@redblobgames
Copy link
Author

While I'm happy to contribute a pull request (or maybe two, as the compat tables seem to be in a separate repository), I'm even happier if someone else does it ;-)

@estelle
Copy link
Member

estelle commented Apr 2, 2024

This issue seems to have been addressed. @redblobgames @wbamberg Is it OK to close?

@wbamberg
Copy link
Collaborator

wbamberg commented Apr 2, 2024

No, this isn't fixed, it looks like I was going to add it into #29083 but it got merged before I got around to it. But I will take care of it now.

@wbamberg
Copy link
Collaborator

wbamberg commented Apr 2, 2024

Ah, but it looks like the BCD did get updated: mdn/browser-compat-data#21523 . Yay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants