D
D
Dmitry2019-10-25 16:32:20
JavaScript
Dmitry, 2019-10-25 16:32:20

How to hide referer for two iframes on a page?

Good day.
Task:
1. Open two third-party sites in a browser window, dividing the screen into 2 halves (I think to do this through 2 iframes, if there are other ways, tell me);
2. Reduce them a little so that you can see more content on the screen (zoom: 0.8);
3. And most importantly, hide the referer for these third party sites.
I think this can be done with a chrome extension.
Can this be done? If so, point in the right direction.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nadim Zakirov, 2019-10-25
@zkrvndm

Chrome extensions have a background page background.js
Inside this background page, you can place code that will be executed before the sites load and replace the referer header. The chrome.webRequest API will help you with this, code example for the background page:

chrome.webRequest.onBeforeSendHeaders.addListener(function(details){
    var newRef = "http://referer.domain/helloworld.example";
    var gotRef = false;
    for(var n in details.requestHeaders){
        gotRef = details.requestHeaders[n].name.toLowerCase()=="referer";
        if(gotRef){
            details.requestHeaders[n].value = newRef;
            break;
        }
    }
    if(!gotRef){
        details.requestHeaders.push({name:"Referer",value:newRef});
    }
    return {requestHeaders:details.requestHeaders};
},{
    urls:["http://target.domain/*"]
},[
    "requestHeaders",
    "blocking"
]);

Meanwhile, for this code to work, and the webRequest and webRequestBlocking permissions must be specified in the manifest, a piece of one of my manifestos, as an example:
"permissions" : [ "webRequest", "webRequestBlocking", "https://*.avito.ru/*" ],
"background" : { "persistent": true, "scripts": [ "background.js" ] },

I completely forgot that in order for the preprocessor to work in a frame, you need to replace the condition with:
{
    urls:["http://target.domain/*"]
}

to:
PS If you want to delve into the topic, google about the webRequest API and about the onBeforeSendHeaders event, of course there are no normal materials in Russian, but in English. full of good manuals.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question