Skip to content

Instantly share code, notes, and snippets.

@peterver
Created September 16, 2016 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterver/b38ceb36b3e18f734469d20484cb95f0 to your computer and use it in GitHub Desktop.
Save peterver/b38ceb36b3e18f734469d20484cb95f0 to your computer and use it in GitHub Desktop.
Detector of browser functions
// Detect canvas support
const DETECTOR = Object.freeze({
CANVAS : (function () {
if (window.CanvasRenderingContext2D) {
return 'canvas';
}
return false;
})(),
CLASSLIST : (function () {
return ('classList' in document.createElement('a'));
})(),
FULLSCREEN : (function () {
if (document.fullscreenEnabled) {
return 'fullscreenEnabled';
}
if (document.webkitFullscreenEnabled) {
return 'webkitFullscreenEnabled';
}
if (document.mozFullScreenEnabled) {
return 'mozFullScreenEnabled';
}
if (document.msFullscreenEnabled) {
return 'msFullscreenEnabled';
}
return false;
})(),
PIXELRATIO : (function () {
return window.devicePixelRatio || 1;
})(),
POINTERLOCK : (function () {
let canvas = document.createElement('canvas');
if (canvas && canvas.requestPointerLock) {
return 'requestPointerLock';
}
if (canvas && canvas.mozRequestPointerLock) {
return 'mozRequestPointerLock';
}
return false;
})(),
WEBGL : (function () {
let canvas = document.createElement('canvas');
if (canvas && canvas.getContext('webgl')) {
return 'webgl';
}
if (canvas && canvas.getContext('experimental-webgl')) {
return 'experimental-webgl';
}
return false;
})(),
});
export default DETECTOR;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment