5

I'm trying to load a video from S3 that may or may not be transcoding at the time. While it's still processing, I get a 403 response. Every other browser I test (Chrome/Firefox/IE) triggers the "error" event so I can display a message to the user like so:

var video = document.createElement('video');
video.onerror = function (e) {
// Show the user a message...
};
video.src = videoURL;

But Safari (on OSX) just logs to the console without triggering the event.

Failed to load resource: the server responded with a status of 403 (Forbidden)

It will trigger if I make the video.src a garbage URL that leads to nothing but it doesn't for a 403.

Is there some other event I can listen for or another way to warn the user? I know I could probably make a separate ajax request for the video and check the response but I'd like to avoid the overhead.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Drew Greene
  • 291
  • 1
  • 3
  • 12

1 Answers1

0

This is a bug in Webkit.

We handle this by first making a HEAD request to check the status of the file, before trying to load the video. Adds a round-trip, but is usually pretty fast:

$.ajax({
  type: "HEAD",
  url: video_filename,
  success: loadVideo,
  error: handleError
});
Meekohi
  • 10,390
  • 6
  • 49
  • 58