HTMLScriptElement: supports() static method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2022.
Thesupports() static method of theHTMLScriptElement interface provides a simple and consistent method to feature-detect what types of scripts are supported by the user agent.
The method is expected to returntrue for classic and module scripts, which are supported by most modern browsers.
In this article
Syntax
HTMLScriptElement.supports(type)Parameters
typeA string literal that indicates the type of script for which support is to be checked.Supported values are case sensitive, and include:
"classic"Test ifclassic scripts are supported."Classic" scripts are the normal/traditional JavaScript files that predate module scripts.
"module"Test ifmodule scripts are supported.
"importmap"Test ifimport maps are supported.
"speculationrules"Test ifspeculation rules are supported and enabled.
Any other value will cause the method to return
false.
Return value
Returnstrue if the indicated script type is supported andfalse otherwise.
Examples
The code below shows how to check ifHTMLScriptElement.supports() is defined, and if so, to use it to test whether particular types of scripts are supported.
const log = document.getElementById("log");function checkSupport(type) { const result = HTMLScriptElement.supports(type) ? "true" : "false"; log.textContent += `HTMLScriptElement.supports('${type}') is ${result}\n`;}if (typeof HTMLScriptElement.supports === "undefined") { log.textContent = "HTMLScriptElement.supports() method is not supported";} else { // Check if various script types are supported checkSupport("module"); checkSupport("classic"); checkSupport("importmap"); checkSupport("speculationrules"); // Any other value will cause the method to return false checkSupport("anything else");}<textarea rows="6" cols="80"></textarea>Specifications
| Specification |
|---|
| HTML> # dom-script-supports-dev> |