- Home /
Detection scheme for WebGL or Unity Plugin playback
Hi Folks,
Our project will be published online, and I would like to find a way to make the playback experience as seamless as possible for the end user. Is there a JavaScript or JQuery method for detecting if a browser can play a Unity WebGL project, and if it can't, redirect the browser to a page with a version that runs with the plugin? I know I can get the browser type and version but I would prefer to not rely on a list of compatible/non-compatible WebGL browsers, and instead use something smart enough to detect the browser's compatibility with WebGL.
Thanks for any leads or info. --Kevin
Answer by RSoj · Jun 25, 2015 at 01:03 PM
There is a function in generated file UnityConfig.js, which can tell you about browser WebGL support:
var hasWebGL = (function ()
{
if (!window.WebGLRenderingContext)
{
// Browser has no idea what WebGL is. Suggest they
// get a new browser by presenting the user with link to
// http://get.webgl.org
return 0;
}
var canvas = document.createElement('canvas');
var gl = canvas.getContext("webgl");
if (!gl)
{
gl = canvas.getContext("experimental-webgl");
if (!gl)
{
// Browser could not initialize WebGL. User probably needs to
// update their drivers or get a new browser. Present a link to
// http://get.webgl.org/troubleshooting
return 0;
}
}
return 1;
})();
I use it along with browser detection: To NOT run WebGL in IE, to run WebGL in Chrome, and in all other browsers I run WebPlayer as default. But if user don't have WebPlayer installed, he can choose to run in WebGL instead (if supported by browser).
My project runs nicely also in Opera WebGL, in Safari not so much.
For browser type and version detection I recommend bowser.
This is just what I was looking for RSoj. Thanks so much for the info.
Thanks so much for the answer! Very cool, almost exactly the procedure I need. And with the bowser.js script i can easily exclude mobiles and tablets, which are also not compatible with our game.
Bowser looks like it is exactly what I need. But this is my first time trying to use something like this. Can anyone point me in the direction of a simple tutorial on how to implement bowser in Unity? I've been googling for a while and haven't found any nice, clear instructions. (And I did look at the Unity Manual entry on Calling JavaScript functions from Unity scripts, I'm still lost on the exact steps to follow.)
Sorry but that's something completely uweless inside Unity. You can build a Unity game / application for WebGL simply by selecting WebGL as build target. Of course your Unity installation need to have WebGL support module installed. If you use the UnityHub you can check your installation under the "Installs" tab and click "Add Modules" from the context menu.a simple tutorial on how to implement bowser in Unity?
This question as well as that Bowser framework is about pure javascript code as a Unity WebGL build can only run in a browser that supports WebGL. So the above mentioned method has to be used before any Unity content starts. This is pure web development and not related to Unity.
However all this is pretty irrelevant nowadays as most browsers do support WebGL. This question was asked at a time when WebGL was a quite new thing. Before that we have the UnityWebplayer plugin. However since google decided to drop the support for plugins for security reasons all major browsers have followed this example and the UnityWebPlayer does no longer exist. Currently if a browser does not support WebGL your Unity WebGL build simply does not load at all. What you do when the browser does not support WebGL is also pure web design and not related to Unity.
If you have a concrete question about gamedevelopment with the Unity engine, please ask a new seperate question. However questions about javascript and web design do not belong here as those are things outside of the Untiy scope. Just for the same reason questions about how to install PC hardware do not belong here, even though you need such hardware to run a Unity game.
Answer by Schubkraft · Jun 11, 2015 at 03:19 PM
For now it should be pretty simple to write since the only browsers we are officially supporting are desktop Firefox and Chrome. So you only have to check for those two.
Your answer
Follow this Question
Related Questions
WebGL crash when certain actions ingame 0 Answers
WebGL Audio on iOS Safari 4 Answers
how to get the browser user agent in unity webgl? 1 Answer
Webgl build disables mouse wheel scroll on webpage. 4 Answers
WebGL: Scroll Camera 0 Answers