npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

detect-browser-es

v0.1.1

Published

[![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] [![License][license-src]][license-href]

Downloads

318

Readme

detect-browser-es

npm version npm downloads License

ESM build of detect-browser with server info via std-env.

Usage

Install:

# pnpm
pnpm add detect-browser-es

# npm
npm i detect-browser-es

# yarn
yarn add detect-browser-es

Import:

// ESM
import { detect } from 'detect-browser-es'

// CommonJS
const { detect } = require('detect-browser-es')

Deprecations

NodeInfo and getNodeVersion have been deprecated and replaced with ServerInfo and getServerVersion respectively.

Breaking changes

Calling detect function returns ServerInfo instead NodeInfo. If you still want to use NodeInfo, use deprecated getNodeVersion function.

New Features

User-Agent Client Hints API

The new asyncDetect function should be used when you need to detect Windows 11 or any User-Agent Client Hints, otherwise you can still use the detect function.

To access the low-entropy User-Agent Client Hints values (mobile, platform and brands ), you don't need to use the asyncDetect function, you can use the navigator.userAgentData object when available in the browser (check browser compatibility), or using lookupServerUserAgentHints function for server.

Windows 11 detection

There is no way to detect Windows 11 using only user-agent, you need to use the asyncDetect function or the serverResponseHeadersForUserAgentHints function and will work only on Chromium based and Opera browsers (those supporting the User-Agent Client Hints API).

To detect Windows 11 in the browser, you need to use the asyncDetect function providing platformVersion in the options.hints array.

To detect Windows 11 in the server, you need to send Accept-CH http response header to the client with the corresponding Sec-CH-UA-* values. You can use the serverResponseHeadersForUserAgentHints function providing the required entries for your application, it will return the corresponding Accept-CH header. The function accepts the hint names you use in the browser, you don't need to worry about http header names.

Testing

To run the tests, from root folder run nr dev or nr test (with coverage), the script will run:

  • the original tests from detect-browser
  • Happy DOM and jsdom tests, except WebdriverIO detection: Happy DOM v15.7.3 seems to omit the version (https://github.com/capricorn86/happy-dom/issues/1528)
  • User-Agent Client Hints server detection
  • Windows 11 server detection
  • Accept-CH response header generation

To run tests using Vitest Browser with WebdriverIO, run one of the following commands:

  • nr test:chrome: Chrome must be installed
  • nr test:edge: Edge must be installed
  • nr test:firefox: Firefox must be installed
  • nr test:safari: Safari must be installed and only on macOS machine

To test WebdriverIO detection, run one of the following commands (will not work, there is a bug in @wdio/browser-runner):

  • nr wdio:chrome: Chrome must be installed
  • nr wdio:edge: Edge must be installed
  • nr wdio:firefox: Firefox must be installed
  • nr wdio:safari: Safari must be installed and only on macOS machine

License

MIT