How can I hack javascript javascript API to always use HTTP?

I plan to measure network traffic when playing video. This, of course, will only work when the video is transmitted via HTTP instead of HTTPS.

However, the YouTube iframe API always switches to HTTPS download, even though I download the API from http:// and specify the YouTube URL using http:// . You can use the example here to test the player. As you can see, it always switches to https://videoplayback... that I want to disable.

How to make it use HTTP instead of HTTPS? This is a kind of reverse question about this . I guess this will lead to some hacking functions in the current JS.

In the widget's API, I see calls such as:

 b = 0 == c.indexOf("https:") ? [c] : bd ? [c.replace("http:", "https:")] : bk ? [c] : [c, c.replace("http:", "https:")]; 

and

 if (this.d = !!("https:" == document.location.protocol || a && 0 == a.src.indexOf("https:"))) { a = [this.j, window.YTConfig || {}, this.defaults]; for (var b = 0; b < a.length; b++) a[b].host && (a[b].host = a[b].host.replace("http://", "https://")) } 

but I donโ€™t know where to override this in the context of YT and YT.Player , or if I can even do it.

Who cares if this is possible on the server side: Please note that YouTube only works with HTTP. If you are not logged into YouTube and switched to http://youtube.com , your videos will be displayed in HTTP format, not HTTPS.

+5
source share
1 answer

YouTube now redirects https through 301 redirects. This was not the case a while ago. Redirecting was only a user setting stored in a cookie.

You can try changing your User Agent and / or test to m.youtube.com, but traffic measurements may be inaccurate, as these are different domain and protocol, and youtube may have separate priorities.

Change User Agent is simple in Chrome Dev Tools (phone icon in the upper left corner).

+4
source

Source: https://habr.com/ru/post/1210963/


All Articles