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

[Feature] Support for touch events/gestures #2903

Open
arjunattam opened this issue Jul 10, 2020 · 38 comments
Open

[Feature] Support for touch events/gestures #2903

arjunattam opened this issue Jul 10, 2020 · 38 comments

Comments

@arjunattam
Copy link
Contributor

Web apps running on touch devices (e.g, mobile and Surface) rely on touch gestures like swiping and pinching to zoom. While page.dispatchEvent can manufacture synthetic touch points, having a simpler API would improve the dev experience.

Scenarios

  1. Two-finger pinch to zoom in/out on a particular element (e.g., canvas in Azure ML designer)
  2. Verify that two-finger left/right swipe is not leading to go back/forward
@JoelEinbinder JoelEinbinder self-assigned this Jul 27, 2020
@pavelfeldman pavelfeldman added v1.4 and removed v1.3 labels Aug 4, 2020
@roune
Copy link

roune commented Aug 14, 2020

It would also be interesting a feature to tap on certain elements or coordinates as Puppeteer allowed.
Simple code as:
await page.tap('div.example)
await element.tap()

@olexandr13
Copy link
Contributor

olexandr13 commented Feb 4, 2021

+swipe

@bonkalol
Copy link

bonkalol commented Mar 22, 2021

+for swipe

@sergioariveros
Copy link

+1 swipe

@eJayYoung
Copy link

is there some quick-access to achieve touch move in mobile, etc popup picker

@egreen0
Copy link

egreen0 commented Mar 4, 2022

Having the ability to swipe, dragto, or even replicate the mouse class for touchscreen would be great. If I could use the touchscreen class to move, press down, move, and unpress, it would take care of a lot of issues that I'm currently having with dragging elements.

@blimmer
Copy link

blimmer commented Mar 15, 2022

I found this issue because I wanted to be able to drag an element using touch events as described in #12599. It looks like I might be able to dispatch the events (see #6072) but it'd be nice to just say "dragto" and have it do the proper touchstart, touchmove and touchend behaviors for me.

@dk-carma
Copy link

+1 for swipe action

@sijakret
Copy link

+1 for overall possibility to automate touch

1 similar comment
@mapau
Copy link

mapau commented May 12, 2022

+1 for overall possibility to automate touch

@nnson0310
Copy link

+1 for native mobile gestures like swipe

@MRamonLeon
Copy link

Is this experimental API (https://playwright.dev/docs/api/class-androidinput) an attempt to implement this feature? I didn't test it yet.

@Orbisti
Copy link

Orbisti commented May 26, 2023

+swipe

Tried a workaround with Touchevent, but I'm getting two touch points on the start and the end coordinates. Probably I messed up something.

        await page.evaluate(
            ([startX, startY, endX, endY]) => {
                const touchStartEvent = new TouchEvent("touchstart", {
                    bubbles: true,
                    cancelable: true,
                    composed: true,
                    touches: [new Touch({ identifier: 1, target: document.documentElement, clientX: startX, clientY: startY })],
                });
                document.elementFromPoint(startX, startY).dispatchEvent(touchStartEvent);

                const touchMoveEvent = new TouchEvent("touchmove", {
                    bubbles: true,
                    cancelable: true,
                    composed: true,
                    touches: [
                        new Touch({ identifier: 1, target: document.documentElement, clientX: startX, clientY: startY }),
                        new Touch({ identifier: 2, target: document.documentElement, clientX: endX, clientY: endY }),
                    ],
                });
                document.elementFromPoint(startX, startY).dispatchEvent(touchMoveEvent);

                const touchEndEvent = new TouchEvent("touchend", {
                    bubbles: true,
                    cancelable: true,
                    composed: true,
                    touches: [],
                });
                document.elementFromPoint(startX, startY).dispatchEvent(touchEndEvent);
            },
            [startX, startY, endX, endY]
        );

@RatexMak
Copy link

+1 for simulating long press on mobile device

@Exordio
Copy link

Exordio commented Dec 14, 2023

damn this is really needed. Please implement this :)

@cctui-dev
Copy link

+1 for swipe/touch events please :)

@ant0d0v
Copy link

ant0d0v commented Dec 25, 2023

+1 for swipe

2 similar comments
@Mark-770
Copy link

+1 for swipe

@artus9033
Copy link

+1 for swipe

@Kostya4ki
Copy link

+1 for all mobile gestures

@agray
Copy link

agray commented Feb 18, 2024

+1 swipe!

@dr3adx
Copy link

dr3adx commented Feb 19, 2024

playwright devs lazy as fuk, still not added after 3 years

@MillerSvt
Copy link

+1

@ml4725
Copy link

ml4725 commented Mar 20, 2024

+1 for simulating long press on mobile device

@IPRIT
Copy link

IPRIT commented Mar 21, 2024

+1

@GarimaGuptaRDC
Copy link

+1 for swipe/touch

@ml4725
Copy link

ml4725 commented Apr 8, 2024

Wasn't this requirement raised three years ago? Are you really not planning to do it? After all, Selenium supports it.

@xaker01
Copy link

xaker01 commented Apr 22, 2024

+1 swipe

@PupilTong
Copy link

Tried on chrome 124, Windows 10.
https://chromedevtools.github.io/devtools-protocol/tot/Input/#method-emulateTouchFromMouseEvent
This CDP API could mock the touch input to invoke scrolling by touch/touchmove.
I plan to add some methods to the page.touchscreen as wrappers of the emulateTouchFromMouseEvent.
It may help us to emulate the swipe/fling gesture.
It will be 1-2 weeks for me to walk through the playwright code and find a way to implement it.

@PupilTong
Copy link

PupilTong commented Apr 28, 2024

Tried on chrome 124, Windows 10. https://chromedevtools.github.io/devtools-protocol/tot/Input/#method-emulateTouchFromMouseEvent This CDP API could mock the touch input to invoke scrolling by touch/touchmove. I plan to add some methods to the page.touchscreen as wrappers of the emulateTouchFromMouseEvent. It may help us to emulate the swipe/fling gesture. It will be 1-2 weeks for me to walk through the playwright code and find a way to implement it.

Input.synthesizeScrollGesture works. Now I'm going to implement page.touchscreen.scroll first.

it('should work on scroll container', async ({ page, server }) => {
  const client = await page.context().newCDPSession(page);
  await page.setContent(`<div id="container" style="width: 500px; height: 500px; overflow-y:scroll;"><div style="width:100%; height:200%;"></div></div>`);
  await client.send('Input.synthesizeScrollGesture', {
    x: 10,
    y: 200,
    xDistance: 0,
    yDistance: -100,
    preventFling: true
  })
  expect(await page.$eval('#container', e => e.scrollTop)).toBe(100);
});

PupilTong pushed a commit to PupilTong/playwright that referenced this issue Apr 29, 2024
https://chromedevtools.github.io/devtools-protocol/tot/Input/#method-synthesizeScrollGesture

This is a wrapper of this CDP method.
Currently the Firefox and the Safari are not yet implement is method.

Close microsoft#2903
PupilTong pushed a commit to PupilTong/playwright that referenced this issue Apr 29, 2024
https://chromedevtools.github.io/devtools-protocol/tot/Input/#method-synthesizeScrollGesture

This is a wrapper of this CDP method.
Currently the Firefox and the Safari are not yet implement is method.

Close microsoft#2903
@PupilTong
Copy link

I've submitted a PR for the page.touchscreen.swipe.

PupilTong pushed a commit to PupilTong/playwright that referenced this issue Apr 29, 2024
https://chromedevtools.github.io/devtools-protocol/tot/Input/#method-synthesizeScrollGesture

This is a wrapper of this CDP method.
Currently the Firefox and the Safari are not yet implement this method.

Close microsoft#2903
PupilTong pushed a commit to PupilTong/playwright that referenced this issue Apr 29, 2024
https://chromedevtools.github.io/devtools-protocol/tot/Input/#method-synthesizeScrollGesture

This is a wrapper of this CDP method.
Currently the Firefox and the Safari are not yet implement this method.

Close microsoft#2903
PupilTong pushed a commit to PupilTong/playwright that referenced this issue Apr 29, 2024
https://chromedevtools.github.io/devtools-protocol/tot/Input/#method-synthesizeScrollGesture

This is a wrapper of this CDP method.
Currently the Firefox and the Safari are not yet implement this method.

Close microsoft#2903
PupilTong pushed a commit to PupilTong/playwright that referenced this issue Apr 29, 2024
https://chromedevtools.github.io/devtools-protocol/tot/Input/#method-dispatchTouchEvent

Implement it for chromium only since it could  using dispatchTouchEvent to invoke scroll.

Tried firefox but it doesn't work.

Close microsoft#2903
PupilTong pushed a commit to PupilTong/playwright that referenced this issue Apr 29, 2024
https://chromedevtools.github.io/devtools-protocol/tot/Input/#method-dispatchTouchEvent

Implement it for chromium only since it could  using dispatchTouchEvent to invoke scroll.

Tried firefox but it doesn't work.

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

No branches or pull requests