如何使用javaScript更改浏览器User-Agent标头?

问题描述:

以下代码更改了浏览器控制台打印的属性(通过javaScript访问时),而不是与标头一起发送的实际Use-Agent字符串。

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)'; }
});


从页面本身是不可能的。用户代理字符串(在HTTP请求标头中发送)只能通过浏览器扩展或浏览器配置进行更改。

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.