Skip to main content

playwright_rs/protocol/
touchscreen.rs

1// Touchscreen - Low-level touchscreen control
2//
3// See: https://playwright.dev/docs/api/class-touchscreen
4
5use crate::error::Result;
6use crate::protocol::page::Page;
7
8/// Touchscreen provides touch input simulation via a single touch point.
9///
10/// Access via [`Page::touchscreen()`].
11///
12/// See: <https://playwright.dev/docs/api/class-touchscreen>
13#[derive(Clone)]
14pub struct Touchscreen {
15    page: Page,
16}
17
18impl Touchscreen {
19    /// Creates a new Touchscreen instance for the given page.
20    pub(crate) fn new(page: Page) -> Self {
21        Self { page }
22    }
23
24    /// Sends a single touch to the specified coordinates.
25    ///
26    /// Dispatches a `touchstart` and `touchend` event sequence at the given
27    /// viewport coordinates. Requires a touch-enabled browser context
28    /// (`has_touch: true` in [`BrowserContextOptions`](crate::protocol::BrowserContextOptions)).
29    ///
30    /// # Arguments
31    ///
32    /// * `x` - X coordinate in CSS pixels (relative to viewport top-left)
33    /// * `y` - Y coordinate in CSS pixels (relative to viewport top-left)
34    ///
35    /// # Errors
36    ///
37    /// Returns error if the RPC call fails or the page has been closed.
38    ///
39    /// See: <https://playwright.dev/docs/api/class-touchscreen#touchscreen-tap>
40    pub async fn tap(&self, x: f64, y: f64) -> Result<()> {
41        self.page.touchscreen_tap(x, y).await
42    }
43}