Erratic errors when downloading crossOrigin videos from video.twimg.com


#1

Hi, I’m using videos from Twitter posts in a webGL application. Due to cross-origin security issues, it’s necessary to set the video DOM element’s crossOrigin attribute to ‘Anonymous’. I’m finding that sometimes I can download the video data from Twitter without a problem because Twitter is correctly setting the HTTP response header ‘access-control-allow-origin: *’. However, at least as often for the same video I get a CORS exception because that header is not set.

The basic sequence is:

video.crossOrigin = ‘Anonymous’;
video.src = ‘https://video.twimg.com/ext_tw_video/704695611594051584/pu/vid/318x180/hX0ogBbeOjfyUM8J.mp4’;

I’ve tried appending a random query string at the end of the URL, to get round any caching issues. That didn’t help.

I also tried a different approach if the first attempt fails: download the video data using Ajax as a blob, and use that. But I then find that sometimes that works, but at least as often it results in an aborted HTTP request.

The problem is shown by this jsfiddle: https://jsfiddle.net/9t0ejhk8/16/. Apologies that the code in here is a bit hacked together, and mixed between jQuery and basic Javascript. Also, please note that the problem is nondeterministic. So you may find you get the video correctly quite a few times (press Try Again or wait for the every-minute attempt on a setInterval timer) before the problem manifests.

Been tearing my hair out with this for some time, so any advice appreciated.


#2

@timkindberg Thanks for contacting us and a nice write-up. We are aware of this issue and already working on a solution. The root cause is that one of our cdn partners is not respecting CORS headers. So if your request is routed to that cdn partner (which is nondeterministic) then web browser will prevent you from accessing HLS content because CORS headers are not set correctly in the response.


#3

Thanks for getting back to me! This problem is preventing a critical application of mine from working. Do you have any idea when you expect it to be fixed, even at the level of days vs weeks vs months?


#4

@timkindberg Sorry for the trouble. We are trying to get this fixed soon but it is taking longer due to external dependency. Hopefully, this wouldn’t take more than a few weeks.


#5

Thank you! I’d appreciate it if you would post here when it’s fixed. I’m sure I’m not the only one who is interested.


#6

@timkindberg Sure. No problem. I will post updates to this thread.


#7

@timkindberg We have implemented a fix for this issue. We are going to roll it out next 1-2 weeks.


#8

@timkindberg We deployed a fix yesterday. All new videos will work consistently with CORS. Old video files may still fail intermittently due to cdn caches but they will be fixed/updated eventually. Let me know if you have any question.


#9

That’s great, thanks.


#10

This topic was automatically closed after 3 days. New replies are no longer allowed.