---
title: MediaKeySession
slug: Web/API/MediaKeySession
tags:
  - API
  - Audio
  - EncryptedMediaExtensions
  - Interface
  - Media
  - MediaKeySession
  - NeedsExample
  - NeedsTranslation
  - Reference
  - TopicStub
  - Video
translation_of: Web/API/MediaKeySession
---
<p>{{APIRef("EncryptedMediaExtensions")}}{{SeeCompatTable}}</p>

<p>The <code><strong>MediaKeySession</strong></code> interface of the <a href="/en-US/docs/Web/API/EncryptedMediaExtensions_API">EncryptedMediaExtensions API</a> represents a context for message exchange with a content decryption module (CDM).</p>

<h2 id="Properties">Properties</h2>

<dl>
 <dt>{{domxref("MediaKeySession.closed")}} {{readonlyInline}}</dt>
 <dd>Returns a {{jsxref("Promise")}} signaling when a <code>MediaKeySession</code> closes. This promise can only be fulfilled and is never rejected. Closing a session means that licenses and keys associated with it are no longer valid for decrypting media data. </dd>
 <dt>{{domxref("MediaKeySession.expiration")}} {{readonlyInline}}</dt>
 <dd>The time after which the keys in the current session can no longer be used to decrypt media data, or <code>NaN</code> if no such time exists. This value is determined by the CDM and measured in milliseconds since January 1, 1970, UTC. This value may change during a session lifetime, such as when an action triggers the start of a window.</dd>
 <dt>{{domxref("MediaKeySession.keyStatuses")}} {{readonlyInline}}</dt>
 <dd>Contains a reference to a read-only {{domxref("MediaKeyStatusMap")}} of the current session's keys and their statuses.</dd>
 <dt>{{domxref("MediaKeySession.sessionId")}} {{readonlyInline}}</dt>
 <dd>Contains a unique string generated by the CDM for the current media object and its associated keys or licenses.</dd>
</dl>

<h3 id="Event_handlers">Event handlers</h3>

<dl>
 <dt>{{domxref("MediaKeySession.onkeystatuseschange")}}</dt>
 <dd>Sets the {{domxref('EventHandler')}} called when there has been a change in the keys in a session or their statuses.</dd>
 <dt>{{domxref("MediaKeySession.onmessage")}}</dt>
 <dd>Sets the {{domxref('EventHandler')}} called when the content decryption module has generated a message for the session.</dd>
</dl>

<h2 id="Methods">Methods</h2>

<dl>
 <dt>{{domxref("MediaKeySession.close()")}}</dt>
 <dd>
 <p class="p1">Returns a {{jsxref("Promise")}} after notifying the current media session is no longer needed and that the CDM should release any resources associated with this object and close it.</p>
 </dd>
 <dt>{{domxref("MediaKeySession.generateRequest()")}}</dt>
 <dd>Returns a {{jsxref("Promise")}} after generating a media request based on initialization data.</dd>
 <dt>{{domxref("MediaKeySession.load()")}}</dt>
 <dd>Returns a {{jsxref("Promise")}} that resolves to a boolean value after loading data for a specified session object. </dd>
 <dt>{{domxref("MediaKeySession.remove()")}}</dt>
 <dd>Returns a {{jsxref("Promise")}} after removing any session data associated with the current object.</dd>
 <dt>{{domxref("MediaKeySession.update()")}}</dt>
 <dd>Returns a {{jsxref("Promise")}} after loading messages and licenses to the CDM.</dd>
</dl>

<h2 id="Examples">Examples</h2>

<pre class="brush: js">// TBD</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('EME', '#mediakeysession-interface', 'MediaKeySession')}}</td>
   <td>{{Spec2('EME')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<div>{{CompatibilityTable}}</div>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Edge</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatChrome(42.0)}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>onkeystatuseschange</code> and <code>onmessage</code></td>
   <td>{{CompatChrome(55.0)}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatOpera(42)}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Android Webview</th>
   <th>Edge</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>Firefox OS</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
   <th>Chrome for Android</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatChrome(43.0)}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatChrome(42.0)}}</td>
  </tr>
  <tr>
   <td><code>onkeystatuseschange</code> and <code>onmessage</code></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatChrome(55.0)}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatOperaMobile(42)}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatChrome(55.0)}}</td>
  </tr>
 </tbody>
</table>
</div>