Identifying IE11 WebGL compatibility (specifically clearStencil and shaders) accurately

Some webGL methods are not functioning properly in IE11 Version 11.0.9600.16428 and older versions, as detailed here: https://github.com/mrdoob/three.js/issues/3600)

For example, the clearStencil method seems to exist but does not work as expected. I am looking for a way to detect this issue and provide feedback to the user. I attempted to use Detector.js from Three.js, but it only checks if the browser and graphics card support WebGL, not if they support all necessary features.

I attempted a WebGL check like so:

var supportsWebGL=function(){
    if(Detector.webgl){
        var _canvas = document.createElement( 'canvas' );
        var _gl = _canvas.getContext( 'webgl' ) || _canvas.getContext( 'experimental-webgl' );
        try{
            _gl.clearStencil( 0 );
        }catch(e){
            return false;
        }
        return true;
    }else{
        return false;
    }
}

In IE11 (11.0.9600.16428), the supportsWebGL method returns true, but throws an error like:

WEBGL11095: INVALID-OPERATION: clearStencil: Method not currently supported.

Now, I want my supportsWebGL method to recognize this incompatibility and return false. Any suggestions on how to achieve this?

Answer №1

I managed to find a solution using the _gl.getError() method.

var checkWebGLSupport=function(){
    if(Detector.webgl){
        var _canvas = document.createElement( 'canvas' );
        var _gl = _canvas.getContext( 'webgl' ) || _canvas.getContext( 'experimental-webgl' );
        var errors=undefined;        
        try{
            _gl.clearStencil( 0 );
            errors=_gl.getError();
        }catch(e){
            return false;
        }
        return errors==0;
    }else{
        return false;
    }
}

The method will only return true if errors is equal to zero. You can add other methods you want to check for in the try/catch block.

If you're looking for a solution that doesn't rely on Three.js, consider this alternative:

var checkWebGLSupport=function(){
    if(!window.WebGLRenderingContext) return false;
    try {
        var _canvas = document.createElement('canvas');
        var _gl = _canvas.getContext('webgl') || _canvas.getContext('experimental-webgl');
        _gl.clearStencil(0);
        var errors = _gl.getError();
        return errors == 0;
    } catch (e) {
        return false;
    }
}

Answer №2

A method that comes to mind is checking the Browser and its specific version.

Use this code snippet to extract the browser name along with its major version:

var browserInformation = (function() {
var temporal = undefined;
var userAgent = navigator.userAgent;
var matches = userAgent.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
if (/trident/i.test(matches[1])) {
    temporal = /\brv[ :]+(\d+)/g.exec(userAgent) || [];
    return 'Internet Explorer ' + (temporal[1] || '');
}
if (matches[1] === 'Chrome') {
    temporal = userAgent.match(/\bOPR\/(\d+)/);
    if (temporal != null)
        return 'Opera ' + temporal[1];
}
matches = matches[2] ? [matches[1], matches[2]] : [navigator.appName, navigator.appVersion, '-?'];
if ((temporal = userAgent.match(/version\/(\d+)/i)) != null)
    matches.splice(1, 1, temporal[1]);
return matches.join(' ');})();

This script will output a text in the form [Browsername Version], for example: Internet Explorer 11.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Testing the jQuery UI datepicker with QUnit: A Step-by-Step Guide

As a newcomer to Qunit, I have a query that I'd like to address. I've developed a JavaScript file to incorporate a datepicker and have created a test script using Qunit. My objective is to display the calendar, choose a date, and confirm that th ...

Error in Syntax & Function is Undefined

issues controllers.js:6 Uncaught SyntaxError: Unexpected token ( ionic.bundle.js:26794 Error: [ng:areq] Argument 'MenuCtrl' is not a function, got undefined In the process of developing a cross-platform app using Ionic framework with WordPress ...

Why is it that every Strapi user is able to modify any user's profile?

I recently introduced a new field named 'config' (type: json) to the User model. When utilizing the built-in swagger of Strapi local document, I encountered an issue where I was able to update another user's config data using the put method. ...

Steps for generating a unique division element for every javascript response

How can I dynamically create a new div for each response in JavaScript? The message is in JSON format containing all the messages sent and received. This is my JavaScript code: $.get("MessageServlet", function (responseJson) { $.each(responseJ ...

Texture's shadow map opaqueness

Wondering if there's a way to address the issue with the shadow map shown below. It seems like the shadowmap isn't properly rendering the alpha test, resulting in shadows only appearing for the tree planes geometry and not the leaves. Could this ...

Redefining the onClick function in the Redux 'presentation' component to include parameters

How can I pass an object as an argument to a function in a redux "presentation component" efficiently? In my <BookList /> container component, I display a <BookListRow/> presentation component for each book. I want to add a button in each Boo ...

Is it possible to incorporate JSON objects within 'if' conditions?

I am in the process of developing a website for my game server and I want to showcase user information using the Steam API. $.getJSON('/steamapi', function(data) { document.getElementById("staff-inner").innerHTML = `${data.response.players.ma ...

What is the best way to send the accurate data type from PHP to Javascript?

My approach involves using the jQuery post method to insert a record in MySQL. The issue I'm facing is that when comparing the output of the PHP using ==, all three conditionals function correctly. However, with ===, the first two conditionals return ...

Is it possible to asynchronously retrieve the information from the HTTP request body in a Node.js environment?

I am trying to send an HTTP POST request to a node.js HTTP server that is running locally. My goal is to extract the JSON object from the HTTP body and utilize the data it contains for server-side operations. Below is the client application responsible fo ...

What is the purpose of declaring a variable within a class and then assigning it to "this" in the constructor?

The following code snippet demonstrates the declaration of a variable constObj within the Test class. The object constObj is then assigned to this in the constructor. Why must we declare the variable again when it is already being assigned to this in the ...

Why is the appsecret_proof invalid?

Currently, I am in the process of developing a new application. I am utilizing the Javascript API for logging in (v2.4) and the latest version of the PHP API (v5). To test the functionality of my app, I have created a Test App. With the Javascript API, I h ...

Executing an Ajax request to a document containing <script> elements

Recently, I developed a sample page that effectively mimics table layout pages but without relying on the traditional mobile-unfriendly table features. The structure of the page is as follows: <html> ... <body> <div type="page" ...

AngularJS - Use a directive to hide a div upon clicking inside an inner element

I am attempting to create a function that will hide a specific box when clicking on a link within that same box. My goal is to utilize a directive in order to easily add additional functionality once the box is hidden, making it adaptable for other views ...

How can the total price for a shopping cart be computed in React/Redux?

After extensive searches on Google and SO, I'm still coming up empty-handed when it comes to calculating the total price of items in a cart. Many tutorials stop at basic cart functionalities like "Add item to cart" or "increase/decrease quantity", but ...

Having trouble with installing node-sass on a Windows system

Having trouble installing node-sass even though I have both Python 3 and 2.7 installed, along with the Visual Studio build tools. Node gyp continues to fail despite attempts to uninstall and rebuild node-sass. How can I resolve this issue? Below is the com ...

Transferring a file between server APIs using Node.js (Express)

I have a situation where I need to make a client-side API request that sends a POST request to my express server with a formData file. This file then needs to be accessed in the server route and forwarded to a third party API. const addAttachment = async ...

Loading an HTML page inside a tab's content in Angular: A seamless and efficient approach

There are multiple tabs within the master.html page, each loading a different tab*.html page with AngularJS code. The problem arises when I try to load the tab*.html pages separately; they work fine. Here is a Plunker example for a single page: Plunker fo ...

Speedy Guide to React's useState and useEffect

I've been struggling to update an older style react class to a new function utilizing useState and useEffect in place of this.setState and componentDidMount. I can't seem to get it working properly, and I find hooks very confusing. Could someone ...

Displaying an alert when the text box contains a duplicate value

I have a set of input fields with various values that can be edited but must not be left empty (if left empty, display an alert). When I update a field with a new value, if that new value matches any of the other input field values, I want to display an al ...

Struggling with the nested array of objects

I have utilized Mongodb aggregation and used the $facet operator to count each value of "reli" and "prov" from the collection. Here is the code I used to retrieve results from the database: const keyy = await db.aggregate([ $facet: { "reli": [ { $group ...