Device

Classin device@fastly/js-compute 3.46.0since 3.10.0View source

Provides device detection based on User-Agent strings.

Note: Can only be used when processing requests, not during build-time initialization.

Properties

name

string | nullread-onlyView source

The name of the device, or null if no name is known.

brand

string | nullread-onlyView source

The brand of the device, which may be different from the manufacturer. null if no brand is known.

model

string | nullread-onlyView source

The model of the device, or null if no model is known.

hardwareType

string | nullread-onlyView source

A string representation of the device's primary platform hardware, or null if not known.

The most commonly used device types are also identified via boolean properties. Because a device may have multiple device types and this property only has the primary type, we recommend using the boolean properties for logic and this string representation for logging.

isDesktop

boolean | nullread-onlyView source

Whether the device is a desktop web browser, or null if not known.

isGameConsole

boolean | nullread-onlyView source

Whether the device is a video game console, or null if not known.

isMediaPlayer

boolean | nullread-onlyView source

Whether the device is a media player (like Blu-ray players, iPod devices, and smart speakers such as Amazon Echo), or null if not known.

isMobile

boolean | nullread-onlyView source

Whether the device is a mobile phone, or null if not known.

isSmartTV

boolean | nullread-onlyView source

Whether the device is a smart TV, or null if not known.

isTablet

boolean | nullread-onlyView source

Whether the device is a tablet (like an iPad), or null if not known.

isTouchscreen

boolean | nullread-onlyView source

Whether the device's screen is touch sensitive, or null if not known.

isBot

boolean | nullread-onlysince 3.39.0View source

Whether the device is a bot, or null if not known.

Methods

lookup

staticView source
static lookup(useragent: string): Device | null

Look up the data associated with a particular User-Agent string. If there is data associated with the User-Agent, a Device instance is returned. Otherwise, null is returned.

Parameters

useragent: string

The User-Agent string to look up.

Returns

Device | null

Throws

  • TypeError if the provided User-Agent string is empty.
toJSON(): Object

Returns a JSON representation of the Device object.

To get a JSON string, you can use JSON.stringify(device) directly; it will call toJSON() automatically.

Returns