主题
userAgent
userAgent 辅助程序使用附加属性和方法扩展了 网络请求 API,以便与请求中的用户代理对象进行交互。
¥The userAgent helper extends the Web Request API with additional properties and methods to interact with the user agent object from the request.
ts
import { NextRequest, NextResponse, userAgent } from 'next/server'
export function middleware(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.
name:代表浏览器名称的字符串,如果无法识别,则为undefined。¥
name: A string representing the browser's name, orundefinedif not identifiable.version:代表浏览器版本的字符串,或undefined。¥
version: A string representing the browser's version, orundefined.
device
包含有关请求中使用的设备的信息的对象。
¥An object containing information about the device used in the request.
model:代表设备型号的字符串,或undefined。¥
model: A string representing the model of the device, orundefined.type:表示设备类型的字符串,例如console、mobile、tablet、smarttv、wearable、embedded或undefined。¥
type: A string representing the type of the device, such asconsole,mobile,tablet,smarttv,wearable,embedded, orundefined.vendor:代表设备供应商的字符串,或undefined。¥
vendor: A string representing the vendor of the device, orundefined.
engine
包含有关浏览器引擎的信息的对象。
¥An object containing information about the browser's engine.
name:代表引擎名称的字符串。可能的值包括:Amaya、Blink、EdgeHTML、Flow、Gecko、Goanna、iCab、KHTML、Links、Lynx、NetFront、NetSurf、Presto、Tasman、Trident、w3m、WebKit或undefined。¥
name: A string representing the engine's name. Possible values include:Amaya,Blink,EdgeHTML,Flow,Gecko,Goanna,iCab,KHTML,Links,Lynx,NetFront,NetSurf,Presto,Tasman,Trident,w3m,WebKitorundefined.version:代表引擎版本的字符串,或undefined。¥
version: A string representing the engine's version, orundefined.
os
包含有关操作系统的信息的对象。
¥An object containing information about the operating system.
name:代表操作系统名称或undefined的字符串。¥
name: A string representing the name of the OS, orundefined.version:代表操作系统版本的字符串,或undefined。¥
version: A string representing the version of the OS, orundefined.
cpu
包含有关 CPU 架构信息的对象。
¥An object containing information about the CPU architecture.
architecture:代表 CPU 架构的字符串。可能的值包括:68k、amd64、arm、arm64、armhf、avr、ia32、ia64、irix、irix64、mips、mips64、pa-risc、ppc、sparc、sparc64或undefined¥
architecture: A string representing the architecture of the CPU. Possible values include:68k,amd64,arm,arm64,armhf,avr,ia32,ia64,irix,irix64,mips,mips64,pa-risc,ppc,sparc,sparc64orundefined