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.

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.

Syntax

js
HTMLScriptElement.supports(type)

Parameters

type

A string literal that indicates the type of script for which support is to be checked. Supported values are case sensitive, and include:

"classic"

Test if classic scripts are supported. "Classic" scripts are the normal/traditional JavaScript files that predate module scripts.

"module"

Test if module scripts are supported.

"importmap"

Test if import maps are supported.

"speculationrules"

Test if speculation rules are supported and enabled.

Any other value will cause the method to return false.

Return value

Returns true if the indicated script type is supported and false otherwise.

Examples

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.

js
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");
}

Specifications

Specification
HTML
# dom-script-supports-dev

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
supports() static method
Chrome – Full support
Chrome 96 (Release date: 2021-11-15)
footnote Full support
Edge – Full support
Edge 96 (Release date: 2021-11-19)
footnote Full support
Firefox – Full support
Firefox 94 (Release date: 2021-11-02)
footnote Full support
Opera – Full support
Opera 82 (Release date: 2021-12-02)
footnote Full support
Safari – Full support
Safari 16 (Release date: 2022-09-12)
footnote Full support
Chrome Android – Full support
Chrome Android 96 (Release date: 2021-11-15)
footnote Full support
Firefox for Android – Full support
Firefox for Android 94 (Release date: 2021-11-02)
footnote Full support
Opera Android – Full support
Opera Android 67 (Release date: 2022-01-31)
footnote Full support
Safari on iOS – Full support
Safari on iOS 16 (Release date: 2022-09-12)
footnote Full support
Samsung Internet – Full support
Samsung Internet 17 (Release date: 2022-05-04)
footnote Full support
WebView Android – Full support
WebView Android 96 (Release date: 2021-11-15)
footnote Full support
WebView on iOS – Full support
WebView on iOS 16 (Release date: 2022-09-12)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

See also