userAgent

userAgent ヘルパーは Web Request API を拡張し、リクエストからユーザーエージェントオブジェクトと相互作用するための追加プロパティとメソッドを提供します。

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

リクエストが既知のボットからのものであるかどうかを示すブール値。

browser

リクエストで使用されたブラウザに関する情報を含むオブジェクト。

  • name: ブラウザ名を表す文字列、または識別できない場合は undefined
  • version: ブラウザのバージョンを表す文字列、または undefined

device

リクエストで使用されたデバイスに関する情報を含むオブジェクト。

  • model: デバイスのモデルを表す文字列、または undefined
  • type: デバイスの種類を表す文字列(console, mobile, tablet, smarttv, wearable, embedded など)、または undefined
  • vendor: デバイスのベンダーを表す文字列、または undefined

engine

ブラウザのエンジンに関する情報を含むオブジェクト。

  • name: エンジン名を表す文字列。取り得る値: Amaya, Blink, EdgeHTML, Flow, Gecko, Goanna, iCab, KHTML, Links, Lynx, NetFront, NetSurf, Presto, Tasman, Trident, w3m, WebKit または undefined
  • version: エンジンのバージョンを表す文字列、または undefined

os

オペレーティングシステムに関する情報を含むオブジェクト。

  • name: OS名を表す文字列、または undefined
  • version: OSのバージョンを表す文字列、または undefined

cpu

CPUアーキテクチャに関する情報を含むオブジェクト。

  • architecture: CPUアーキテクチャを表す文字列。取り得る値: 68k, amd64, arm, arm64, armhf, avr, ia32, ia64, irix, irix64, mips, mips64, pa-risc, ppc, sparc, sparc64 または undefined