I'm writing a Chrome extension in pure JavaScript and wish to change the user agent for HTTP requests to a given URL as the owner of that URL has requested that a user agent of a certain format be used.
The following code works until the user agent modification line is added, at which point the Chrome inspector console give the error Refused to set unsafe header "User-Agent"
.
var xhr = new XMLHttpRequest();
xhr.open("GET", serviceURL, true, username, password);
xhr.setRequestHeader('User-Agent', 'MyExtensionName/0.0.1');
xhr.onreadystatechange = function() {
// do some stuff
}
xhr.send(null);
Why is it not possible to modify the user agent in this manner?