detect-gpu
Classify GPU's based on their benchmark score in order to provide an adaptive experience.
Last updated 4 years ago by timvanscherpenzeel .
MIT · Original npm · Tarball · package.json
$ npm install detect-gpu 
SYNC missed versions from official npm registry.

Detect GPU

npm version gzip size install size

Classifies GPUs based on their 3D rendering benchmark score allowing the developer to provide sensible default settings for graphically intensive applications. Think of it like a user-agent detection for the GPU but more powerful.

Demo

Live demo

Installation

By default we use the UNPKG CDN to host the benchmark data. If you would like to serve the benchmark data yourself download the required benchmarking data from benchmarks.tar.gz and serve it from a public directory.

Make sure you have Node.js installed.

 $ npm install detect-gpu

Usage

import { getGPUTier } from 'detect-gpu';

(async () => {
  const gpuTier = await getGPUTier();

  // Example output:
  // {
  //   "tier": 1,
  //   "isMobile": false,
  //   "type": "BENCHMARK",
  //   "fps": 21,
  //   "gpu": "intel iris graphics 6100"
  // }
})();

detect-gpu uses rendering benchmark scores (framerate, normalized by resolution) in order to determine what tier should be assigned to the user's GPU. If no WebGLContext can be created, the GPU is blocklisted or the GPU has reported to render on less than 15 fps tier: 0 is assigned. One should provide a fallback to a non-WebGL experience.

Based on the reported fps the GPU is then classified into either tier: 1 (>= 15 fps), tier: 2 (>= 30 fps) or tier: 3 (>= 60 fps). The higher the tier the more graphically intensive workload you can offer to the user.

API

getGPUTier({
  /**
   * URL of directory where benchmark data is hosted.
   *
   * @default https://unpkg.com/detect-gpu@{version}/dist/benchmarks
   */
  benchmarksURL?: string;
  /**
   * Optionally pass in a WebGL context to avoid creating a temporary one
   * internally.
   */
  glContext?: WebGLRenderingContext | WebGL2RenderingContext;
  /**
   * Whether to fail if the system performance is low or if no hardware GPU is
   * available.
   *
   * @default false
   */
  failIfMajorPerformanceCaveat?: boolean;
  /**
   * Framerate per tier for mobile devices.
   *
   * @defaultValue [0, 15, 30, 60]
   */
  mobileTiers?: number[];
  /**
   * Framerate per tier for desktop devices.
   *
   * @defaultValue [0, 15, 30, 60]
   */
  desktopTiers?: number[];
  /**
   * Optionally override specific parameters. Used mainly for testing.
   */
  override?: {
    renderer?: string;
    /**
     * Override whether device is an iPad.
     */
    isIpad?: boolean;
    /**
     * Override whether device is a mobile device.
     */
    isMobile?: boolean;
    /**
     * Override device screen size.
     */
    screenSize?: { width: number; height: number };
    /**
     * Override how benchmark data is loaded
     */
    loadBenchmarks?: (file: string) => Promise<ModelEntry[]>;
  };
})

Support

Special care has been taken to make sure all browsers that support WebGL are also supported by detect-gpu including IE 11.

Changelog

Changelog

Licence

My work is released under the MIT license.

detect-gpu uses both mobile and desktop benchmarking scores from https://gfxbench.com.

Current Tags

  • 5.0.50                                ...           latest (2 months ago)
  • 2.0.2-rc1                                ...           next (4 years ago)

194 Versions

  • 5.0.50                                ...           2 months ago
  • 5.0.49                                ...           2 months ago
  • 5.0.48                                ...           2 months ago
  • 5.0.33                                ...           a year ago
  • 5.0.32                                ...           a year ago
  • 5.0.31                                ...           a year ago
  • 5.0.30                                ...           a year ago
  • 5.0.29                                ...           a year ago
  • 5.0.28                                ...           a year ago
  • 5.0.27                                ...           a year ago
  • 5.0.26                                ...           a year ago
  • 5.0.25                                ...           a year ago
  • 5.0.24                                ...           2 years ago
  • 5.0.23                                ...           2 years ago
  • 5.0.22                                ...           2 years ago
  • 5.0.21                                ...           2 years ago
  • 5.0.20                                ...           2 years ago
  • 5.0.19                                ...           2 years ago
  • 5.0.18                                ...           2 years ago
  • 5.0.17                                ...           2 years ago
  • 5.0.16                                ...           2 years ago
  • 5.0.15                                ...           2 years ago
  • 5.0.14                                ...           2 years ago
  • 5.0.11                                ...           2 years ago
  • 5.0.10                                ...           2 years ago
  • 5.0.9                                ...           2 years ago
  • 5.0.8                                ...           2 years ago
  • 5.0.7                                ...           2 years ago
  • 5.0.6                                ...           2 years ago
  • 5.0.5                                ...           2 years ago
  • 5.0.4                                ...           2 years ago
  • 5.0.3                                ...           2 years ago
  • 5.0.2                                ...           2 years ago
  • 5.0.1                                ...           2 years ago
  • 4.0.50                                ...           2 years ago
  • 4.0.49                                ...           2 years ago
  • 4.0.48                                ...           2 years ago
  • 4.0.47                                ...           2 years ago
  • 4.0.46                                ...           2 years ago
  • 4.0.45                                ...           2 years ago
  • 4.0.44                                ...           2 years ago
  • 4.0.43                                ...           2 years ago
  • 4.0.42                                ...           2 years ago
  • 4.0.41                                ...           2 years ago
  • 4.0.40                                ...           2 years ago
  • 4.0.39                                ...           2 years ago
  • 4.0.38                                ...           2 years ago
  • 4.0.37                                ...           2 years ago
  • 4.0.36                                ...           2 years ago
  • 4.0.35                                ...           2 years ago
  • 4.0.34                                ...           2 years ago
  • 4.0.33                                ...           2 years ago
  • 4.0.32                                ...           2 years ago
  • 4.0.31                                ...           2 years ago
  • 4.0.30                                ...           2 years ago
  • 4.0.29                                ...           2 years ago
  • 4.0.28                                ...           2 years ago
  • 4.0.27                                ...           2 years ago
  • 4.0.26                                ...           2 years ago
  • 4.0.25                                ...           2 years ago
  • 4.0.24                                ...           2 years ago
  • 4.0.23                                ...           2 years ago
  • 4.0.22                                ...           3 years ago
  • 4.0.21                                ...           3 years ago
  • 4.0.20                                ...           3 years ago
  • 4.0.19                                ...           3 years ago
  • 4.0.18                                ...           3 years ago
  • 4.0.17                                ...           3 years ago
  • 4.0.16                                ...           3 years ago
  • 4.0.15                                ...           3 years ago
  • 4.0.14                                ...           3 years ago
  • 4.0.13                                ...           3 years ago
  • 4.0.12                                ...           3 years ago
  • 4.0.11                                ...           3 years ago
  • 4.0.10                                ...           3 years ago
  • 4.0.9                                ...           3 years ago
  • 4.0.8                                ...           3 years ago
  • 4.0.7                                ...           3 years ago
  • 4.0.6                                ...           3 years ago
  • 4.0.5                                ...           3 years ago
  • 4.0.4                                ...           3 years ago
  • 4.0.3                                ...           3 years ago
  • 4.0.2                                ...           3 years ago
  • 4.0.1                                ...           3 years ago
  • 3.1.30                                ...           3 years ago
  • 3.1.29                                ...           3 years ago
  • 2.0.0-rc2                                ...           4 years ago
  • 2.0.0-rc1                                ...           4 years ago
  • 1.5.1                                ...           4 years ago
  • 1.5.0                                ...           4 years ago
  • 1.4.1                                ...           4 years ago
  • 1.4.0                                ...           4 years ago
  • 1.3.0                                ...           5 years ago
  • 1.2.0                                ...           5 years ago
  • 1.1.5                                ...           5 years ago
  • 1.1.4                                ...           5 years ago
  • 1.1.3                                ...           5 years ago
  • 1.1.2                                ...           5 years ago
  • 1.1.1                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
  • 0.0.40                                ...           6 years ago
  • 0.0.39                                ...           6 years ago
  • 0.0.38                                ...           6 years ago
  • 0.0.37                                ...           6 years ago
  • 0.0.36                                ...           6 years ago
  • 0.0.35                                ...           6 years ago
  • 0.0.34                                ...           6 years ago
  • 0.0.33                                ...           6 years ago
  • 0.0.31                                ...           6 years ago
  • 0.0.30                                ...           6 years ago
  • 0.0.29                                ...           6 years ago
  • 0.0.28                                ...           6 years ago
  • 0.0.27                                ...           6 years ago
  • 0.0.26                                ...           6 years ago
  • 0.0.24                                ...           6 years ago
  • 0.0.23                                ...           6 years ago
  • 0.0.22                                ...           6 years ago
  • 0.0.21                                ...           6 years ago
  • 0.0.20                                ...           6 years ago
  • 0.0.19                                ...           6 years ago
  • 0.0.18                                ...           6 years ago
  • 0.0.17                                ...           6 years ago
  • 0.0.16                                ...           6 years ago
  • 0.0.15                                ...           6 years ago
  • 0.0.13                                ...           6 years ago
  • 0.0.12                                ...           6 years ago
  • 0.0.11                                ...           6 years ago
  • 0.0.10                                ...           6 years ago
  • 0.0.9                                ...           6 years ago
  • 0.0.8                                ...           6 years ago
  • 0.0.7                                ...           6 years ago
  • 0.0.6                                ...           6 years ago
  • 0.0.5                                ...           6 years ago
  • 0.0.4                                ...           6 years ago
  • 0.0.3                                ...           6 years ago
  • 0.0.2                                ...           6 years ago
  • 5.0.47                                ...           2 months ago
  • 5.0.46                                ...           2 months ago
  • 5.0.45                                ...           3 months ago
  • 5.0.44                                ...           3 months ago
  • 5.0.43                                ...           3 months ago
  • 5.0.42                                ...           3 months ago
  • 5.0.41                                ...           4 months ago
  • 5.0.40                                ...           4 months ago
  • 5.0.39                                ...           4 months ago
  • 5.0.38                                ...           9 months ago
  • 5.0.37                                ...           a year ago
  • 5.0.36                                ...           a year ago
  • 5.0.35                                ...           a year ago
  • 5.0.34                                ...           a year ago
  • 5.0.13                                ...           2 years ago
  • 5.0.12                                ...           2 years ago
  • 3.1.28                                ...           3 years ago
  • 3.1.27                                ...           3 years ago
  • 3.1.26                                ...           3 years ago
  • 3.1.25                                ...           3 years ago
  • 3.1.24                                ...           3 years ago
  • 3.1.23                                ...           3 years ago
  • 3.1.22                                ...           3 years ago
  • 3.1.21                                ...           3 years ago
  • 3.1.20                                ...           3 years ago
  • 3.1.19                                ...           3 years ago
  • 3.1.18                                ...           3 years ago
  • 3.1.17                                ...           3 years ago
  • 3.1.16                                ...           3 years ago
  • 3.1.15                                ...           3 years ago
  • 3.1.14                                ...           3 years ago
  • 3.1.13                                ...           3 years ago
  • 3.1.12                                ...           3 years ago
  • 3.1.11                                ...           3 years ago
  • 3.1.10                                ...           3 years ago
  • 3.1.9                                ...           3 years ago
  • 3.1.8                                ...           3 years ago
  • 3.1.7                                ...           3 years ago
  • 3.1.6                                ...           3 years ago
  • 3.1.5                                ...           3 years ago
  • 3.1.4                                ...           3 years ago
  • 3.1.3                                ...           3 years ago
  • 3.1.2                                ...           3 years ago
  • 3.1.1                                ...           3 years ago
  • 3.1.0                                ...           3 years ago
  • 3.0.0                                ...           4 years ago
  • 2.0.4                                ...           4 years ago
  • 2.0.3                                ...           4 years ago
  • 2.0.2                                ...           4 years ago
  • 2.0.2-rc1                                ...           4 years ago
  • 2.0.1                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 2.0.0-rc5                                ...           4 years ago
  • 2.0.0-rc4                                ...           4 years ago
  • 2.0.0-rc3                                ...           4 years ago
  • 0.0.32                                ...           6 years ago
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dependents (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE