
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
detect-gpu
Advanced tools
Classify GPU's based on their benchmark score in order to provide an adaptive experience.
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.
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
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.
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[]>;
};
})
Special care has been taken to make sure all browsers that support WebGL are also supported by detect-gpu including IE 11.
My work is released under the MIT license.
detect-gpu uses both mobile and desktop benchmarking scores from https://gfxbench.com.
gpu.js is a JavaScript library for GPU-accelerated computing in the browser. It allows you to run complex computations on the GPU, which can significantly speed up performance for certain tasks. Unlike detect-gpu, which focuses on detecting GPU information, gpu.js is designed for leveraging the GPU for computational tasks.
webgl-detect is a package that helps in detecting WebGL capabilities of the user's browser. It provides information about the WebGL version, supported extensions, and renderer details. While detect-gpu focuses on GPU detection, webgl-detect is more about understanding the WebGL capabilities of the browser.
FAQs
Classify GPU's based on their benchmark score in order to provide an adaptive experience.
The npm package detect-gpu receives a total of 658,100 weekly downloads. As such, detect-gpu popularity was classified as popular.
We found that detect-gpu demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

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.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.