Skip to content

Commit

Permalink
Merge pull request fingerprintjs#57 from Schinkentanz/master
Browse files Browse the repository at this point in the history
Add detection for webgl support.
  • Loading branch information
Valve committed Jul 17, 2015
2 parents 92e22c6 + 3f43175 commit 6a78d84
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
21 changes: 20 additions & 1 deletion fingerprint2.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
return keys;
},
webglKey: function(keys) {
if(!this.options.excludeWebGL && this.isCanvasSupported()) {
if (!this.options.excludeWebGL && this.isWebGlSupported()) {
keys.push(this.getWebglFp());
}
return keys;
Expand Down Expand Up @@ -659,6 +659,14 @@
result.push("webgl stencil bits:" + gl.getParameter(gl.STENCIL_BITS));
result.push("webgl vendor:" + gl.getParameter(gl.VENDOR));
result.push("webgl version:" + gl.getParameter(gl.VERSION));

if (!gl.getShaderPrecisionFormat) {
if (typeof NODEBUG === "undefined") {
this.log("Skipping FPing of specific webgl functions (getShaderPrecisionFormat). This browser does not support them.");
}
return result.join("~");
}

result.push("webgl vertex shader high float precision:" + gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision);
result.push("webgl vertex shader high float precision rangeMin:" + gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.HIGH_FLOAT ).rangeMin);
result.push("webgl vertex shader high float precision rangeMax:" + gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.HIGH_FLOAT ).rangeMax);
Expand Down Expand Up @@ -695,6 +703,7 @@
result.push("webgl fragment shader low int precision:" + gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.LOW_INT ).precision);
result.push("webgl fragment shader low int precision rangeMin:" + gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.LOW_INT ).rangeMin);
result.push("webgl fragment shader low int precision rangeMax:" + gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.LOW_INT ).rangeMax);

return result.join("~");
},
getAdBlock: function(){
Expand Down Expand Up @@ -846,6 +855,16 @@
var elem = document.createElement("canvas");
return !!(elem.getContext && elem.getContext("2d"));
},
isWebGlSupported: function() {
if (!this.isCanvasSupported()) {
return false;
}

var canvas = document.createElement("canvas"),
glContext = canvas.getContext && (canvas.getContext("webgl") || canvas.getContext("experimental-webgl"));

return !!window.WebGLRenderingContext && !!glContext;
},
isIE: function () {
if(navigator.appName === "Microsoft Internet Explorer") {
return true;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"eslint": "^0.14.1",
"gulp": "^3.8.11",
"gulp-eslint": "^0.4.2",
"gulp-jasmine-phantom": "^1.2.0",
"gulp-uglify": "^1.1.0"
},
"scripts": {
Expand Down

0 comments on commit 6a78d84

Please sign in to comment.