recursal/MDN huggingface dataset:
PaymentManager: enableDelegations() method
==========================================

**Experimental:** **This is an experimental technology**  
Check the Browser compatibility table carefully before using this in production.

The **`enableDelegations()`** method of the `PaymentManager` interface delegates responsibility for providing various parts of the required payment information to the payment app rather than collecting it from the browser (for example, via autofill).

For example, if the `requestShipping` option is set to `true` in the options object when invoking the `PaymentRequest()` constructor, a shipping address will be returned.

* If `enableDelegations()` was used to delegate `shippingAddress`, that address will come from the payment app.
* If not, it will come from the browser autofill.
Syntax
------


```js
enableDelegations(delegations)
```

### Parameters

`delegations` Optional

An array containing one or more enumerated values that specify the payment information you want to delegate to the payment app. Possible values can be:

`payerEmail`

The payment app will provide the payer's email whenever it is needed.

`payerName`

The payment app will provide the payer's name whenever it is needed.

`payerPhone`

The payment app will provide the payer's phone number whenever it is needed.

`shippingAddress`

The payment app will provide the shipping address whenever it is needed.


### Return value

A `Promise` that resolves with a value of `undefined`.

Examples
--------


```js
navigator.serviceWorker.register("serviceworker.js").then((registration) => {
  registration.paymentManager.userHint = "Card number should be 16 digits";

  registration.paymentManager
    .enableDelegations(["shippingAddress", "payerName"])
    .then(() => {
      // ...
    });

  // ...
});
```

Specifications
--------------

| Specification |
| --- |
| Payment Handler API # dom-paymentmanager-enabledelegations |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Payment Handler API
* Web-based payment apps overview
* Setting up a payment method
* Life of a payment transaction
* Using the Payment Request API
* Payment processing concepts
PaymentManager: userHint property
=================================

**Experimental:** **This is an experimental technology**  
Check the Browser compatibility table carefully before using this in production.

The **`userHint`** property of the `PaymentManager` interface provides a hint for the browser to display along with the payment app's name and icon in the Payment Handler UI.

Value
-----

A string.

Examples
--------


```js
navigator.serviceWorker.register("serviceworker.js").then((registration) => {
  registration.paymentManager.userHint = "Card number should be 16 digits";

  registration.paymentManager
    .enableDelegations(["shippingAddress", "payerName"])
    .then(() => {
      // ...
    });

  // ...
});
```

Specifications
--------------

| Specification |
| --- |
| Payment Handler API # dom-paymentmanager-userhint |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Payment Handler API
* Web-based payment apps overview
* Setting up a payment method
* Life of a payment transaction
* Using the Payment Request API
* Payment processing concepts
PaymentRequestUpdateEvent: PaymentRequestUpdateEvent() constructor
==================================================================

**Secure context:** This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

 The **`PaymentRequestUpdateEvent()`** constructor creates a new
 `PaymentRequestUpdateEvent` object which enables a web page to update the
 details of a `PaymentRequest` in response to a user action. Actual updates
 are made by passing options to the
 `updateWith()` method.

Syntax
------


```js
new PaymentRequestUpdateEvent()
```

### Parameters

None.

### Return value

A new `PaymentRequestUpdateEvent`.

Specifications
--------------

| Specification |
| --- |
| Payment Request API 1.1 # constructor-0 |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
MediaSource: handle property
============================

**Experimental:** **This is an experimental technology**  
Check the Browser compatibility table carefully before using this in production.

The **`handle`** read-only property of the `MediaSource` interface returns a `MediaSourceHandle` object, a proxy for the `MediaSource` that can be transferred from a dedicated worker back to the main thread and attached to a media element via its `HTMLMediaElement.srcObject` property.

**Note:** `handle` is only visible on `MediaSource` instances inside dedicated workers.

Each `MediaSource` object created inside a dedicated worker has its own distinct `MediaSourceHandle`. The `handle` getter will always return the `MediaSourceHandle` instance specific to the associated dedicated worker `MediaSource` instance. If the handle has already been transferred to the main thread using `postMessage()`, the handle instance in the worker is technically detached and can't be transferred again.

**Note:** This feature is available in Web Workers

Value
-----

A `MediaSourceHandle` object instance.

Examples
--------

The `handle` property can be accessed inside a dedicated worker and the resulting `MediaSourceHandle` object is then transferred over to the thread that created the worker (in this case the main thread) via a `postMessage()` call:


```js
// Inside dedicated worker
let mediaSource = new MediaSource();
let handle = mediaSource.handle;
// Transfer the handle to the context that created the worker
postMessage({ arg: handle }, [handle]);

mediaSource.addEventListener("sourceopen", () => {
  // Await sourceopen on MediaSource before creating SourceBuffers
  // and populating them with fetched media — MediaSource won't
  // accept creation of SourceBuffers until it is attached to the
  // HTMLMediaElement and its readyState is "open"
});
```


Over in the main thread, we receive the handle via a `message` event handler, attach it to a `<video>` via its `HTMLMediaElement.srcObject` property, and `play` the video:


```js
worker.addEventListener("message", (msg) => {
  let mediaSourceHandle = msg.data.arg;
  video.srcObject = mediaSourceHandle;
  video.play();
});
```


**Note:** `MediaSourceHandle`s cannot be successfully transferred into or via a shared worker or service worker.

Specifications
--------------

| Specification |
| --- |
| Media Source Extensions™ # dom-mediasource-handle |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* MSE-in-Workers Demo by Matt Wolenetz
* Media Source Extensions API
* `MediaSource`
* `SourceBuffer`
MediaSource: MediaSource() constructor
======================================

 The **`MediaSource()`** constructor of the
 `MediaSource` interface constructs and returns a new
 `MediaSource` object with no associated source buffers.

Syntax
------


```js
new MediaSource()
```

### Parameters

None.

Examples
--------

The following snippet is taken from a simple example written by Nick Desaulniers (view the full demo live, or download the source for further investigation).


```js
const video = document.querySelector("video");

const assetURL = "frag\_bunny.mp4";
// Need to be specific for Blink regarding codecs
// ./mp4info frag\_bunny.mp4 | grep Codec
const mimeCodec = 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"';

if ("MediaSource" in window && MediaSource.isTypeSupported(mimeCodec)) {
  const mediaSource = new MediaSource();
  //console.log(mediaSource.readyState); // closed
  video.src = URL.createObjectURL(mediaSource);
  mediaSource.addEventListener("sourceopen", sourceOpen);
} else {
  console.error("Unsupported MIME type or codec: ", mimeCodec);
}

// …
```

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `SourceBuffer`
* `SourceBufferList`
MediaSource: removeSourceBuffer() method
========================================

The **`removeSourceBuffer()`** method of the `MediaSource` interface removes the given `SourceBuffer` from the `SourceBufferList` associated with this `MediaSource` object.

Syntax
------


```js
removeSourceBuffer(sourceBuffer)
```

### Parameters

`sourceBuffer`

The `SourceBuffer` object to be removed.

### Return value

None (`undefined`).

### Exceptions

`NotFoundError` `DOMException`

Thrown if the supplied sourceBuffer doesn't exist in `MediaSource.sourceBuffers`.

Examples
--------


```js
for (let i = 0; i < 10; i++) {
  const sourceBuffer = mediaSource.addSourceBuffer(mimeCodec);
}

mediaSource.removeSourceBuffer(mediaSource.sourceBuffers[0]);
```

Specifications
--------------

| Specification |
| --- |
| Media Source Extensions™ # dom-mediasource-removesourcebuffer |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `SourceBuffer`
* `SourceBufferList`
MediaSource: setLiveSeekableRange() method
==========================================

 The **`setLiveSeekableRange()`** method of the
 `MediaSource` interface sets the range that the user can seek to in the
 media element.

Syntax
------


```js
setLiveSeekableRange(start, end)
```

### Parameters

`start`

 The start of the seekable range to set in seconds measured from the beginning of the
 source. If the duration of the media source is positive infinity, then the
 `TimeRanges` object returned by the
 `HTMLMediaElement.seekable` property will have a start timestamp no
 greater than this value.


`end`

 The end of the seekable range to set in seconds measured from the beginning of the
 source. If the duration of the media source is positive infinity, then the
 `TimeRanges` object returned by the
 `HTMLMediaElement.seekable` property will have an end timestamp no
 less than this value.


### Return value

None (`undefined`).

Examples
--------


```js
// TBD
```

Specifications
--------------

| Specification |
| --- |
| Media Source Extensions™ # dom-mediasource-setliveseekablerange |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
MediaSource: clearLiveSeekableRange() method
============================================

 The **`clearLiveSeekableRange()`** method of the
 `MediaSource` interface clears a seekable range previously set with a call
 to `setLiveSeekableRange()`.

Syntax
------


```js
clearLiveSeekableRange()
```

### Parameters

None.

### Return value

None (`undefined`).

Specifications
--------------

| Specification |
| --- |
| Media Source Extensions™ # dom-mediasource-clearliveseekablerange |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
MediaSource: isTypeSupported() static method
============================================

The **`MediaSource.isTypeSupported()`** static method returns a boolean value which is `true` if the given MIME type and (optional) codec are *likely* to be supported by the current user agent.

 That is, if it can successfully create `SourceBuffer` objects for that media type.
 If the returned value is `false`, then the user agent is certain that it *cannot* access media of the specified format.

Syntax
------


```js
MediaSource.isTypeSupported(type)
```

### Parameters

`type`

A string specifying the MIME type of the media and (optionally) a `codecs` parameter containing a comma-separated list of the supported codecs.

### Return value

A value of `false` if the media of the given type will *not* play.

 A value of `true` is returned if the browser can *probably* play media of the specified type.
 This is *not* a guarantee, and your code must be prepared for the possibility that the media will not play correctly if at all.

 All web APIs that work with media files use a "no/maybe/probably" approach (or, in this case, "no or probably") when determining if a media type can be used.
 This is because media files are complex, intricate constructs with far too many subtle variations to be absolutely certain of anything until you actually use the contents of the media.

Examples
--------

The following snippet is from an example written by Nick Desaulniers (view the full demo live, or download the source for further investigation). The function `getMediaSource()`, which is not defined here, returns a `MediaSource`.


```js
const assetURL = "frag\_bunny.mp4";
// Need to be specific for Blink regarding codecs
// ./mp4info frag\_bunny.mp4 | grep Codec
const mimeCodec = 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"';
let mediaSource;

if ("MediaSource" in window && MediaSource.isTypeSupported(mimeCodec)) {
  mediaSource = getMediaSource();
  console.log(mediaSource.readyState); // closed
  video.src = URL.createObjectURL(mediaSource);
  mediaSource.addEventListener("sourceopen", sourceOpen);
} else {
  console.error("Unsupported MIME type or codec: ", mimeCodec);
}

function sourceOpen() {
  console.log(this.readyState); // open
  const sourceBuffer = mediaSource.addSourceBuffer(mimeCodec);
  fetchAB(assetURL, (buf) => {
    sourceBuffer.addEventListener("updateend", () => {
      mediaSource.endOfStream();
      video.play();
      console.log(mediaSource.readyState); // ended
    });
    sourceBuffer.appendBuffer(buf);
  });
}
```

Specifications
--------------

| Specification |
| --- |
| Media Source Extensions™ # dom-mediasource-istypesupported |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Media Source Extensions API
* Guide to media types and formats on the web
* Codecs in common media types
* `SourceBuffer`
* `SourceBufferList`
MediaSource: activeSourceBuffers property
=========================================

 The **`activeSourceBuffers`** read-only property of the
 `MediaSource` interface returns a `SourceBufferList` object
 containing a subset of the `SourceBuffer` objects contained within
 `sourceBuffers` — the list of objects
 providing the selected video track, enabled audio tracks, and shown/hidden text tracks.

Value
-----

 A `SourceBufferList` containing the `SourceBuffer` objects
 for each of the active tracks.

Examples
--------

The following snippet is based on a simple example written by Nick Desaulniers (view the full demo live, or download the source for further investigation). The function `getMediaSource()`, which is not defined here, returns a `MediaSource`.


```js
const mediaSource = getMediaSource();

function sourceOpen() {
  console.log(mediaSource.readyState); // open
  const sourceBuffer = mediaSource.addSourceBuffer(mimeCodec);
  fetchAB(assetURL, (buf) => {
    sourceBuffer.addEventListener("updateend", () => {
      mediaSource.endOfStream();
      console.log(mediaSource.activeSourceBuffers);
      // will contain the source buffer that was added above,
      // as it is selected for playing in the video player
      video.play();
      console.log(mediaSource.readyState); // ended
    });
    sourceBuffer.appendBuffer(buf);
  });
}

// …
```

Specifications
--------------

| Specification |
| --- |
| Media Source Extensions™ # dom-mediasource-activesourcebuffers |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `SourceBuffer`
* `SourceBufferList`
MediaSource: addSourceBuffer() method
=====================================

 The **`addSourceBuffer()`** method of the
 `MediaSource` interface creates a new `SourceBuffer` of the
 given MIME type and adds it to the `MediaSource`'s
 `sourceBuffers` list. The new
 `SourceBuffer` is also returned.

Syntax
------


```js
addSourceBuffer(mimeType)
```

### Parameters

`mimeType`

 A string specifying the MIME type of the
 `SourceBuffer` to create and add to the `MediaSource`.


### Return value

 A `SourceBuffer` object representing the new source buffer that has been
 created and added to the media source.

### Exceptions

`InvalidAccessError` `DOMException`

 Thrown if the value specified for `mimeType` is an empty string rather than a valid
 MIME type.


`InvalidStateError` `DOMException`

 Thrown if the `MediaSource` is not in the `"open"`
`readyState`.


`NotSupportedError` `DOMException`

 Thrown if the specified `mimeType` isn't supported by the user
 agent, or is not compatible with the MIME types of other
 `SourceBuffer` objects that are already included in the media source's
 `sourceBuffers` list.


`QuotaExceededError` `DOMException`

 Thrown if the user agent can't handle any more `SourceBuffer` objects, or creating
 a new `SourceBuffer` using the given `mimeType` would result in
 an unsupported configuration of `SourceBuffer`s.


Examples
--------

The following snippet is from a simple example written by Nick Desaulniers (view the full demo live, or download the source for further investigation). The function `getMediaSource()`, which is not defined here, returns a `MediaSource`.


```js
const assetURL = "frag\_bunny.mp4";
// Need to be specific for Blink regarding codecs
// ./mp4info frag\_bunny.mp4 | grep Codec
const mimeCodec = 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"';
const mediaSource = getMediaSource();

if ("MediaSource" in window && MediaSource.isTypeSupported(mimeCodec)) {
  console.log(mediaSource.readyState); // closed
  mediaSource.addEventListener("sourceopen", sourceOpen);
  video.src = URL.createObjectURL(mediaSource);
} else {
  console.error("Unsupported MIME type or codec: ", mimeCodec);
}

function sourceOpen() {
  console.log(this.readyState); // open
  const sourceBuffer = mediaSource.addSourceBuffer(mimeCodec);
  fetchAB(assetURL, (buf) => {
    sourceBuffer.addEventListener("updateend", () => {
      mediaSource.endOfStream();
      video.play();
      console.log(mediaSource.readyState); // ended
    });
    sourceBuffer.appendBuffer(buf);
  });
}
```

Specifications
--------------

| Specification |
| --- |
| Media Source Extensions™ # dom-mediasource-addsourcebuffer |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `SourceBuffer`
* `SourceBufferList`
MediaSource: endOfStream() method
=================================

 The **`endOfStream()`** method of the
 `MediaSource` interface signals the end of the stream.

Syntax
------


```js
endOfStream()
endOfStream(endOfStreamError)
```

### Parameters

`endOfStreamError` Optional

 A string representing an error to throw when the end of the stream
 is reached. The possible values are:


`network`

 Terminates playback and signals that a network error has
 occurred. This can be used create a custom error handler related to media streams.
 For example, you might have a function that handles media chunk requests, separate
 from other network requests. When you make a `fetch()` request for a media
 chunk and receive a network error, you might want
 to call `endOfStream('network')`, display a descriptive message in the
 UI, and maybe retry the network request immediately or wait until the network is
 back up (via some kind of polling.)


`decode`

 Terminates playback and signals that a decoding error has
 occurred. This can be used to indicate that a parsing error has occurred while
 fetching media data; maybe the data is corrupt, or is encoded using a codec that
 the browser doesn't know how to decode.



### Return value

None (`undefined`).

### Exceptions

`InvalidStateError` `DOMException`

 Thrown if `MediaSource.readyState` is not equal to `open`, or one or more of the `SourceBuffer` objects in `MediaSource.sourceBuffers` are being updated (i.e. their `SourceBuffer.updating` property is
 `true`.)


Examples
--------

The following snippet is from a simple example written by Nick Desaulniers (view the full demo live, or download the source for further investigation). The function `getMediaSource()`, which is not defined here, returns a `MediaSource`.


```js
const assetURL = "frag\_bunny.mp4";
// Need to be specific for Blink regarding codecs
// ./mp4info frag\_bunny.mp4 | grep Codec
const mimeCodec = 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"';

let mediaSource;

if ("MediaSource" in window && MediaSource.isTypeSupported(mimeCodec)) {
  mediaSource = getMediaSource();
  console.log(mediaSource.readyState); // closed
  video.src = URL.createObjectURL(mediaSource);
  mediaSource.addEventListener("sourceopen", sourceOpen);
} else {
  console.error("Unsupported MIME type or codec: ", mimeCodec);
}

function sourceOpen() {
  console.log(this.readyState); // open
  const sourceBuffer = mediaSource.addSourceBuffer(mimeCodec);
  fetchAB(assetURL, (buf) => {
    sourceBuffer.addEventListener("updateend", () => {
      mediaSource.endOfStream();
      video.play();
      console.log(mediaSource.readyState); // ended
    });
    sourceBuffer.appendBuffer(buf);
  });
}
```

Specifications
--------------

| Specification |
| --- |
| Media Source Extensions™ # dom-mediasource-endofstream |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `SourceBuffer`
* `SourceBufferList`
MediaSource: duration property
==============================

 The **`duration`** property of the `MediaSource`
 interface gets and sets the duration of the current media being presented.

Value
-----

A double. A value in seconds is expected.

### Exceptions

The following exceptions may be thrown when setting a new value for this property.

`InvalidAccessError` `DOMException`

Thrown if an attempt was made to set a duration value that was negative or `NaN`.

`InvalidStateError` `DOMException`

 Thrown if `MediaSource.readyState` is not equal to
 `open`, or one or more of the
 `SourceBuffer` objects in
 `MediaSource.sourceBuffers` are being updated
 (i.e. their `SourceBuffer.updating` property is
 `true`.)


Examples
--------

The following snippet is based on a simple example written by Nick Desaulniers (view the full demo live, or download the source for further investigation). The function `getMediaSource()`, which is not defined here, returns a `MediaSource`.


```js
const mediaSource = getMediaSource();

function sourceOpen() {
  console.log(this.readyState); // open
  const sourceBuffer = mediaSource.addSourceBuffer(mimeCodec);
  fetchAB(assetURL, (buf) => {
    sourceBuffer.addEventListener("updateend", () => {
      mediaSource.endOfStream();
      mediaSource.duration = 120;
      video.play();
      console.log(mediaSource.readyState); // ended
    });
    sourceBuffer.appendBuffer(buf);
  });
}

// …
```

Specifications
--------------

| Specification |
| --- |
| Media Source Extensions™ # dom-mediasource-duration |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `SourceBuffer`
* `SourceBufferList`