#[non_exhaustive]pub struct DeviceDescriptor {
pub user_agent: String,
pub viewport: DeviceViewport,
pub screen: Option<DeviceViewport>,
pub device_scale_factor: f64,
pub is_mobile: bool,
pub has_touch: bool,
pub default_browser_type: String,
}Expand description
Describes a device for browser emulation.
Use with BrowserContext::new_context() options to emulate a specific device,
matching the behavior of playwright.devices["iPhone 13"] in Python/JS.
Device descriptors are accessed by name from crate::protocol::Playwright::devices.
The name is the map key, not a field of the descriptor itself.
§Example
use playwright_rs::protocol::Playwright;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let playwright = Playwright::launch().await?;
let iphone = &playwright.devices()["iPhone 13"];
assert!(iphone.is_mobile);
assert!(iphone.has_touch);
assert_eq!(iphone.default_browser_type, "webkit");
playwright.shutdown().await?;
Ok(())
}See: https://playwright.dev/docs/api/class-playwright#playwright-devices
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.user_agent: StringThe user-agent string for the device.
viewport: DeviceViewportThe viewport dimensions.
screen: Option<DeviceViewport>The screen size the device reports through window.screen, larger
than the viewport on a device whose browser chrome takes room. Pass
it as BrowserContextOptions::screen
to emulate the device fully. Not every descriptor has one.
device_scale_factor: f64The device pixel ratio (e.g., 3.0 for Retina displays).
is_mobile: boolWhether the device is a mobile device.
has_touch: boolWhether the device supports touch input.
default_browser_type: StringThe default browser type for the device: "chromium", "firefox", or "webkit".