Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow no-cors on fetch request #5959

Closed
Robloche opened this issue Nov 30, 2023 · 15 comments · Fixed by #5964 or #5986
Closed

Allow no-cors on fetch request #5959

Robloche opened this issue Nov 30, 2023 · 15 comments · Fixed by #5964 or #5986
Labels
component: HLS The issue involves Apple's HLS manifest format priority: P2 Smaller impact or easy workaround status: archived Archived and locked; will not be updated type: bug Something isn't working correctly
Milestone

Comments

@Robloche
Copy link
Contributor

Robloche commented Nov 30, 2023

I was looking for a solution to my problem and found the following issue:
#1286

I think I have indeed found a use case for such a request.
I have an HLS manifest in which segments don't have any extension.
Then, as shown in code below, the parser does a HEAD request to retrieve the mime type:

// If unable to guess mime type, request a segment and try getting it
// from the response.
const headRequest = shaka.net.NetworkingEngine.makeRequest(
middleSegmentUris, this.config_.retryParameters);
headRequest.method = 'HEAD';
const type = shaka.net.NetworkingEngine.AdvancedRequestType.MEDIA_SEGMENT;
const response = await this.makeNetworkRequest_(
headRequest, requestType, {type});

And in my case, a CORS error happens.
Since I don't have any control on the manifest and I don't care about the anwser (only the response headers matter), a no-cors fetch request would certainly solves my issue.

What do you think?

@Robloche Robloche added the type: enhancement New feature or request label Nov 30, 2023
@avelad
Copy link
Collaborator

avelad commented Nov 30, 2023

So what you propose is to use no-cors for HEAD requests? If you can share the manifest with me so I can investigate the issue and provide an appropriate solution. Thanks!

@avelad avelad added the priority: P3 Useful but not urgent label Nov 30, 2023
@avelad avelad added this to the Backlog milestone Nov 30, 2023
@avelad
Copy link
Collaborator

avelad commented Nov 30, 2023

I have been looking and it is not possible, in no-cors mode we do not have access to the headers, so we can not detect the mimetype correctly.

@avelad avelad added status: infeasible The requested feature is not currently feasible and removed type: enhancement New feature or request priority: P3 Useful but not urgent labels Nov 30, 2023
@avelad avelad removed this from the Backlog milestone Nov 30, 2023
@avelad avelad added the status: waiting on response Waiting on a response from the reporter(s) of the issue label Nov 30, 2023
@Robloche
Copy link
Contributor Author

Robloche commented Nov 30, 2023

Oh, you're totally right.
I knew I wouldn't be able to access the response's body, but I thought the headers would be OK.

Here's the manifest anyway:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:38405
#EXT-X-TARGETDURATION:6
#EXTINF:6.000,
/beacon/amg01074-fueltv-netgem/147216c6-8f61-11ee-8f06-e2013c1e3b32/1920x1080_6503200?bcn=1&ca=0&cid=FUNGS-2301&dur=6.000000&media_type=C&redirect_url=https%3A%2F%2Famg01074-fueltv-netgem.amagi.tv%2Fmain_1080_2608675.ts&seg_id=2608675&user_id=147216c6-8f61-11ee-8f06-e2013c1e3b32
#EXTINF:6.000,
/beacon/amg01074-fueltv-netgem/147216c6-8f61-11ee-8f06-e2013c1e3b32/1920x1080_6503200?bcn=1&ca=0&cid=FUNGS-2301&dur=6.000000&media_type=C&redirect_url=https%3A%2F%2Famg01074-fueltv-netgem.amagi.tv%2Fmain_1080_2608676.ts&seg_id=2608676&user_id=147216c6-8f61-11ee-8f06-e2013c1e3b32
#EXTINF:6.000,
/beacon/amg01074-fueltv-netgem/147216c6-8f61-11ee-8f06-e2013c1e3b32/1920x1080_6503200?bcn=1&ca=0&cid=FUNGS-2301&dur=6.000000&media_type=C&redirect_url=https%3A%2F%2Famg01074-fueltv-netgem.amagi.tv%2Fmain_1080_2608677.ts&seg_id=2608677&user_id=147216c6-8f61-11ee-8f06-e2013c1e3b32
#EXTINF:6.000,
/beacon/amg01074-fueltv-netgem/147216c6-8f61-11ee-8f06-e2013c1e3b32/1920x1080_6503200?bcn=1&ca=0&cid=FUNGS-2301&dur=6.000000&media_type=C&redirect_url=https%3A%2F%2Famg01074-fueltv-netgem.amagi.tv%2Fmain_1080_2608678.ts&seg_id=2608678&user_id=147216c6-8f61-11ee-8f06-e2013c1e3b32
#EXTINF:6.000,
/beacon/amg01074-fueltv-netgem/147216c6-8f61-11ee-8f06-e2013c1e3b32/1920x1080_6503200?bcn=1&ca=0&cid=FUNGS-2301&dur=6.000000&media_type=C&redirect_url=https%3A%2F%2Famg01074-fueltv-netgem.amagi.tv%2Fmain_1080_2608679.ts&seg_id=2608679&user_id=147216c6-8f61-11ee-8f06-e2013c1e3b32
#EXTINF:6.000,
/beacon/amg01074-fueltv-netgem/147216c6-8f61-11ee-8f06-e2013c1e3b32/1920x1080_6503200?bcn=1&ca=0&cid=FUNGS-2301&dur=6.000000&media_type=C&redirect_url=https%3A%2F%2Famg01074-fueltv-netgem.amagi.tv%2Fmain_1080_2608680.ts&seg_id=2608680&user_id=147216c6-8f61-11ee-8f06-e2013c1e3b32
#EXTINF:6.000,
/beacon/amg01074-fueltv-netgem/147216c6-8f61-11ee-8f06-e2013c1e3b32/1920x1080_6503200?bcn=1&ca=0&cid=FUNGS-2301&dur=6.000000&media_type=C&redirect_url=https%3A%2F%2Famg01074-fueltv-netgem.amagi.tv%2Fmain_1080_2608681.ts&seg_id=2608681&user_id=147216c6-8f61-11ee-8f06-e2013c1e3b32
#EXTINF:6.000,
/beacon/amg01074-fueltv-netgem/147216c6-8f61-11ee-8f06-e2013c1e3b32/1920x1080_6503200?bcn=1&ca=0&cid=FUNGS-2301&dur=6.000000&media_type=C&redirect_url=https%3A%2F%2Famg01074-fueltv-netgem.amagi.tv%2Fmain_1080_2608682.ts&seg_id=2608682&user_id=147216c6-8f61-11ee-8f06-e2013c1e3b32
#EXTINF:6.000,
/beacon/amg01074-fueltv-netgem/147216c6-8f61-11ee-8f06-e2013c1e3b32/1920x1080_6503200?bcn=1&ca=0&cid=FUNGS-2301&dur=6.000000&media_type=C&redirect_url=https%3A%2F%2Famg01074-fueltv-netgem.amagi.tv%2Fmain_1080_2608683.ts&seg_id=2608683&user_id=147216c6-8f61-11ee-8f06-e2013c1e3b32
#EXTINF:6.000,
/beacon/amg01074-fueltv-netgem/147216c6-8f61-11ee-8f06-e2013c1e3b32/1920x1080_6503200?bcn=1&ca=0&cid=FUNGS-2301&dur=6.000000&media_type=C&redirect_url=https%3A%2F%2Famg01074-fueltv-netgem.amagi.tv%2Fmain_1080_2608684.ts&seg_id=2608684&user_id=147216c6-8f61-11ee-8f06-e2013c1e3b32

Thanks for the quick answer.

@shaka-bot shaka-bot removed the status: waiting on response Waiting on a response from the reporter(s) of the issue label Nov 30, 2023
@Robloche Robloche reopened this Nov 30, 2023
@avelad
Copy link
Collaborator

avelad commented Nov 30, 2023

I don't have an explanation for this, maybe @theodab can help here.

@Robloche
Copy link
Contributor Author

Thanks.
I'm using the latest version of the player (v4.6.3).

@Robloche
Copy link
Contributor Author

Robloche commented Nov 30, 2023

My bad...

On the demo page, I was providing the manifest's URL for the representation of highest quality:
https://amg01074-fueltv-netgem.amagi.tv/playlist/amg01074-fueltv-netgem/d423e0fe-8f96-11ee-9edc-fa70851de8e1/28/1920x1080_6503200/index.m3u8

But in my app (and it's my use case), I'm providing the playlist's URL:
https://cdn-ue1-prod.tsv2.amagi.tv/linear/amg01074-fueltv-netgem/playlist.m3u8?did=c9bda167-2609-f2c3-88d8-81b2cd8332c1&dnt=1&genre=sport&app_bundle=com.netgem.netgemtv&app_name=Netgem+TV&us_privacy=0&gdpr=1&gdpr_consent=0&coppa=0

Which leads to downloading this:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="Portuguese",DEFAULT=YES,AUTOSELECT=YES,LANGUAGE="por",URI="d423e0fe-8f96-11ee-9edc-fa70851de8e1/28/subs-portuguese-por/subtitle.m3u8"
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="French",DEFAULT=YES,AUTOSELECT=YES,LANGUAGE="fra",URI="d423e0fe-8f96-11ee-9edc-fa70851de8e1/28/subs-french-fra/subtitle.m3u8"
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="Finnish",DEFAULT=YES,AUTOSELECT=YES,LANGUAGE="fin",URI="d423e0fe-8f96-11ee-9edc-fa70851de8e1/28/subs-finnish-fin/subtitle.m3u8"
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="Spanish",DEFAULT=YES,AUTOSELECT=YES,LANGUAGE="spa",URI="d423e0fe-8f96-11ee-9edc-fa70851de8e1/28/subs-spanish-spa/subtitle.m3u8"
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="English Closed Captions",DEFAULT=YES,AUTOSELECT=YES,LANGUAGE="eng",URI="d423e0fe-8f96-11ee-9edc-fa70851de8e1/28/subs-english-closed-captions-eng/subtitle.m3u8"
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="German",DEFAULT=YES,AUTOSELECT=YES,LANGUAGE="deu",URI="d423e0fe-8f96-11ee-9edc-fa70851de8e1/28/subs-german-deu/subtitle.m3u8"
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="Russian",DEFAULT=YES,AUTOSELECT=YES,LANGUAGE="rus",URI="d423e0fe-8f96-11ee-9edc-fa70851de8e1/28/subs-russian-rus/subtitle.m3u8"
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="Swedish",DEFAULT=YES,AUTOSELECT=YES,LANGUAGE="swe",URI="d423e0fe-8f96-11ee-9edc-fa70851de8e1/28/subs-swedish-swe/subtitle.m3u8"
#EXT-X-STREAM-INF:PROGRAM-ID=0,BANDWIDTH=6503200,AVERAGE-BANDWIDTH=6261200,CODECS="avc1.640028,mp4a.40.2",RESOLUTION=1920x1080,SUBTITLES="subs",FRAME-RATE=25.000
d423e0fe-8f96-11ee-9edc-fa70851de8e1/28/1920x1080_6503200/index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=0,BANDWIDTH=4919200,AVERAGE-BANDWIDTH=4611200,CODECS="avc1.64001f,mp4a.40.2",RESOLUTION=1280x720,SUBTITLES="subs",FRAME-RATE=25.000
d423e0fe-8f96-11ee-9edc-fa70851de8e1/28/1280x720_4919200/index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=0,BANDWIDTH=2200000,AVERAGE-BANDWIDTH=2120800,CODECS="avc1.77.30,mp4a.40.2",RESOLUTION=640x360,SUBTITLES="subs",FRAME-RATE=25.000
d423e0fe-8f96-11ee-9edc-fa70851de8e1/28/640x360_2200000/index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=0,BANDWIDTH=1284800,AVERAGE-BANDWIDTH=1240800,CODECS="avc1.4d4014,mp4a.40.2",RESOLUTION=416x234,SUBTITLES="subs",FRAME-RATE=25.000
d423e0fe-8f96-11ee-9edc-fa70851de8e1/28/416x234_1284800/index.m3u8

In conclusion, giving a playlist causes a HEAD in the end, and a CORS error with the demo app, as well as with my app.

@avelad
Copy link
Collaborator

avelad commented Nov 30, 2023

The difference is that when you provide the master playlist, since we have all the information, we only need to make a HEAD to obtain the contentType, but when you provide a half playlist we have to obtain all the information, so we download the entire segment.

@Robloche
Copy link
Contributor Author

Robloche commented Nov 30, 2023

OK, I understand the "why", but now, I need to make it work. 😄

I also found this issue which is very similar to mine:
#3142

And from what I read, it led to a PR that was merged 2 years ago.
But the code has changed a bit since that day, and now, when the HEAD request fails, it seems like the execution simply stops instead of going through guessMimeTypeFallback_() and fallback-ing to mp4.

Shouldn't const response = await this.makeNetworkRequest_(headRequest, requestType, {type}); be inside a try/catch?

@avelad avelad added type: bug Something isn't working correctly component: HLS The issue involves Apple's HLS manifest format priority: P2 Smaller impact or easy workaround and removed status: infeasible The requested feature is not currently feasible labels Nov 30, 2023
@avelad avelad added this to the v4.7 milestone Nov 30, 2023
@avelad
Copy link
Collaborator

avelad commented Nov 30, 2023

@Robloche I created #5964 to fix it

@Robloche
Copy link
Contributor Author

Wow, that was fast!
Thanks a lot.

@Robloche
Copy link
Contributor Author

Robloche commented Dec 1, 2023

It works like a charm.
Thanks again for your swiftness.

@Robloche
Copy link
Contributor Author

Robloche commented Dec 4, 2023

Sorry to bother you again but it seems like the same behavior is needed here as well:

static async getMimeType(uri, netEngine, retryParams) {
const extension = shaka.net.NetworkingUtils.getExtension_(uri);
let mimeType =
shaka.net.NetworkingUtils.EXTENSIONS_TO_MIME_TYPES_[extension];
if (mimeType) {
return mimeType;
}
const type = shaka.net.NetworkingEngine.RequestType.MANIFEST;
const request = shaka.net.NetworkingEngine.makeRequest([uri], retryParams);
request.method = 'HEAD';
const response = await netEngine.request(type, request).promise;
// https://bit.ly/2K9s9kf says this header should always be available,
// but just to be safe:
mimeType = response.headers['content-type'];
return mimeType ? mimeType.toLowerCase().split(';').shift() : '';
}

I indeed have another case where the playlist itself doesn't have any extension, and redirects to a a .m3u8 file.
In this case, a HEAD request is made, which fails.

@avelad
Copy link
Collaborator

avelad commented Dec 4, 2023

@Robloche I created #5986 to fix it

@Robloche
Copy link
Contributor Author

Robloche commented Dec 4, 2023

Thank you so much.

@shaka-bot shaka-bot added the status: archived Archived and locked; will not be updated label Feb 3, 2024
@shaka-project shaka-project locked as resolved and limited conversation to collaborators Feb 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
component: HLS The issue involves Apple's HLS manifest format priority: P2 Smaller impact or easy workaround status: archived Archived and locked; will not be updated type: bug Something isn't working correctly
Projects
None yet
3 participants