Skip to content

Instantly share code, notes, and snippets.

@cvan
Last active September 5, 2024 07:22
Show Gist options
  • Save cvan/042b2448fcecefafbb6a91469484cdf8 to your computer and use it in GitHub Desktop.
Save cvan/042b2448fcecefafbb6a91469484cdf8 to your computer and use it in GitHub Desktop.
use JavaScript to detect GPU used from within your browser
var canvas = document.createElement('canvas');
var gl;
var debugInfo;
var vendor;
var renderer;
try {
gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
} catch (e) {
}
if (gl) {
debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
vendor = gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL);
renderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
}
// Sample output:
//
// » console.log(renderer);
// ATI Technologies Inc. AMD Radeon R9 M370X OpenGL Engine
@mkateregga
Copy link

Hello anyone,

I have a data set of webgl debugger renderer similar to what is generated by this webgl-detect-gpu.js. My interest is to try and detect from this data which one is malicious or fraudulent. Does anyone has an idea how I could do that using a python script or bash script?

@FrancYescO
Copy link

If can be usefull to anyone:
changing line https://gist.github.com/cvan/042b2448fcecefafbb6a91469484cdf8#file-webgl-detect-gpu-js-L8
to
gl = canvas.getContext('webgl', { powerPreference: "high-performance" }) || canvas.getContext('experimental-webgl', { powerPreference: "high-performance" });

allow you to create the canvas using the -if any- high performance GPU

@SoumavaBanerjee
Copy link

Hey, thanks for putting this up! It really helped me.

@justforuse
Copy link

justforuse commented Sep 1, 2021

Just wonder what the console output in M1, can anyone tell me?😊

@danigb
Copy link

danigb commented Sep 20, 2021

The above script with M1:

{
  debugInfo: {
    UNMASKED_RENDERER_WEBGL: 37446,
    UNMASKED_VENDOR_WEBGL: 37445
  },
  renderer: "Apple M1",
  vendor: "Apple"
}

Or using https://github.com/pmndrs/detect-gpu

{
  "gpu": "apple m1 (Apple M1)",
  "isMobile": false,
  "tier": 1,
  "type": "FALLBACK"
}

@justforuse
Copy link

@danigb thanks bro

@adamthewan
Copy link

Using this method on M1, sometimes getting Google SwiftShader

@athlonzam
Copy link

do you have vue3 version. thanks in advance

@tskj
Copy link

tskj commented Aug 18, 2022

Just a note for anyone who'll use this to detect M1; I get the same as @danigb on Firefox, but on Chrome I get the following:

{
  debugInfo: {
    UNMASKED_RENDERER_WEBGL: 37446,
    UNMASKED_VENDOR_WEBGL: 37445
  },
  renderer: "ANGLE (Apple, Apple M1 Pro, OpenGL 4.1)",
  vendor: "Google Inc. (Apple)"
}

@vimal691
Copy link

vimal691 commented Dec 30, 2022

Can anyone tell me what will be the output for android phone and Windows desktop. Both for chrome and mozilla.

@noel-friedrich
Copy link

Can anyone tell me what will be the output for android phone and Windows desktop. Both for chrome and mozilla.

Using Android Phone (Samsung S10e) I got:

vendor: Google Inc. (ARM)
renderer: ANGLE (ARM, Mali-G76, OpenGL ES 3.2)

On Windows 11 (Acer Aspire A315-56, Intel i3-1005G1 CPU) I got:

vendor: Google Inc. (Intel)
renderer: ANGLE (Intel, Intel(R) UHD Graphics Direct3D11 vs_5_0 ps_5_0, D3D11)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment