The supports() static method of the HTMLScriptElement 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 return true for classic and module scripts, which are supported by most modern browsers.
HTMLScriptElement.supports(type)
Returns true if the indicated script type is supported and false otherwise.
The code below shows how to check if HTMLScriptElement.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 {
checkSupport("module");
checkSupport("classic");
checkSupport("importmap");
checkSupport("speculationrules");
checkSupport("anything else");
}