Navigator: requestMediaKeySystemAccess() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2019.
Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.
TherequestMediaKeySystemAccess() method of theNavigator interface returns aPromise which delivers aMediaKeySystemAccess object that can be used to access a particular media key system, which can in turn be used to create keys for decrypting a media stream.
This method is part of theEncrypted Media Extensions API, which brings support for encrypted media and DRM-protected video to the web.
This method may have user-visible effects such as asking for permission to access one or more system resources.Consider that when deciding when to callrequestMediaKeySystemAccess(); you don't want those requests to happen at inconvenient times.As a general rule, this function should be called only when it's about time to create and use aMediaKeys object by calling the returnedMediaKeySystemAccess object'screateMediaKeys() method.
In this article
Syntax
requestMediaKeySystemAccess(keySystem, supportedConfigurations)Parameters
keySystemA string identifying the key system.For example
com.example.some-systemororg.w3.clearkey.supportedConfigurationsA non-empty
Arrayof objects conforming to the object returned byMediaKeySystemAccess.getConfiguration.The first element with a satisfiable configuration will be used.Each object may have the following properties:
Note:Either
videoCapabilitiesoraudioCapabilitiesmay be empty, but not both!labelOptionalAn optional label for the configuration, which defaults to
"".This label is preserved for configurations fetched usingMediaKeySystemAccess.getConfigurationinitDataTypesAn array of strings that indicate the data type names for the supported initialization data formats (default to an empty array).These names are names like
"cenc","keyids"and"webm"that are defined in theEncrypted Media Extensions Initialization Data Format Registry.audioCapabilitiesAn array of supported audio capabilities.If the array is empty the content type does not support audio capabilities.
Each object in the array has the following properties:
contentTypeA string indicating the media MIME-type of the media resource, such as
"audio/mp4;codecs=\"mp4a.40.2\".Note that the empty string is invalid, and that if the MIME-type definition includes parameters, such ascodecs, these must also be included.encryptionSchemeThe encryption scheme associated with the content type, such as
cenc,cbcs,cbcs-1-9.This value should be set by an application (it defaults tonull, indicating that any encryption scheme may be used).robustnessThe robustness level associated with the content type.The empty string indicates that any ability to decrypt and decode the content type is acceptable.
videoCapabilitiesAn array of supported video capabilities.The objects in the array have the same form as those in
audioCapabilities.distinctiveIdentifierA string indicating whether the implementation may use "distinctive identifiers" (or distinctive permanent identifiers) for any operations associated with any object created from this configuration.The allowed values are:
requiredThe returned object must support this feature.
optionalThe returned object may support this feature.This is the default
not-allowedThe returned object must not support or use this feature.
persistentStateA string indicating whether the returned object must be able to persist session data or any other type of state.The values are the same as for
distinctiveIdentifierand have the same meaning:required,optional(default),not-allowed.Only "temporary" sessions may be created when persistent state is not allowed.sessionTypesAn array of strings indicating the session types that must be supported.Permitted values include:
temporaryA session for which the license, key(s) and record of or data related to the session are not persisted.The application does not need to manage such storage.Implementations must support this option, and it is the default.
persistent-licenseA session for which the license (and potentially other data related to the session) will be persisted.A record of the license and associated keys persists even if the license is destroyed, providing an attestation that the license and key(s) it contains are no longer usable by the client.
Return value
APromise that fulfils with aMediaKeySystemAccess object representing the media key system configuration described bykeySystem andsupportedConfigurations.
Exceptions
In case of an error, the returnedPromise is rejected with aDOMException whose name indicates what kind of error occurred.
NotSupportedErrorDOMExceptionEither the specified
keySystemisn't supported by the platform or the browser, or none of the configurations specified bysupportedConfigurationscan be satisfied (if, for example, none of thecodecsspecified incontentTypeare available).SecurityErrorDOMExceptionUse of this feature was blocked by
Permissions-Policy: encrypted-media.TypeErrorEither
keySystemis an empty string or thesupportedConfigurationsarray is empty.
Examples
The example below shows how you might userequestMediaKeySystemAccess(), specifying a key system and configuration.
const clearKeyOptions = [ { initDataTypes: ["keyids", "webm"], audioCapabilities: [ { contentType: 'audio/webm; codecs="opus"' }, { contentType: 'audio/webm; codecs="vorbis"' }, ], videoCapabilities: [ { contentType: 'video/webm; codecs="vp9"' }, { contentType: 'video/webm; codecs="vp8"' }, ], },];navigator .requestMediaKeySystemAccess("org.w3.clearkey", clearKeyOptions) .then((keySystemAccess) => { /* use the access to get create keys */ });Specifications
| Specification |
|---|
| Encrypted Media Extensions> # navigator-extension-requestmediakeysystemaccess> |