files/en-us/web/api/mediakeys/getstatusforpolicy/index.md
{{APIRef("Encrypted Media Extensions")}}{{SecureContext_Header}}
The getStatusForPolicy() method of the {{domxref("MediaKeys")}} interface is used to check whether the Content Decryption Module (CDM) would allow the presentation of encrypted media data using the keys, based on the specified policy requirements.
The method returns a {{jsxref("Promise")}} that resolves with a string that indicates the status of the key with respect to all the specified policy requirements.
If the value resolves to "usable" then the content can be decrypted and presented at the ideal quality.
Other values indicate reasons why the keys cannot be used for presenting the content; in some cases they hint at fallback options, such as playing the content at a lower quality.
The policy restrictions currently only include a restriction on the minimum supported HDCP version.
Note that the method checks a "hypothetical key" against the restrictions. The application does not need to first create a real key and fetch a real license using {{domxref("MediaKeySession")}}, and the {{domxref("MediaKeys")}} doesn't even have to be attached to audio or video elements.
getStatusForPolicy(policy)
policy {{optional_inline}}
minHdcpVersion {{optional_inline}}
1.0, 1.4, 2.2, 2.3.[!NOTE] At least one policy restriction must be specified, so
minHdcpVersionis only "technically" optional.
A {{jsxref("Promise")}} that resolves with a string indicating whether the key can be used for decryption given the specified policy.
The string can have one of the following values:
usable
expired
released
output-restricted
output-downscaled
usable-in-future
status-pending
internal-error
TypeError
policy has no defined properties (policy restrictions), or a property key is not valid.NotSupportedError
This example checks if keys are usable for decrypting a particular video format when using a minimum HDCP version of 2.2.
[!NOTE] A status of
output-restrictedwhen you're using an external display can be caused by hardware HDCP incompatibility issues. If using a laptop, you may be able to "fix" this by disconnecting the external display.
<pre id="log"></pre>
#log {
height: 100px;
overflow: scroll;
padding: 0.5rem;
border: 1px solid black;
}
const logElement = document.querySelector("#log");
function log(text) {
logElement.innerText = `${logElement.innerText}${text}\n`;
logElement.scrollTop = logElement.scrollHeight;
}
const config = [
{
videoCapabilities: [
{
contentType: 'video/mp4; codecs="avc1.640028"',
encryptionScheme: "cenc",
robustness: "SW_SECURE_DECODE", // Widevine L3
},
],
},
];
getMediaStatus(config);
async function getMediaStatus(config) {
try {
const mediaKeySystemAccess = await navigator.requestMediaKeySystemAccess(
"com.widevine.alpha",
config,
);
const mediaKeys = await mediaKeySystemAccess.createMediaKeys();
const mediaStatus = await mediaKeys.getStatusForPolicy({
minHdcpVersion: "2.2",
});
log(mediaStatus);
// Get the content or fallback to an alternative if the
// keys are not usable
if (mediaStatus === "usable") {
console.log("HDCP 2.2 can be enforced.");
// Fetch the high resolution protected content
} else {
log("HDCP 2.2 cannot be enforced");
// Fallback other content, get license, etc.
}
} catch (error) {
log(error);
}
}
{{EmbedLiveSample("Check if keys are usable with HDCP restriction")}}
{{Specifications}}
{{Compat}}