pub enum Platform {
IosPhone,
IosTablet,
IosWatch,
AndroidPhone,
AndroidTablet,
Macos,
Tv,
Web,
}Expand description
What kind of device is being emulated.
§Why this exists
Setting the viewport is not device emulation. A page served to a
desktop User-Agent can declare <meta name="viewport" content="width=1120">,
and Chrome honours that meta tag whenever mobile is set — so the layout
viewport becomes 1120 CSS px and the desktop layout is merely scaled down
into a phone-sized frame. The image is the right number of pixels and shows
entirely the wrong thing.
Measured against a real site with identical metrics, changing only the User-Agent and touch points:
| metrics only | + UA + touch | |
|---|---|---|
innerWidth | 1120 | 440 |
maxTouchPoints | 0 | 5 |
| meta viewport | width=1120 | width=device-width |
The server returned different HTML. Emulating the platform is therefore part of producing a correct screenshot, not a nicety.
Variants§
Implementations§
Source§impl Platform
impl Platform
Sourcepub fn user_agent(self) -> Option<&'static str>
pub fn user_agent(self) -> Option<&'static str>
A representative User-Agent for this platform.
These are deliberately generic-but-plausible rather than pinned to one handset: the goal is for content negotiation to pick the right layout, not to impersonate a specific device.
Sourcepub fn ch_platform(self) -> &'static str
pub fn ch_platform(self) -> &'static str
Platform name for User-Agent Client Hints (Sec-CH-UA-Platform).
Modern sites increasingly branch on Client Hints rather than the UA string, so overriding one without the other produces a page that is half-convinced it is on a phone.
Sourcepub fn touch_points(self) -> u32
pub fn touch_points(self) -> u32
Simultaneous touch points to report, or 0 for a pointer device.