Socket
Book a DemoInstallSign in
Socket

client-hints

Package Overview
Dependencies
Maintainers
0
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

client-hints

🕵️‍♂️ Parse client hints headers and provide a convenient API to access device information and user preferences

latest
Source
npmnpm
Version
2.2.2
Version published
Maintainers
0
Created
Source

client-hints

🕵️‍♂️ Parse client hints headers and provide a convenient API to access device information and user preferences

Use client hints, where available

import { ClientHints } from "client-hints";
import { userAgentParser } from "some-user-agent-parser-library";

app.get("/api-endpoint", (req, res) => {
  const hints = new ClientHints(req);

  const isMobile =
    hints.mobile ?? // cheap
    userAgentParser(req.get("user-agent")).device?.type === "mobile"; // more expensive

  const browserName =
    hints.vendorName ?? // cheap
    userAgentParser(req.get("user-agent")).browser?.name; // more expensive

  console.log(JSON.stringify(hints, null, 2)); // Serialises all available hints

  res.send(`${isMobile ? "Mobile" : "Desktop"} browser: ${browserName}`);
});

Available detections

All detections return undefined if the relevant header is not available.

FeatureTypeHeaderMeaningAdoption level
arch, architecturestringSec-CH-UA-ArchCPU architectureExperimental
bitnessnumberSec-CH-UA-BitnessCPU bitness (32, 64)Experimental
contentDpr, contentDevicePixelRationumberContent-DPRImage device pixel ratioDeprecated
deviceMemorynumberDevice-MemoryAppr. available RAMExperimental
downlinknumberDownlinkNetwork speed (Mbps)Experimental
dpr, devicePixelRationumberDPRDevice pixel ratioDeprecated
ect, effectiveConnectionTypestringECTNetwork profile (G)Experimental
fetchDest, fetchDestinationstringSec-Fetch-DestResource type
fetchModestringSec-Fetch-ModeNavigation type
fetchSitestringSec-Fetch-SiteRelationship to origin
fetchUserbooleanSec-Fetch-UserWas the request triggered by user action
gpcbooleanSec-GPCConsents to sell or share personal informationExperimental
mobilebooleanSec-CH-UA-MobileBoolean: Is this a mobile deviceExperimental
modelstringSec-CH-UA-ModelDevice modelExperimental
platformstringSec-CH-UA-PlatformOperating system nameExperimental
platformVersionstringSec-CH-UA-Platform-VersionOperating system versionExperimental
prefersColorSchemestringSec-CH-Prefers-Color-SchemeUser's preferred color schemeExperimental
prefersReducedMotionbooleanSec-CH-Prefers-Reduced-MotionUser prefers reduced motionExperimental
prefersReducedTransparencybooleanSec-CH-Prefers-Reduced-TransparencyUser prefers reduced transparencyExperimental
purposestringSec-PurposeResource purpose (prefetch)Experimental
vendorNamestringSec-CH-UA / Sec-CH-UA-Full-Version-ListBrowser NameExperimental
vendorVersionstringSec-CH-UA-Full-Version / Sec-CH-UA / Sec-CH-UA-Full-Version-ListBrowser versionExperimental
viewportWidthnumberViewport-WidthLayout viewport widthDeprecated
widthnumberWidthResource desired widthDeprecated

Client Hints Instructions Response Header

Set the value of Accept-CH header to include the headers you want the browse to send.

Accept-CH: Sec-CH-UA-Mobile,Sec-CH-UA-Full-Version,Sec-CH-UA-Full-Version-List,Sec-CH-UA-Model,Sec-CH-UA-Platform,Sec-CH-UA-Platform-Version,ECT

Include all available hints:

Accept-CH: *

Keywords

client-hints

FAQs

Package last updated on 06 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts