rembrembdocs

userAgent

Last updated April 23, 2026

The userAgent helper extends the Web Request API with additional properties and methods to interact with the user agent object from the request.

proxy.ts

JavaScriptTypeScript

import { NextRequest, NextResponse, userAgent } from 'next/server'
 
export function proxy(request: NextRequest) {
  const url = request.nextUrl
  const { device } = userAgent(request)
 
  // device.type can be: 'mobile', 'tablet', 'console', 'smarttv',
  // 'wearable', 'embedded', or undefined (for desktop browsers)
  const viewport = device.type || 'desktop'
 
  url.searchParams.set('viewport', viewport)
  return NextResponse.rewrite(url)
}

isBot

A boolean indicating whether the request comes from a known bot.

browser

An object containing information about the browser used in the request.

device

An object containing information about the device used in the request.

engine

An object containing information about the browser's engine.

os

An object containing information about the operating system.

cpu

An object containing information about the CPU architecture.

Was this helpful?