メインコンテンツまでスキップ

userAgent

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

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

export function middleware(request: NextRequest) {
const url = request.nextUrl
const { device } = userAgent(request)

// device.type は、'mobile', 'tablet', 'console', 'smarttv',
// 'wearable', 'embedded' または undefined(デスクトップブラウザの場合)になります
const viewport = device.type || '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 が含まれます。