Closed Bug 1412485 Opened 7 years ago Closed 5 years ago

Consider removing some parts of touch event APIs on desktop

Categories

(Core :: DOM: Events, enhancement, P2)

enhancement

Tracking

()

VERIFIED FIXED
mozilla67
Tracking Status
relnote-firefox --- -
firefox57 --- unaffected
firefox65 --- wontfix
firefox66 --- wontfix
firefox67 --- verified

People

(Reporter: stone, Assigned: smaug)

References

(Blocks 1 open bug)

Details

(Keywords: dev-doc-complete, parity-chrome, site-compat, Whiteboard: [webcompat])

Attachments

(3 files)

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.
Priority: -- → P2
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).

http://mozilla.pettay.fi/moztests/touchmove.html
So looks like no touchevent on either Chrome or Edge. Time to think about removing it.

Flags: webcompat?
Whiteboard: [webcompat]

This touchevent issue also breaks embedded Soundcloud players on touchscreen laptops. You can seek in the player using touch events, but not mouse clicks.

e.g. http://www.openculture.com/2015/10/postage-stamps-from-bhutan-that-double-as-playable-vinyl-records.html

Keywords: parity-chrome
Assignee: nobody → bugs

Chrome hides just parts of the API.

Summary: Consider removing touch event APIs on desktop → Consider removing some parts of touch event APIs on desktop

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.

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.

Keywords: site-compat
Pushed by opettay@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/19d1f6485a13
disable legacy touch APIs on desktop, r=masayuki
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla67
Depends on: 1533413
No longer depends on: 1533413

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.

Status: RESOLVED → VERIFIED

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?

Flags: needinfo?(bugs)

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."

Flags: needinfo?(bugs)

(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.

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.

Sounds like this is mentioned in the MDN page for 67 not the main user-facing release notes.

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.

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.

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.

Flags: needinfo?(nikle)

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.

Flags: needinfo?(nikle)

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.

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.

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.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: