Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8266267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:05:47+00:00 2026-06-08T05:05:47+00:00

I am trying to add a Referer-HTTP-Header to certain AJAX requests in my Chrome

  • 0

I am trying to add a “Referer”-HTTP-Header to certain AJAX requests in my Chrome extension.
You can’t change it directly in the AJAX request so I tried to change it using the webRequest api:

chrome.webRequest.onBeforeSendHeaders.addListener(function(data) {
    console.log("onBeforeSendHeaders fired");
    var xdata=data.requestHeaders;
    xdata.push({
        "name":"Referer",
        "value": "http://the.new/referrer"
    })
    return {requestHeaders: xdata};
}, { //Filter
    urls: ["<all_urls>"], //For testing purposes
    types: ["xmlhttprequest"]
},["requestHeaders","blocking"]);

But this doesn’t work for the AJAX requests in my extension. It only fires the event on other AJAX requests but not the ones done in my extension.
Another strange thing is that everything works fine when “blocking” flag is not set, but then I can’t change the headers.

Does anyone know a way to solve this (or another way to achieve my goal: changing the “Referer” for a site request and retrieving the contents)

Thank you 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T05:05:49+00:00Added an answer on June 8, 2026 at 5:05 am

    The reason you can’t set the Referrer header when you don’t have a blocking request is that the request has potentially already gone out – you are being notified asynchronously, and cannot change anything about the request.

    To change headers, I use this code:

    function mod_headers(header_array,p_name,p_value) {
         var did_set = false;                                                                                      
         for(var i in header_array) {                                                                                                   
             var header = header_array[i];                                                                                              
             var name = header.name;                                                                                                    
             var value = header.value;                                                                                                  
    
             // If the header is already present, change it:
             if(name == p_name) {
                 header.value = p_value;
                 did_set = true;
             }                                                                                                         
         }
         // if it is not, add it:
         if(!did_set) { header_array.push( { name : p_name , value : p_value } ); }                                                                                                                       
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add a referer to an http post in Apache HttpClient (httpclient-4.0-beta2).
im trying add item with ajax, all work, except the view doesnt refresh, when
Trying to add a custom header item to a Lotus Notes email item, from
I am trying to set a cookie in a wp ajax request handler without
Trying to add an onclick handler to my tabs, and can't seem to get
I'm trying add data triggers to the default combobox style so each text item
I am trying add picture boxes dynamically. My code is as PictureBox picture =
Im new to asp.net mvc. I'm trying add new model class but it got
Trying to add init parameter names to a list in init(ServletConfig) method. public void
Trying to add a blank sample app for a rails tutorial to GitHub, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.