explainers

HTMLScriptElement.supports(type) method

Author: horo@chromium.org - Last Updated: 2021-09-06

Summary

Provides a unified way to detect new features that use script elements.

Motivation

Currently there is no simple way to know what kind of types can be used for HTMLScriptElement’s type attribute.

There are several new feature proposals using the script element.

We can use the nomodule attribute to detect the module type support as this example shows. But there is no unified method to detect such new features. (E.g.: https://github.com/WICG/import-maps/issues/171) If we have the HTMLScriptElement.supports(type) method which is like HTMLLinkElement.relList.supports(), we can easily detect such features.

Usage

if (HTMLScriptElement.supports('importmap')) {
  console.log('Your browser supports import maps.');
}
if (HTMLScriptElement.supports('speculationrules')) {
  console.log('Your browser supports speculationrules.');
}
if (HTMLScriptElement.supports('bundlepreload')) {
  console.log('Your browser supports bundlepreload.');
}

Security Considerations

There are no known security impacts of this API.

Privacy Considerations

This API can be used as part of browser fingerprinting technique of checking the availability of each feature. However, in general, these are already feature-detectable by asynchronous way or by fetching useless HTTP requests. This API itself only introduces one bit of information about the availability of the API itself. But, this is also the case when introducing any other new feature-detectable APIs.