Getting started
sh
npm install undevicesh
pnpm add undevicesh
yarn add undevicesh
bun add undeviceFirst detection
Create a detector once, then pass each incoming request's headers to detect():
ts
import { undevice } from 'undevice'
const { detect } = undevice()
const device = detect({ headers: request.headers })
device.isMobile
device.isTablet
device.isDesktopundevice() returns a frozen object with a detect method. Each call to detect() returns a new frozen UndeviceResult with detection flags.
The library does not mutate input data or implicitly access request context or browser globals.
User-Agent
In the browser, pass navigator.userAgent:
ts
import { undevice } from 'undevice'
const { detect } = undevice()
const device = detect({ userAgent: navigator.userAgent })To override the User-Agent:
ts
const device = detect({
headers: request.headers,
userAgent: customUserAgent,
})For SSR, reuse the server's result on the client to avoid hydration mismatches.