D
D
dllweb2017-02-07 22:01:46
JavaScript
dllweb, 2017-02-07 22:01:46

Is it possible to send another User-Agent in an ajax request to the server from a Chrome extension?

Good time.
Actually, the question is whether it is possible to send an ajax request from the extension to any domain
containing the User-Agent header: "With its arbitrary content" other headers such as
Origin and Host are also of interest. I tried with the built-in tools of the jquery library through the headers property: {....}
But, as a result, in the background page of the extension debugging, I noticed that the User-Agent header did not change

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2017-02-07
@dllweb

https://developer.mozilla.org/en-US/Add-ons/WebExt...

"use strict";
// URL страницы, запросы к которой ловим
var targetPage = "https://httpbin.org/*";
// Свой кастомный User-Agent
var ua = "Свой кастомный User-Agent";
// Функция-перехватчик, в которой заголовок будет подменен на наше значение
function rewriteUserAgentHeader(e) {
  for (var header of e.requestHeaders) {
    if (header.name.toLowerCase() === "user-agent") {
      header.value = ua;
    }
  }
  return {requestHeaders: e.requestHeaders};
}
// Установка обработчика запросов
browser.webRequest.onBeforeSendHeaders.addListener(
  rewriteUserAgentHeader,
  {urls: [targetPage]},
  ["blocking", "requestHeaders"]
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question