How to Check the OffScreenCanvas is Supported by the Browser or not? Last Updated : 11 Oct, 2024 Comments Improve Suggest changes Like Article Like Report OffscreenCanvas enables rendering graphics in a separate thread, improving performance for complex applications. To determine if the OffscreenCanvas is supported by a browser, checking for its existence in the global window object is essential. Below are the methods to check the OffscreenCanvas is supported or not:Table of ContentUsing typeOf OperatorUsing transferControlToOffscreen methodApproach 1: Using typeOf OperatorThe typeof operator checks the type of a variable or object.You can use typeof to see if the OffscreenCanvas object exists in the browser.If typeof OffscreenCanvas returns 'undefined', it means OffscreenCanvas is not supported.If it returns something else, OffscreenCanvas is supported by the browser.Comparing typeof OffscreenCanvas with 'undefined' helps you determine if it is available.Syntax:if (typeof OffscreenCanvas !== "undefined") { isSupported = true; } else { isSupported = false; }Example: This example shows the implementation of the above- mentioned approach. html <!DOCTYPE html> <html> <head> <title> How to check the OffScreenCanvas is supported by the Browser or not? </title> </head> <body> <h1 style="color: green"> GeeksforGeeks </h1> <b> How to check the OffScreenCanvas is supported by the Browser or not? </b> <p> Click on the button to check for OffscreenCanvas support </p> <p> OffscreenCanvas is supported: <span class="output"></span> </p> <button onclick="checkOffscreenCanvas()"> Check for OffscreenCanvas </button> <script type="text/javascript"> function checkOffscreenCanvas() { if (typeof OffscreenCanvas !== "undefined") { isSupported = true; } else { isSupported = false; } document.querySelector(".output").textContent = isSupported; } </script> </body> </html> Output: Approach 2: Using transferControlToOffscreen methodThe transferControlToOffscreen method transfers control of a canvas to an OffscreenCanvas object.It is used to initialize the OffscreenCanvas.To check if transferControlToOffscreen is defined, use the typeof operator and compare it with 'function' using strict equality (===).If the comparison returns true, OffscreenCanvas is supported by the browser. Syntax:let canvasObj = document.createElement("canvas");if (typeof canvasObj.transferControlToOffscreen === "function") { isSupported = true;} else { isSupported = false;}Example:This example shows the implementation of the above-mentioned approach. html <!DOCTYPE html> <html> <head> <title> How to check the OffScreenCanvas is supported by the Browser or not? </title> </head> <body> <h1 style="color: green"> GeeksforGeeks </h1> <b> How to check the OffScreenCanvas is supported by the Browser or not? </b> <p> Click on the button to check for OffscreenCanvas support </p> <p> OffscreenCanvas is supported: <span class="output"></span> </p> <button onclick="checkOffscreenCanvas()"> Check for OffscreenCanvas </button> <script type="text/javascript"> function checkOffscreenCanvas() { let canvasObj = document.createElement("canvas"); if (typeof canvasObj.transferControlToOffscreen === "function") { isSupported = true; } else { isSupported = false; } document.querySelector('.output').textContent = isSupported; } </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to Check the OffScreenCanvas is Supported by the Browser or not? S sayantanm19 Follow Improve Article Tags : JavaScript Web Technologies HTML-Canvas Similar Reads How to detect HTML 5 is supported or not in the browser ? HTML 5 is the latest standard of HTML that includes many new changes and features. HTML 5 support can be detected by using three approaches:Method 1: Checking for Geolocation support: The Geolocation API was added in HTML5. It is used for identifying the user's location. The presence of this API cou 4 min read How to check if CSS property is supported in browser using JavaScript ? Few CSS properties are not supported in some browsers, thus it is required to check whether a CSS property & its value are supported in the current browser. We can find it using JavaScript using CSS.supports() method. Syntax: supports(propertyName, value) supports(condition) There are two distin 2 min read How to find whether browser supports JavaScript or not ? We will discuss how to find whether our Browser supports JavaScript or not. For this, we need to use the <noscript> tag, which defines an alternate text to be displayed to users who have disabled <script> tag in their Browsers. Since JavaScript is written inside <script> tag in HTM 2 min read How To Change The Browser To Fullscreen with JavaScript? In web development, there may be scenarios where you want to display your web application or a specific element in full-screen mode, covering the entire browser window. This can be useful for creating immersive experiences, such as games, presentations, or video players. JavaScript provides a built- 2 min read How to return true if browser tab page is focused in JavaScript ? There may be situations when we need to check if a browser tab is focused or not. The reasons for this include: Prevent sending network requests if the page is not being used by the user as this would reduce the amount of load on the server. Also, this would save upon the cost if we are using a paid 4 min read Like