I am trying to send an HTTP request from an extension in which I need to change the User-Agent.
My code is as follows:
function getXMLHttpRequest(method, url, extraHeaders) { var xhr = new XMLHttpRequest(); xhr.open(method, url, true) for (var headerKey in extraHeaders) { xhr.setRequestHeader(headerKey, extraHeaders[headerKey]); } return xhr; }
Then I get the error "Installation of unsafe header refused: UserAgent"
I need to change this because my Backend must have a special User-Agent, is it possible to do this from the extension?
I tried the webRequest API to change the header before sending the request, but it says that it does not work with XMLHttpRequest made from extensions to prevent blocking.
source share