Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Default to passive: true on document level wheel/mousewheel event listeners #64

Closed

Description

@sahel-sh

Chromium/Blink would like to propose an intervention where the passive option for wheel/mousewheel event listeners added to Document level objects would be true by default. To opt out developers can explicitly specify passive: false when they want to prevent scrolling/zooming.

This intervention is the wheel equivalent of touch scroll intervention which is implemented by Chrome (since M56), Safari1, and Firefox2.

Our statistics show that:

  • On Windows and Mac platforms scrolling by mouse wheel (and touchpad) accounts for more than 90% and 96% of scrolling respectively.
  • 75% of the wheel event listeners added to a Document level element do not specify passive option and more than 98.5% of such listeners do not call preventDefault().

See more details in Document Level Passive Wheel Event Listener Intervention


1: Tried on Safari 11 (IOS 11.4)
2: Tried on Firefox 61

Activity

  1. hober commented on Dec 10, 2018

    @hober
  2. sahel-sh commented on Jan 2, 2019

    @sahel-sh
    Author
  3. sahel-sh commented on Jan 2, 2019

    @sahel-sh
    Author

    /cc @ChumpChief

    Since high precision touchpad scrolling on Edge is already not blocked on wheel events. Edge might be implicitly in favor of the intervention.

  4. ChumpChief commented on Jan 2, 2019

    @ChumpChief

    Yes, Edge is in favor. I've seen too many analytics libraries throwing benign wheel listeners on the document :)

    I'd guess most pages with document-level preventDefaults are also non-scrollable, since it's weird for a user to see overflowing content and a scrollbar but not be able to scroll with mousewheel. Maybe some "parallax" sites that eat the wheel to apply their own physics/animation? Even with this intervention these probably function approximately as expected if setting scrollTop in script wins over the scroll animation.

    That said, I'm now observing that in Chrome the scroll animation wins over setting scrollTop in script. Is that expected? Is there a means for a developer to halt an in-progress scroll animation in Chrome?

    http://jsfiddle.net/gcxof62e/

    You might want to consider changing this behavior to match Edge/FF to further reduce the compat risk of the intervention.

    P.S. Precision Touchpad doesn't fire any wheel events in Edge so it's perhaps not quite fair to compare against. But regardless this intervention seems good.

  5. staktrace commented on Jan 2, 2019

    @staktrace

    I don't have any objections to this intervention either. It should be straightforward to implement in FF as well.

  6. sahel-sh commented on Jan 4, 2019

    @sahel-sh
    Author

    That said, I'm now observing that in Chrome the scroll animation wins over setting scrollTop in script. Is that expected? Is there a means for a developer to halt an in-progress scroll animation in Chrome?

    Since M65 Chrome is handling wheel events asynchronously: https://www.chromestatus.com/feature/5728708706959360
    In http://jsfiddle.net/gcxof62e/ if the developer wants to set document.scrollingElement.scrollTop they should preventDefault the wheel event and specify that the event listener is blocking.

  7. ChumpChief commented on Jan 4, 2019

    @ChumpChief

    Love the scroll latching and async events :)

    This is a slightly different point though - regardless of whether a developer is setting scrollTop in response to the wheel event or in response to something else, it seems that developer cannot interrupt the animation.

    In this specific case, the compatibility risk I'm highlighting is for document-level script takeover of scrolling (e.g. maybe Nicescroll would be an example). Since these are not specifying passive: false today, I suspect the script-driven scroll animation might fight with the native scroll animation for some strange visual effects. Whereas if setting scrollTop halts the native scroll animation like in Edge and FF, then I suspect the script-driven scroll animation would be able to take over from the native animation and function mostly as expected (maybe barring a frame or two of native scrolling animation), potentially partially mitigating that compatibility risk.

    In any case, I'm in favor of the intervention. Just offering a suggestion in case issues are discovered on that type of construction.

  8. sahel-sh commented on Jan 4, 2019

    @sahel-sh
    Author

    Love the scroll latching and async events :)

    This is a slightly different point though - regardless of whether a developer is setting scrollTop in response to the wheel event or in response to something else, it seems that developer cannot interrupt the animation.

    In this specific case, the compatibility risk I'm highlighting is for document-level script takeover of scrolling (e.g. maybe Nicescroll would be an example). Since these are not specifying passive: false today, I suspect the script-driven scroll animation might fight with the native scroll animation for some strange visual effects. Whereas if setting scrollTop halts the native scroll animation like in Edge and FF, then I suspect the script-driven scroll animation would be able to take over from the native animation and function mostly as expected (maybe barring a frame or two of native scrolling animation), potentially partially mitigating that compatibility risk.

    In any case, I'm in favor of the intervention. Just offering a suggestion in case issues are discovered on that type of construction.

    I understand your concern about the fight between script-driven scroll animation and the native scroll animation which is the current behavior of Chrome and Firefox (tried http://jsfiddle.net/gcxof62e/ on 60.2.0esr (64-bit))
    However this intervention won't change/add any compatibility risks: Regardless of the value of the passive option, even in cases that it used to be false by default and this intervention changes it to be true, with async wheel events if the first wheel event is not prevented by default the rest of the wheel events in the current scroll sequence are not cancelable and the fight between script-driven scroll animation and the native scroll animation will happen anyway with our without this intervention.

  9. pauljohnknight commented on Mar 19, 2019

    @pauljohnknight

    Hi

    Since this has been implemented it has broken a number of smooth-scroll plugins / libraries that remove the 'judder' created by a traditional mouse wheel when scrolling on Chrome.

    How would you set explicitly set passive: false as mentioned in the original post on this thread via javascript, as a stand-alone function (to save me going through all the code of a plugin finding where best to place it)?

    Any help would be wonderful.

    Paul.

  10. grorg commented on Apr 24, 2019

    @grorg

    Maybe I don't understand how this repository is supposed to work. Have Chrome/Blink + Firefox implemented this intervention? If so, why is this issue still open?

    My specific question is whether WebKit should do it now, but my general question is how to know what the state of an intervention issue proposed here is.

  11. bzbarsky commented on Apr 24, 2019

    @bzbarsky
  12. sahel-sh commented on Apr 24, 2019

    @sahel-sh
    Author

    ...

    Chrome extension developers prevent this issue by calling e.preventDefault() on zoom document level zoom events so the zoom level across all documents stays the same, but because this breaking change is shipped, all chrome extensions that relied on e.preventDefault() for preventing zoom events are now broken!
    ...
    Above issue was opened on 26 May 2016 , but support for passive events is still not there as of 2019 this just shows it can take months, sometimes years to get these breaking changes to work well with the existing apps and extensions.

    I am sorry that your extensions are negatively impacted by the intervention. However e.preventDefault() is not broken:
    If a document level wheel event listener needs to call e.preventDefault() for wheel events to keep the zoom level the same, it should get declared as blocking using the {passive:false} option. Please check this developer's guide for more details:
    https://developers.google.com/web/updates/2019/02/scrolling-intervention You can also file a bug using https://crbug.com/wizard and provide and example extension to get better guidance.

    Please not that the intervention for touchmove and touchend has been shipped in chrome 56, and implemented by Edge, Firefox, and Safari layer on. This new issue (opened on Dec 2018) is for wheel events.

  13. sahel-sh commented on Apr 24, 2019

    @sahel-sh
    Author

    /cc @NavidZ for follow up since I am not working on this project any longer.

  14. NavidZ commented on Apr 25, 2019

    @NavidZ
    Member

    It is not the static sites like CNN that you used in the demo that are affected, it is the SPAs, Chrome apps, Chrome Extensions, Electron apps, JavaScript transpilers that are severely affected, does your team take all the above into consideration when you implement breaking changes like the above?

    We certainly considered all the URLs that this intervention might have broken. That will include all the sites including the ones with Javascript transpilers. We also worked with popular frameworks to get this handled on their side such as react.

    Looking at the previous breaking changes your team has made, your team does not care about robustness, all they care about is raw performance on mobile devices achieved at the expense rest of the web.

    Refactoring all event listeners across all projects will definitely take some time but does your team give enough time for everybody to catch up and implement the change? In 2017 when you made changes to the touch events, Google's own projects were broken.

    We do our best in terms of consulting all developers and other browser vendors through GitHub issues, blogposts, console warnings, and whatnot. One of the problems with improving web in general is that there will be always a long tail of websites/usecases that might never go away. We just have to make a call and say if a particular legacy feature usage has gone lower than a very very small threshold that will be good enough to change to make the overall performance of the rest of the web better. It is like breaking a very small percentage of the usecases to get a better performance for the rest of the web.
    We understand being in that small portion of the population is frustrating but consider a lot of other interventions that you were not on that small portion and your app got the benefit without noticing anything.

    I'm still not sure about your particular usecase to dig further and suggest any other actions for you. But just as another workaround (not sure whether it applies to your usecase or not) you could try having your listener not on the document but in a more nested element. That way it is not going to be affected by this intervention until more frameworks add the support for event listener options.

  15. NavidZ commented on May 16, 2019

    @NavidZ
    Member

    @drbcode as we fixed the bug you reported I assume now your use case is addressed. Is that fair enough or do you have other concerns?

  16. NavidZ commented on May 17, 2019

    @NavidZ
    Member

    I'm glad to see your issue fixed. Please feel free to file bugs and be vocal when you seen something wrong and we can always look into them and discuss solutions and workarounds.

  17. jabcreations commented on Sep 1, 2019

    @jabcreations

    This should not be implemented. This breaks GUI fixes (Gecko is blatant GUI breaker and most GUI bugs/regressions are not fixed). This will make gecko even more unbearable to program with and make engines that do not implement this more cooperative for UX.

    In example I've ensured that in competent browsers that the X and Y axis scrolling while hovering range type input elements adjusts the input's value. However in Blink/Chrome if the parent element has a scrollbar it will scroll losing focus thereby negating the user's intuition to use their scrollwheel.

    You are literally advocating that that you know better than web authors and I can dig up two decades worth of almost entirely ignored bug reports to show Mozilla is only further alienating the people who actually know WTF we're doing.

    Stop dictating what you think web authors should be "allowed" to do.

    Stop blindly copying Google.

  18. bokand commented on Sep 10, 2019

    @bokand

    Web authors can still use non-passive listeners and call preventDefault by specifying passive: false in the event listener. This only changes defaults which will impact legacy pages that don't update. While that's a concern, the trade-off has been carefully considered.

  19. foolip commented on May 19, 2021

    @foolip
    Member

    What is the status of getting this behavior into a spec? In whatwg/dom#365 (comment) it was noted that we have tests for this in WPT, but seemingly no spec, so I've renamed the test in web-platform-tests/wpt#29039.

  20. bokand commented on May 19, 2021

    @bokand
  21. johannhof commented on Jun 16, 2022

    @johannhof
    Member

    (As noted in #72, we intend to archive this repository and are thus triaging and resolving all open issues)

    As noted in #35 I think we can continue to track this work under whatwg/dom#365, see whatwg/dom#365 (comment)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions