The Touchscreen in puppeteer-sharp API just gives one method: TapAsync. but I need drag(touchStart and touchEnd and touch move). How can I do that?
Asked
Active
Viewed 990 times
1 Answers
1
PuppeteerSharp doesn't have those APIs (because Pupppeteer doesn't have them). But, you could try sending those messages to the browser in the same way TapAsync
does.
This is the TapAsync
code:
// Touches appear to be lost during the first frame after navigation.
// This waits a frame before sending the tap.
// @see https://crbug.com/613219
await _client.SendAsync("Runtime.evaluate", new RuntimeEvaluateRequest
{
Expression = "new Promise(x => requestAnimationFrame(() => requestAnimationFrame(x)))",
AwaitPromise = true
}).ConfigureAwait(false);
var touchPoints = new[] { new TouchPoint { X = Math.Round(x), Y = Math.Round(y) } };
await _client.SendAsync("Input.dispatchTouchEvent", new InputDispatchTouchEventRequest
{
Type = "touchStart",
TouchPoints = touchPoints,
Modifiers = _keyboard.Modifiers
}).ConfigureAwait(false);
await _client.SendAsync("Input.dispatchTouchEvent", new InputDispatchTouchEventRequest
{
Type = "touchEnd",
TouchPoints = Array.Empty<TouchPoint>(),
Modifiers = _keyboard.Modifiers
}).ConfigureAwait(false);
Page has a public property Client. You can use that Client to perform these calls.
As you can check here, Type supports: touchStart, touchEnd, touchMove and touchCancel.

hardkoded
- 18,915
- 3
- 52
- 64
-
Thansks. I has another question, how to implement function from the link:https://medium.com/@jsoverson/using-chrome-devtools-protocol-with-puppeteer-737a1300bac0 . I need to Intercepte the link ,but the link over then start a javascript Navigation immediately. this is a chrome bug – dongdong Jun 05 '20 at 15:48