Closed rishbitsnbytes closed 3 months ago
👋 Thanks for opening your first issue here! 👋
If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can. To help make it easier for us to investigate your issue, please follow the contributing guidelines.
Hey @gkatsev
videojs.Hls.xhr.beforeRequest
works for adding other custom headers but not working for overwriting the 'User-Agent' request header. Can you please refer to some information about it.
It's not possible to change the user-agent header. Browsers don't allow it to be modified by client side javascript, only by extensions.
Hey @mister-ben thank you very much for a quick response. And yes I checked various places, some say it can't be changed at all and then other places even like official MDN docs says it can be changed now.
Pls have a quick look at this below highlighted text "Note" and kindly reply with your thoughts on this. https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name#:~:text=Note%3A%20The,bug%20571722).
It seems specs were changes and it's possible to change it for quite a while now. 'User-Agent' doesn't seem to be in Forbidden-Header-Name anymore. https://fetch.spec.whatwg.org/#forbidden-header-name
Yeah, apparently it should be allowed now, but it seems like Chrome didn't make the change, though Firefox seems to have (not sure about Safari). So, if you care about Chrome, you can't do it this way. Maybe Chrome lets you modify the user agent via a service worker?
TIL. You can change it on Safari and Firefox, but not Chrome or Edge. (Latest versions on Sonoma).
So, yeah, I think this can be closed as a browser bug. https://issues.chromium.org/issues/40450316 linked from mdn. If beforeRequest is working for you to add headers, it should work the same for user agent for the browsers that support it, i.e. not chromium based ones.
Thank you for your quick responses guys. As you have already concluded it with browser bug. And I tested it on Chrome, Firefox and Safari. It was working only in Firefox.
Also don't know why but videojs.Hls.xhr.beforeRequest
stopped working for me with error can't access Hls.xhr
But I was able to make it work videojs.Vhs.xhr.beforeRequest
.
The usage of .Hls
has bees deprecated for a while and as of v8, only .Vhs is available.
It's possible you may need to reload the source or only set it after
videojs.Hls.xhr.beforeRequest
is set.Originally posted by @gkatsev in https://github.com/videojs/video.js/issues/5724#issuecomment-459363403