Changing User-Agent in XMLHttpRequest from a Chrome extension

前端 未结 1 1327
天命终不由人
天命终不由人 2021-01-12 01:05

I\'m trying to send a HTTP request from a Extension in which I need to change the User-Agent.

My code looks like this:

function getXMLHttpRequest(met         


        
相关标签:
1条回答
  • 2021-01-12 01:37

    You can easily change the User-Agent header with the webRequest API.
    For sample code, see Associate a custom user agent to a specific Google Chrome page/tab.

    Take the code from that answer, and change "main_frame", "sub_frame" to "xmlhttprequest" to modify network requests initiated via XMLHttpRequest.

    Obviously, to prevent deadlocks, this method does not work with synchronous requests ( i.e. when the third parameter of xhr.open is set to false).

    0 讨论(0)
提交回复
热议问题