Modification of header collection causes video stream issues

Having problems with building or using the CefSharp .NET binding? Ask your CEF-related questions here. Please ask general usage questions on StackOverflow.

Moderator: amaitland

Modification of header collection causes video stream issues

Postby jonasax » Wed Nov 11, 2020 8:19 am

Introduction
This issue was first reported to the CefSharp GitHub Issue Tracker, it was later discovered that the problem seems to originate further upstream and on suggestion this report was redirected onward to the CEF forums.
(Link to original tracker post: https://github.com/cefsharp/CefSharp/issues/3277)

Setup Information
CefSharp v.85.3.130 (wrapping CEF v85.3.130) running on x64 Windows 10.

Issue Description
Our client/server-based application uses an internal CefSharp WPF browser to display web pages in an embedded fashion. For our purposes we need to attach custom headers with every web request. We have been able to do this successfully in the past (CefSharp 79.x.xxx) using the IResourceRequestHandler.OnBeforeResourceLoad method.

We recursively update the CefSharp-packages after every major release, but during this cycle we encountered unusual issues; Test runs with a freshly updated CefSharp (v85.3.130 + custom CEF build for proprietary encoding flags) showed that certain video streams no longer loaded or played in the browser at all ('buffering' forever). Specifically videos in the YouTube encoding standard (H264 video and AAC audio) which we should have proper support for even without the proprietary encoding flags.

We traced the issue back to the IResourceRequestHandler.OnBeforeResourceLoad method, if we modify the header collection here (using either the newer IRequest.SetHeaderByName or the traditional overwriting of the IRequest.Headers collection with a modified one) the video streams malfunction as described above. If we remove the addition of custom headers, all video streams work as expected again, but sadly our application needs these custom headers to function correctly, and they have to be added before the request leaves the CefSharp browser (i.e. before they reach our internal proxy).
(We tested to see if the name of the headers added matter, but they do not, as long as we add anything to the header collection at this stage the video streams malfunction.)

To further narrow down the cause we removed all influence of our own application by cloning the minimal example provided by CefSHarp (https://github.com/cefsharp/CefSharp.MinimalExample) and manually adding a minimal ResourceRequestHandler which would only add a single custom header to requests via the IResourceRequestHandler.OnBeforeResourceLoad method:
Code: Select all
private const string HeaderName = "CustomHeader";

public CefReturnValue OnBeforeResourceLoad(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback)
{
   request.SetHeaderByName(HeaderName, Guid.NewGuid().ToString(), true);

   return CefReturnValue.Continue;
}

Navigating to YouTube with the minimally modified example shows the same issue, videos malfunction and never play after adding custom headers to outbound requests via the ResourceRequestHandler. This test result seems to support that the cause is located further upstream, possibly in CEF.
(The entirety of the modified minimal example source code is available on request)

Expected Outcome
Functioning video streams for the encoding options we support and the ability to add custom headers. Instead some of those streams never start, seemingly 'buffering' forever (seems to only happen to H264/AAC streams), as long as custom headers are added in the IResourceRequestHandler.OnBeforeResourceLoad stage.

Additional Information
The CEF log has been checked, but sadly shows nothing relevant to the issue.
jonasax
Newbie
 
Posts: 4
Joined: Tue Nov 10, 2020 4:17 am

Re: Modification of header collection causes video stream is

Postby magreenblatt » Wed Nov 11, 2020 10:55 am

Thanks for this detailed report. You say that the problem only occurs with H264/AAC video streams. What other video formats have you tested?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Modification of header collection causes video stream is

Postby jonasax » Thu Nov 12, 2020 4:31 am

While having a somewhat limited experience with video/audio codecs, we used a codec test web page to test other formats in browser.
We tested both the minimal CefSharp example and our own application (with proprietary codecs flag set), both applying a custom header.

- Both applications played VP8/VP9/Theora video with Vorbis audio without issue.
- Both failed to load or play H263 video with AMR audio.
- The minimal example failed to load or play all H.264/AVC videos with AAC audio available on the page (.mp4, .m4v, .m2ts).
- Our application played all H.264/AVC videos with AAC audio except the one carried in .m2ts (H.264/AVC High@L4).
- Both failed to load or play H265/HEVC video with any audio codec, but this is expected due to H.256 codec not being supported by either application.
- Both failed to load or play MPEG-4 Visual video with any audio codec, but we assume this is also a case of non-support.
- Both still fail to load or play any video we have tried on YouTube while the custom headers are set.

Thank you for a quick response! We hope this provides a detailed answer to your question.
jonasax
Newbie
 
Posts: 4
Joined: Tue Nov 10, 2020 4:17 am

Re: Modification of header collection causes video stream is

Postby jonasax » Tue Nov 24, 2020 4:31 am

Update:
Another user on the CefSharp GitHub mentioned that they had found something that looked relevant inside the CEF logs that we initially missed:
Code: Select all
"Access to XMLHttpRequest at 'https://r3---sn-5goeen7y.googlevideo.com/videoplayback?expire=1604936612&ei=RA-pX5fZB4KP7ASu05yQCw&ip=195.60.68.148&id=o-AJaY4Ts2u3uF6M7x5A3VxNQFYce2YpzcGPCddUGXWc69&itag=396&aitags=133%2C134%2C135%2C136%2C137%2C160%2C242%2C243%2C244%2C247%2C248%2C278%2C394%2C395%2C396%2C397%2C398%2C399&source=youtube&requiressl=yes&mh=Qw&mm=31%2C29&mn=sn-5aauxax-0hxe%2Csn-5goeen7y&ms=au%2Crdu&mv=m&mvi=3&pl=23&initcwndbps=5978750&vprv=1&mime=video%2Fmp4&gir=yes&clen=978055&dur=39.998&lmt=1600687242529046&mt=1604914832&fvip=3&keepalive=yes&c=WEB&txp=5531432&sparams=expire%2Cei%2Cip%2Cid%2Caitags%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRQIgAt2PiAuYblwGjJrdCSrmLtyc29-RxWjbS-MzEABM1JICIQCXUWmO9nUkqjNwEEB23fhcmtKlLGlA12FsNVfQLGsYHw%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRAIgeptW5HzPHo1OdTon-dbIQofYwIAQ2YG5_QOanfj1Ig0CICgzKKB1XTcxcQJVb5loVC9zv_Sn501c_zWgz_hvRrVW&alr=yes&cpn=sEWHHOwZJuZfQGfn&cver=2.20201105.01.01&fallback_count=1&range=0-839&rn=5&rbuf=0' from origin 'https://www.youtube.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.", source: https://www.youtube.com/watch?v=B3EBs7sCOzo (0)

The user suspects the addition of custom headers cause the request to no longer be classified as "simple" and cause pre-flight requests that Youtube denies.
This might relate to issues with video playback that we encounter on sites other than Youtube as well, but we are uncertain.

The main expertise areas of my team lies outside network/web development, so we sadly have little insight to add here.
More info is always good however, so we will reference the other users own bug report concerning pre-flight request issues here for the benefit of others:
https://github.com/SafeExamBrowser/seb-win-refactoring/issues/46
jonasax
Newbie
 
Posts: 4
Joined: Tue Nov 10, 2020 4:17 am

Re: Modification of header collection causes video stream is

Postby magreenblatt » Tue Nov 24, 2020 1:44 pm

The user suspects the addition of custom headers cause the request to no longer be classified as "simple" and cause pre-flight requests that Youtube denies.

Yes, that sounds feasible. You should avoid adding unexpected headers to requests.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Modification of header collection causes video stream is

Postby jonasax » Wed Nov 25, 2020 4:25 am

You should avoid adding unexpected headers to requests.

Sadly our application cannot be completely without custom headers, a large upcoming feature depends on the use of custom headers in internal requests.

For our purposes we need to attach custom headers with every [internal] web request. We have been able to do this successfully in the past (CefSharp 79.x.xxx)

We can try being even more selective about when we apply the custom headers, which should hopefully make request with custom headers only go towards internal resources which we have more control over.
However if we continue to see issues with video streams internally, we fear we might have to revert to CefSharp 79.x.xxx were this issue does not exist (which would no doubt be problematic in the future).
jonasax
Newbie
 
Posts: 4
Joined: Tue Nov 10, 2020 4:17 am


Return to CefSharp Forum

Who is online

Users browsing this forum: No registered users and 15 guests