Consider removing some parts of touch event APIs on desktop
Categories
(Core :: DOM: Events, enhancement, P2)
Tracking
()
Tracking | Status | |
---|---|---|
relnote-firefox | --- | - |
firefox57 | --- | unaffected |
firefox65 | --- | wontfix |
firefox66 | --- | wontfix |
firefox67 | --- | verified |
People
(Reporter: stone, Assigned: smaug)
References
Details
(Keywords: dev-doc-complete, parity-chrome, site-compat, Whiteboard: [webcompat])
Attachments
(3 files)
24.32 KB,
patch
|
Details | Diff | Splinter Review | |
39.99 KB,
patch
|
Details | Diff | Splinter Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review |
Chrome's going to do it: https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/KV6kqDJpYiE/YFM28ZNBBAAJ For web compatibility of those websites which assume touch = mobile, we should also consider disabling touch event APIs by default. So that those websites handle mouse events when browsing on a desktop with touchscreen supported. This doesn't stop firing touch events for gestures.
Reporter | ||
Updated•6 years ago
|
Comment 1•6 years ago
|
||
Note that we're proposing just removing the older-style feature detection APIs. Touch events will actually then work consistently on desktop otherwise (including detection via the most direct expression: 'TouchEvent' in window).
Comment 2•5 years ago
|
||
http://mozilla.pettay.fi/moztests/touchmove.html
So looks like no touchevent on either Chrome or Edge. Time to think about removing it.
Updated•5 years ago
|
![]() |
||
Updated•5 years ago
|
![]() |
||
Updated•5 years ago
|
Comment 3•5 years ago
|
||
This touchevent issue also breaks embedded Soundcloud players on touchscreen laptops. You can seek in the player using touch events, but not mouse clicks.
Assignee | ||
Updated•5 years ago
|
Assignee | ||
Comment 4•5 years ago
|
||
Chrome hides just parts of the API.
Assignee | ||
Comment 5•5 years ago
|
||
Current patch. Waiting for tryserver results still (try was closed earlier today). I expect some broken tests: cases when ontouch* is used, but now
addEventListener is needed.
Assignee | ||
Comment 6•5 years ago
|
||
remote: View your changes here:
remote: https://hg.mozilla.org/try/rev/679741986b9069fcb45b89be6ab5c5c41ceaa95f
remote: https://hg.mozilla.org/try/rev/39c942ebb3585081324ac509fddd5fdb8e5e185a
remote:
remote: Follow the progress of your build on Treeherder:
remote: https://treeherder.mozilla.org/#/jobs?repo=try&revision=39c942ebb3585081324ac509fddd5fdb8e5e185a
Assignee | ||
Comment 7•5 years ago
|
||
Assignee | ||
Comment 8•5 years ago
|
||
Hiding document.createEvent("TouchEvent"), document.createTouch, document.createTouchList and ontouch* event
handlers on desktop to follow what Chrome has done.
This patch explicitly does not remove createTouch or createTouchList everywhere, although those seem to have been
removing already on some other browsers.
Devtools use TOUCHEVENTS_OVERRIDE_ENABLED for touch event testing, and this patch keeps the old behavior per discussion
with devtools devs.
Updated•5 years ago
|
Updated•5 years ago
|
Pushed by opettay@mozilla.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/19d1f6485a13 disable legacy touch APIs on desktop, r=masayuki
Comment 10•5 years ago
|
||
bugherder |
Comment 11•5 years ago
|
||
Verified fixed. The New York Times and Soundcloud sites that I reported as broken on my Windows touchscreen laptop now work correctly in today's 67 Nightly.
Comment 12•5 years ago
|
||
I also confirmed that https://assessments.michaelhyatt.com/lifescore/assessment/ now works on a Windows touchscreen laptop.
Smaug, can you suggest a release note for beta 67?
Assignee | ||
Comment 14•5 years ago
|
||
Something like
"Hiding document.createEvent("TouchEvent"), document.createTouch, document.createTouchList and ontouch* event handlers on desktop with touchscreen to make it less likely that websites treat Firefox as a mobile user agent."
Comment 16•5 years ago
|
||
(In reply to Olli Pettay [:smaug] from comment #14)
Something like
"Hiding document.createEvent("TouchEvent"), document.createTouch, document.createTouchList and ontouch* event handlers on desktop with touchscreen to make it less likely that websites treat Firefox as a mobile user agent."
Exactly. The principle (as discussed on the referenced public-touchevents thread) is that these are all older-style APIs which have long been used across the web to identify a phone form factor. There's no problem with touch events themselves, just the specific feature-detection pattern sites have come to rely on and make assumptions about. Although it's a little hacky (as web compat concessions always are), this distinction is key to the change we made in Chrome - letting us remove much hackier / less reliable hacks about where touch events are and are not supported.
Comment 17•4 years ago
|
||
Note to MDN writers: I've mentioned this in the Fx67 rel notes: https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Releases/67#Removals_6
In terms of other work, you should porbably explain this in more detail somewhere, and update BCD.
Comment 18•4 years ago
|
||
I've filed https://github.com/mdn/browser-compat-data/pull/4095 to update the BCD.
Comment 19•4 years ago
|
||
Posted site compatibility note: https://www.fxsitecompat.com/en-CA/docs/2019/legacy-touch-events-api-is-now-disabled-on-desktop/
Comment 20•4 years ago
|
||
Sounds like this is mentioned in the MDN page for 67 not the main user-facing release notes.
Comment 21•4 years ago
|
||
https://github.com/mdn/browser-compat-data/pull/4095 is merged, and I've added a paragraph about this here:
https://developer.mozilla.org/en-US/docs/Web/API/Touch_events#Browser_compatibility
I'm marking this as dev-doc-complete, but please let me know if you spot anything wrong or missing here.
Comment 22•4 years ago
|
||
We just noticed that the detection we use for touchevents in our JavaScript code now works in Firefox 74 (in Windows 10 on both laptop and desktop) and I'm wondering if it's intended? We use 'ontouchstart' in window and document.createEvent('TouchEvent') to detect this.
I just wanted to check if the plans described in https://developer.mozilla.org/en-US/docs/Web/API/Touch_events still holds true? That pointer events are to be preferred if we want to support touch and mouse across all types of devices.
Assignee | ||
Comment 23•4 years ago
|
||
Niko, has something changed recently? I can't quite interpret what "now works in Firefox 74" means? This bug was fixed long ago for Firefox 67.
dom.w3c_touch_events.legacy_apis.enabled which controls some parts of the Touch API should be disabled on desktop
(see about:config )
Pointer events are the preferred way to deal with touch and mouse.
Comment 24•4 years ago
|
||
Sorry for being a bit unclear on that point. This detection did not work back in Firefox 69 so I filed a bug (https://bugzilla.mozilla.org/show_bug.cgi?id=1587760) and back then it 'worked as intended'. So I just wanted to make sure nothing had changed since then before I start working on using pointer events instead.
Our detection works on desktop with Firefox 74, even with dom.w3c_touch_events.legacy_apis.enabled set to false.
Assignee | ||
Comment 25•4 years ago
|
||
So depends on what detection you want. ontouchstart isn't supposed to work, nor document.createEvent("TouchEvent"); on desktop.
"TouchEvent" in window
should be true on desktop/laptop which has touchscreen.
What does "Our detection works on desktop with Firefox 74, even with dom.w3c_touch_events.legacy_apis.enabled set to false." mean?
That pref disables some parts of the API, not all.
Comment 26•4 years ago
|
||
I re-checked and noticed ontouchstart indeed doesn't work. It was another part of the check that passed this time.
Thank you for the answers and sorry for the inconvenience.
Comment 27•4 years ago
|
||
There seems to be some confusion here, the three ways to work with touch seems to be:
- ontouch
- addEventListener with touchstart etc.
- pointer events
What both fxsitecompat* and MDN web docs** says is that 'ontouch' is not to be used any more.
However fxsitecompat states that addEventListener still works with touchstart (which can make our implementation work with small tweaks) while MDN makes it sound that only pointer events will work.
The removal of ontouch is in line what chrome*** has done too, but they seem to keep addEventListener support still.
Is it planned to remove addEventListener for touchstart etc. or can we continue to use these instead of migrating fully to pointer events?
It seems wasteful to rewrite all our code if addEventListener will continue to work.
- fxsitecompat: https://www.fxsitecompat.dev/en-CA/docs/2019/legacy-touch-events-api-is-now-disabled-on-desktop/
** MDN: https://developer.mozilla.org/en-US/docs/Web/API/Touch_events#Browser_compatibility
*** Chrome: https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/KV6kqDJpYiE/YFM28ZNBBAAJ
Comment hidden (spam) |
Comment hidden (spam) |
Description
•