Functions
userAgent: Advisory request classification
Extract advisory browser, device and related characteristics from a request user-agent string. Values can be absent, misleading or spoofed. Never use them as a security principal or permission check; responsive CSS and feature detection are generally more robust for presentation. Example context: Next.js 16.x documentation lane; illustrative snippet or file tree, not executed. Exact candidate patch 16.4.6 remains unverified. Expected behavior / verification: Send fixed synthetic headers, including an empty header, and check a safe fallback. Do not persist identifying raw user-agent values by default.
Formal Syntax & Structure
nextjs syntaxnextjs
userAgent(request)Working Example
Example Snippetnextjs
import { userAgent, type NextRequest } from 'next/server';export function GET(request: NextRequest) { const { device } = userAgent(request); return Response.json({ deviceType: device.type ?? 'unknown' });}