Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change browser User-Agent Header with javaScript?

Following code changes property printed (when accessed through javaScript) by browser console and not the actual Use-Agent string sent with the header.

Object.defineProperty(navigator, 'userAgent', {
    get: function () { return 'Mozilla/5.0 (Windows NT 6.2; WOW64; 
    rv:28.0) Gecko/20100101 Firefox/28.0)'; }
});
like image 578
user435421 Avatar asked Oct 17 '25 10:10

user435421


2 Answers

This is now possible to do, see: https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name You can use ‘ XMLHttpRequest.setRequestHeader(User-Agent, value)’

like image 121
Gertjan Brouwer Avatar answered Oct 19 '25 23:10

Gertjan Brouwer


This isn't possible from the page itself. The user agent string (as sent in the HTTP request headers) can only be changed via browser extension or browser configuration.

like image 30
Brad Avatar answered Oct 19 '25 22:10

Brad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!