outlandnish / ext-f1-tv

Browser Extension that enables modern playback controls + Google Cast support for F1 TV
17 stars 2 forks source link

Older Streams not working due to strict CORS #1

Open fritzfr opened 4 years ago

fritzfr commented 4 years ago

Hey,

great extension! I wanted to watch an old race (Monaco 1996) and after connecting, my TV just shows a gray screen and it reads "F1 TV (Unofficial)" in the middle, nothing else. Races from this season are working just fine.

Console shows:

Cast error loading media: session_error

According to the docs, this means "A session could not be created, or a session was invalid." So nothing wrong with the stream/playlist file itself, but the cast session? Seems odd, as switching to a recent race works.

Any ideas?

-- UPDATE:

Found this in the othe repo:

Older F1 race streams do not Cast because of a stricter CORS policy for webpage origin. Possible workaround is proxy HLS calls using Lambda functions on Netlify.

I'd like to help. Still trying to figure out though, what f1tv-cast-receiver does and how it gets to my TV.

outlandnish commented 4 years ago

Yup, it's because of the CORS issue. It looks like the older stream provider (Tata) had a much stricter policy on web requests.

This extension passes along the stream URL to the Cast Receiver. On load, the receiver then loads the HLS Playlist from the m3u8 file and downloads segments of the video to play.

For those older streams, the Fetch or XMLHTTPRequests for both the Playlist file and video chunks send a pre-flight CORS request which gets rejected because the domain of the receiver page doesn't match the f1tv.formula1.com domain

The easiest solution would be to proxy the requests to F1 TV and use HTTP redirects to get the data. I just haven't tried it yet. You're welcome to give it a shot if you'd like!

fritzfr commented 4 years ago

@outlandnish Thanks for the quick response.

So this would have to be done on the receiver then, not in this repo?

outlandnish commented 4 years ago

@fritzfr yep, that's correct. If you do give it a shot, lemme know and I'd be happy to merge the changes in. I might try it if not when I have some free time

fritzfr commented 4 years ago

Never worked with the Cast framework before, looks like an interesting challenge, but the hassle to debug the receiver seems quite high (need a paid account and a long USB cable).

outlandnish commented 4 years ago

You can debug from any Chromium browser too. If you open the remote debugging window, you should see the Chromecast / Cast device. It doesn't require payment for that option.