Skip to main content

Platform

Enum Platform 

Source
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
innerWidth1120440
maxTouchPoints05
meta viewportwidth=1120width=device-width

The server returned different HTML. Emulating the platform is therefore part of producing a correct screenshot, not a nicety.

Variants§

§

IosPhone

§

IosTablet

§

IosWatch

§

AndroidPhone

§

AndroidTablet

§

Macos

§

Tv

§

Web

Implementations§

Source§

impl Platform

Source

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.

Source

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.

Source

pub fn ch_mobile(self) -> bool

Whether Client Hints should report a mobile device.

Source

pub fn touch_points(self) -> u32

Simultaneous touch points to report, or 0 for a pointer device.

Trait Implementations§

Source§

impl Clone for Platform

Source§

fn clone(&self) -> Platform

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Platform

Source§

impl Debug for Platform

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Platform

Source§

fn default() -> Platform

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Platform

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Platform

Source§

impl PartialEq for Platform

Source§

fn eq(&self, other: &Platform) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Platform

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Platform

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.