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

feat: add the page.touchscreen.swipe method #30587

Closed
wants to merge 1 commit into from

Conversation

PupilTong
Copy link

@PupilTong PupilTong commented 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.

#2903

This comment has been minimized.

@PupilTong
Copy link
Author

@PupilTong please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree company="Bytedance"

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

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
Copy link
Author

https://chromedevtools.github.io/devtools-protocol/tot/Input/#method-synthesizeScrollGesture
This CDP method cannot scroll a container on xvfb headless chromium with gestureSourceType:'touch'. It might only works on a device with a screen.
Also, this 'dispatchtouch' implementation is tried in Firefox. But it cannot scroll a container neither.

Copy link
Contributor

Test results for "tests 1"

1 flaky ⚠️ [webkit-library] › library/browsercontext-clearcookies.spec.ts:92:3 › should remove cookies by domain

27260 passed, 677 skipped
✔️✔️✔️

Merge workflow run.

Copy link
Contributor

@dgozman dgozman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR! Unfortunately, we cannot make this a Chromium-only feature, it has to work in all three browser engines.

@PupilTong
Copy link
Author

PupilTong commented May 6, 2024

Thank you for the PR! Unfortunately, we cannot make this a Chromium-only feature, it has to work in all three browser engines.

How about expose the Input.dispatchTouchEvent ?
For example, add a page.touchscreen.touch() therefore we could create the swipe wrapper by ourselves.

The firefox also implemented this CDP method.

Just like the page.mouse.wheel(), it is supported by chromium and firefox.

@PupilTong
Copy link
Author

Thank you for the PR! Unfortunately, we cannot make this a Chromium-only feature, it has to work in all three browser engines.

How about expose the Input.dispatchTouchEvent ? For example, add a page.touchscreen.touch() therefore we could create the swipe wrapper by ourselves.

The firefox also implemented this CDP method.

Just like the page.mouse.wheel(), it is supported by chromium and firefox.

kindly ping @dgozman ;-)

@dgozman
Copy link
Contributor

dgozman commented May 8, 2024

How about expose the Input.dispatchTouchEvent ? For example, add a page.touchscreen.touch() therefore we could create the swipe wrapper by ourselves.

I am not really sure what you mean by "exposing Input.dispatchTouchEvent". Could you please elaborate?

Just like the page.mouse.wheel(), it is supported by chromium and firefox.

Generally, Playwright APIs should be supported by chromium, firefox and webkit.

@PupilTong
Copy link
Author

How about expose the Input.dispatchTouchEvent ? For example, add a page.touchscreen.touch() therefore we could create the swipe wrapper by ourselves.

I am not really sure what you mean by "exposing Input.dispatchTouchEvent". Could you please elaborate?

Just like the page.mouse.wheel(), it is supported by chromium and firefox.

Generally, Playwright APIs should be supported by chromium, firefox and webkit.

@dgozman

  • expose the CDP method 'Input.dispatchTouchEvent'

Both the firefox and the chromium support this CDP method. I can submit another PR, create a Playwright method like page.touchscreen.touch() as a wrapper of the CDP method. Therefore developers are able to create their own swipe() method based on it.

  • About the compatibility

Currently Playwright already have a method ,page.mouse.wheel(), which cannot be called for webkit running env. I think this means if a new method only support chromium and firefox may be accepted.
Considering the Safari team's attitude about the touch-related feature on desktop safari (They even do not provide the TouchEvent on the desktop safari.), I guess add a touchscreen method for playwright without safari support is reasonable.

@dgozman
Copy link
Contributor

dgozman commented May 9, 2024

@PupilTong Thank you for the answers!

If you believe that developers can implement swipe() based on exposed dispatchTouchEvent in Firefox, then you should be able to do the same. Therefore, I'd prefer to stick with touchscreen.swipe() API as in this PR.

As for compatibility, our goal is cross-browser support where possible. For example, we support touchscreen.tap() on every browser where hasTouch option was set. In contrast, mouse.wheel() is not supported in mobile webkit because there is no real mouse on devices with mobile webkit browsers, however mouse.wheel() is supported in desktop webkit.

Overall, the approach you take in this PR is a good one. Unfortunately, this feature most likely requires some work in the browser engines themselves, so it is not that straightforward to implement.

As a workaround for now, we recommend using locator.dispatchEvent() method and issue some specific events like touchstart/touchmove/touchend. This is not the real swipe, but it is something useful today. See also #6072.

@PupilTong
Copy link
Author

@PupilTong Thank you for the answers!

If you believe that developers can implement swipe() based on exposed dispatchTouchEvent in Firefox, then you should be able to do the same. Therefore, I'd prefer to stick with touchscreen.swipe() API as in this PR.

As for compatibility, our goal is cross-browser support where possible. For example, we support touchscreen.tap() on every browser where hasTouch option was set. In contrast, mouse.wheel() is not supported in mobile webkit because there is no real mouse on devices with mobile webkit browsers, however mouse.wheel() is supported in desktop webkit.

Overall, the approach you take in this PR is a good one. Unfortunately, this feature most likely requires some work in the browser engines themselves, so it is not that straightforward to implement.

As a workaround for now, we recommend using locator.dispatchEvent() method and issue some specific events like touchstart/touchmove/touchend. This is not the real swipe, but it is something useful today. See also #6072.

Thanks for your answer!

Let me explain why the dispatchEvent is not enough to use.
The locator.dispatchEvent() cannot meet our requirements. It requires to "locate a dom". But for e2e tests, typically we have to send events based on the x&y position to test the gestures implementation.

I'll spend some time for Firefox about this.

For Safari, it seems they requires developers to use their emulator to test touch gestures. https://developer.apple.com/documentation/safari-developer-tools/inspecting-ios
I don't know if it could be implemented.

@pavelfeldman
Copy link
Member

Let me archive this for now, please feel free to re-post and link to this PR.

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

Successfully merging this pull request may close these issues.

None yet

3 participants