goldfire / howler.js

Javascript audio library for the modern web.
https://howlerjs.com
MIT License
23.29k stars 2.21k forks source link

Use the MediaError message attribute if available #1727

Open bausmeier opened 1 month ago

bausmeier commented 1 month ago

Issue/Feature

Prefer the message attribute on the error over the code attribute because it contains more specific diagnostic information.

Related Issues

I couldn't find any.

Solution

The message attribute on the MediaError object returned by HTMLMediaElement.error contains specific diagnostic details about the error if available, or an empty string otherwise.

If this message is available then it will be passed with the loaderror, otherwise the code will be passed as before.

See https://html.spec.whatwg.org/multipage/media.html#error-codes.

Reproduction/Testing

Trigger a media error, and observe that a string message is provided to onloaderror instead of a code.

The easiest option is to use a non-existent source:

const howl = new Howl({
  src: 'non-existent.webm',
  html5: true,
  onloaderror(id, error) {
    console.log(error)
  },
})
howl.play()

Which will print something like Failed to init decoder instead of 4.

Breaking Changes

The onloaderror was already being called with a message in most cases, so I wouldn't consider this a breaking change.

bausmeier commented 1 month ago

Context for this is that we're receiving error reports that just say 3 from which we can determine that it's related to decoding the audio, but doesn't give us much to go on. We're hoping that the actual error message will give us more to work with for debugging.