files/en-us/web/api/navigator/requestmediakeysystemaccess/index.md
{{APIRef("Encrypted Media Extensions")}}{{SecureContext_Header}}
The requestMediaKeySystemAccess() method of the {{domxref("Navigator")}} interface returns a {{jsxref('Promise')}} which delivers a {{domxref('MediaKeySystemAccess')}} 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 the Encrypted 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 call requestMediaKeySystemAccess(); 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 a {{domxref("MediaKeys")}} object by calling the returned {{domxref("MediaKeySystemAccess")}} object's {{domxref("MediaKeySystemAccess.createMediaKeys", "createMediaKeys()")}} method.
requestMediaKeySystemAccess(keySystem, supportedConfigurations)
keySystem
com.example.some-system or org.w3.clearkey.supportedConfigurations
: A non-empty {{jsxref('Array')}} of objects conforming to the object returned by {{domxref("MediaKeySystemAccess.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!
label {{optional_inline}}
"".
This label is preserved for configurations fetched using {{domxref("MediaKeySystemAccess.getConfiguration")}}initDataTypes
"cenc", "keyids" and "webm" that are defined in the Encrypted Media Extensions Initialization Data Format Registry.audioCapabilities
: An 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:
contentType
"audio/mp4;codecs=\"mp4a.40.2\".
Note that the empty string is invalid, and that if the MIME-type definition includes parameters, such as codecs, these must also be included.encryptionScheme
cenc, cbcs, cbcs-1-9.
This value should be set by an application (it defaults to null, indicating that any encryption scheme may be used).robustness
videoCapabilities
audioCapabilities.distinctiveIdentifier
required
optional
not-allowed
persistentState
distinctiveIdentifier and have the same meaning: required, optional (default), not-allowed.
Only "temporary" sessions may be created when persistent state is not allowed.sessionTypes
temporary
persistent-license
A {{jsxref('Promise')}} that fulfils with a {{domxref('MediaKeySystemAccess')}} object representing the media key system configuration described by keySystem and supportedConfigurations.
In case of an error, the returned {{jsxref('Promise')}} is rejected with a {{domxref('DOMException')}} whose name indicates what kind of error occurred.
NotSupportedError {{domxref("DOMException")}}
keySystem isn't supported by the platform or the browser, or none of the configurations specified by supportedConfigurations can be satisfied (if, for example, none of the codecs specified in contentType are available).SecurityError {{domxref("DOMException")}}
Permissions-Policy: encrypted-media.keySystem is an empty string or the supportedConfigurations array is empty.The example below shows how you might use requestMediaKeySystemAccess(), 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}}
{{Compat}}