etienne-martin/device-detector-js

Can we also detect GPU?

shah-manthan9 opened this issue · 2 comments

⚠️ Missing/incorrect detections should be reported at https://github.com/matomo-org/device-detector/issues instead of this repo.

I have a scenario where I would like to detect the GPU as well. Doing that with one more library is possible, however I was thinking if we can do it using one.

No Way

This is possible in the browser by using the WEBGL_debug_renderer_info extension. Unfortunately this is not something we can include in the library since it would work only in the browser.

Here's how you can do that yourself:

const getGPU = () => {
  const canvas = document.createElement("canvas");
  const gl = canvas.getContext("webgl");

  // webgl is not supported
  if (!gl) return;

  const supportedExtension = gl.getSupportedExtensions();
  const webglDebugRendererInfo = gl.getExtension("WEBGL_debug_renderer_info");

  if (!supportedExtension?.includes("WEBGL_debug_renderer_info")) return;
  if (!webglDebugRendererInfo) return;

  return {
    vendor: gl.getParameter(webglDebugRendererInfo.UNMASKED_VENDOR_WEBGL),
    model: gl.getParameter(webglDebugRendererInfo.UNMASKED_RENDERER_WEBGL)
  };
};

console.log(getGPU());

Result:

{
  "vendor": "Intel Inc.",
  "model": "Intel(R) Iris(TM) Plus Graphics 655"
}