3

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)'; }
});
user435421
  • 771
  • 2
  • 10
  • 30
  • _A Navigator object can be retrieved using the **read-only** window.navigator property._ https://developer.mozilla.org/en-US/docs/Web/API/Navigator – mplungjan Sep 19 '19 at 07:44
  • However https://stackoverflow.com/questions/2166540/how-can-i-fool-a-site-that-looks-at-the-javascript-object-navigator-to-see-tha – mplungjan Sep 19 '19 at 07:46
  • Firefox and Safari just let you use `XHR.setRequestHeader('User-Agent', 'whatever')`. Chrome on the other hand throws an error... – Kaiido Sep 19 '19 at 12:19
  • This is now allowed, see my answer – Gertjan Brouwer Dec 27 '20 at 19:54

2 Answers2

5

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)’

Gertjan Brouwer
  • 954
  • 1
  • 11
  • 31
3

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.

Brad
  • 152,561
  • 47
  • 332
  • 504