Is there any option to detect in the view function if the browser from which the user is coming is webGL compatible or not?
2 Answers
Detecting WebGL is a matter of using JavaScript on the frontend (see Proper way to detect WebGL support?), so I don't think there is a way to do this directly in the backend in a Django view.
What you could do is perform the detection with JavaScript on the first page the user visits and use AJAX to store the result in a server-side variable which you can use in subsequent requests to decide whether to use WebGL features or not.

- 1
- 1

- 2,123
- 3
- 22
- 29
-
Is there a way that this information is given through the request? Same as the requests gives GET, POST, COOKIES, etc.. so it also gives WEBGLCOMPATIBLE or similar called variable – Ignasi Jan 05 '17 at 13:46
-
@Ignasi not that I know of. – voodoo-burger Jan 05 '17 at 13:48
-
Thank you very much @voodoo-burger! – Ignasi Jan 05 '17 at 13:53
Expanding on voodoo's answer, here is the javascript to quickly determine wheter a client has webgl support
var canvas = document.getElementById("canvas");
var names = ["webgl", "experimental-webgl", "webkit-3d", "mozwebgl"];
var webgl_supported = false;
for(var i in names) {
try {
gl = canvas.getContext(names[i], { });
if (gl && typeof gl.getParameter == "function") {
webgl_supported = true;
break;
}
} catch(e) { }
}
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", "/webgl_enabled_handler");
xmlhttp.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
xmlhttp.send(JSON.stringify({webgl_enabled: webgl_supported }));
This assumes that in your html page/template there's a canvas element with id "canvas".
The resulting json would be sent as a POST request to django after page loads
Unfortunately I doubt there's a way to determine webgl support through a general GET request from django

- 168
- 1
- 8
-
2FYI: "webkil-3d" and "mozwebgl" are not needed. They were a thing for a few months in like 2010 and are long gone. Similarly "experimental-webgl" is only used by Edge at this point because it's WebGL implementation is still not spec compliant. – gman Jan 06 '17 at 03:06