Skip to content

Instantly share code, notes, and snippets.

@erkobridee
Last active February 13, 2026 13:42
Show Gist options
  • Select an option

  • Save erkobridee/13cb4f86d032b6bdf908d9c4b0feb20e to your computer and use it in GitHub Desktop.

Select an option

Save erkobridee/13cb4f86d032b6bdf908d9c4b0feb20e to your computer and use it in GitHub Desktop.
/*
based on:
https://github.com/add-qwq/WebGL-GPU-Detector/blob/main/gpu-detector.js
https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/By_example/Detect_WebGL
*/
export const hasWebGLSupport = () => {
if (!window.WebGLRenderingContext) {
return false
}
let canvas = null
try {
canvas = document.createElement('canvas')
// Get WebGLRenderingContext from canvas element.
const gl = canvas.getContext('webgl')
if (!gl) return false
return gl instanceof WebGLRenderingContext
} catch (_e) {
console.error('GPU acceleration detection exception')
return false
} finally {
if (canvas && canvas.parentNode) {
canvas.parentNode.removeChild(canvas)
}
}
}
export default hasWebGLSupport
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment