Skip to main content

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.

import { NextRequest, NextResponse, userAgent } from 'next/server'

export function middleware(request: NextRequest) {
const url = request.nextUrl
const { device } = userAgent(request)
const viewport = device.type === 'mobile' ? 'mobile' : 'desktop'
url.searchParams.set('viewport', viewport)
return NextResponse.rewrite(url)
}
import { NextResponse, userAgent } from 'next/server'

export function middleware(request) {
const url = request.nextUrl
const { device } = userAgent(request)
const viewport = device.type === 'mobile' ? 'mobile' : '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, or undefined if not identifiable.

  • version:代表浏览器版本的字符串,或 undefined

    ¥version: A string representing the browser's version, or undefined.

device

包含有关请求中使用的设备的信息的对象。

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

  • model:代表设备型号的字符串,或 undefined

    ¥model: A string representing the model of the device, or undefined.

  • type:表示设备类型的字符串,例如 consolemobiletabletsmarttvwearableembeddedundefined

    ¥type: A string representing the type of the device, such as console, mobile, tablet, smarttv, wearable, embedded, or undefined.

  • vendor:代表设备供应商的字符串,或 undefined

    ¥vendor: A string representing the vendor of the device, or undefined.

engine

包含有关浏览器引擎的信息的对象。

¥An object containing information about the browser's engine.

  • name:代表引擎名称的字符串。可能的值包括:AmayaBlinkEdgeHTMLFlowGeckoGoannaiCabKHTMLLinksLynxNetFrontNetSurfPrestoTasmanTridentw3mWebKitundefined

    ¥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, WebKit or undefined.

  • version:代表引擎版本的字符串,或 undefined

    ¥version: A string representing the engine's version, or undefined.

os

包含有关操作系统的信息的对象。

¥An object containing information about the operating system.

  • name:代表操作系统名称或 undefined 的字符串。

    ¥name: A string representing the name of the OS, or undefined.

  • version:代表操作系统版本的字符串,或 undefined

    ¥version: A string representing the version of the OS, or undefined.

cpu

包含有关 CPU 架构信息的对象。

¥An object containing information about the CPU architecture.

  • architecture:代表 CPU 架构的字符串。可能的值包括:68kamd64armarm64armhfavria32ia64irixirix64mipsmips64pa-riscppcsparcsparc64undefined

    ¥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, sparc64 or undefined