A partial archive of discourse.wicg.io as of Saturday February 24, 2024.

[Proposal] video MediaError extension

vicyao
2019-07-17

Problem

When a video error occur, we can get the error code through MediaError. The code defines here:

interface MediaError {

const unsigned short MEDIA_ERR_ABORTED = 1;

const unsigned short MEDIA_ERR_NETWORK = 2;

const unsigned short MEDIA_ERR_DECODE = 3;

const unsigned short MEDIA_ERR_SRC_NOT_SUPPORTED = 4;

readonly attribute unsigned short code;

};

The problem is, when it comes to MEDIA_ERR_SRC_NOT_SUPPORTED, developer can’t confirm what had happened. It could be one of the following issues:

  1. The src request returned a 403, 403 or 5xx.
  2. The src request returned a 200, but it’s a html page instead of video. Most likely the request has been blocked.
  3. The src request returned a video but the encode was not supported.
  4. Other exceptions.

In these cases the “error.message” is empty or just “Format error”, no further information.

Proposed API: a httpCode on MediaError

We propose an addition attribute, httpCode, on MediaError. So developer can figure out what happened and report the issue. Here’s a example:

let video = document.createElement('video');
video.addEventListener('error', function() {
    console.log(this.error.httpCode);
}

Other consideration

By getting the httpCode, we need to follow the CORS specification. Only When the request pass the CORS successfully(or in the same domain), it’s allowed to read the httpCode, otherwise throw an exception.

Besides video element, audio can share the httpCode too.