简体   繁体   English

如何使用 puppeteer-sharp touchStart 和 touchEnd 和 touch move

[英]how to use puppeteer-sharp touchStart and touchEnd and touch move

The Touchscreen in puppeteer-sharp API just gives one method: TapAsync. puppeteer-sharp API 中的触摸屏只给出了一种方法:TapAsync。 but I need drag(touchStart and touchEnd and touch move).但我需要拖动(touchStart 和 touchEnd 和 touch move)。 How can I do that?我怎样才能做到这一点?

PuppeteerSharp doesn't have those APIs (because Pupppeteer doesn't have them). PuppeteerSharp 没有这些 API(因为 Puppppeteer 没有它们)。 But, you could try sending those messages to the browser in the same way TapAsync does.但是,您可以尝试以与TapAsync相同的方式将这些消息发送到浏览器。

This is the TapAsync code:这是TapAsync代码:

// 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 .页面有一个公共属性Client You can use that Client to perform these calls.您可以使用该客户端来执行这些调用。

As you can check here , Type supports: touchStart, touchEnd, touchMove and touchCancel.你可以在这里查看,Type 支持:touchStart、touchEnd、touchMove 和 touchCancel。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM