1

I'm trying to change chrome headers. I've tried two approaches

1) use chrome extensions
2) Write my own extension

1) I've installed Requestly and added a rule

enter image description here

Now if I load, for example, facebook.com and open the dev-tools, I don't see this response header

enter image description here

I don't see why this doesn't work. I assume that the rule set in Requestly applies to all tabs.

2) This approach was inspired by this post. So, I created an extensions with the following code:

function updateHeaders() {
    chrome.webRequest.onHeadersReceived.addListener(function(details){
        for(var i = 0; i < details.responseHeaders.length; ++i)
            if(details.responseHeaders[i].name.toLowerCase() == 'server')
                details.responseHeaders[i].value = 'barfoo';
        return {responseHeaders:details.responseHeaders};
    }, {urls: ['*://*']}, ['blocking', 'responseHeaders']);
}

document.addEventListener('DOMContentLoaded', updateHeaders());

manifest.json

{
    "manifest_version": 2,

    "name": "Getting started example",
    "description": "Replace the server header",
    "version": "1.0",

    "browser_action": {
        "default_icon": "icon.png",
        "default_popup": "popup.html",
        "default_title": "Click here!"
   },
    "permissions": [
        "webRequest"
    ]
}

Which doesn't work too

I must admit I have no experience with building chrome extensions, so the changes are pretty big that what I'm trying here doesn't make any sense, so any help would be appreciated!

Community
  • 1
  • 1
Jeanluca Scaljeri
  • 26,343
  • 56
  • 205
  • 333
  • 2
    Youve set your filter to request, not response... – BugFinder May 22 '16 at 13:10
  • check, thats a mistake I made for this screen shot! Anyway, even with `response` set I noticed that `Add` sometimes works but `Modify` doesn't. I'm also not sure what to do to have changes take effect; do I have to kill the browser. I didn't discover a pattern yet. – Jeanluca Scaljeri May 22 '16 at 13:39
  • Id imagine its whether its pulling data from cache or not – BugFinder May 22 '16 at 13:53
  • Even in that case I can imagine that the extension is in the middle and does its magic – Jeanluca Scaljeri May 22 '16 at 13:54
  • Dunno, because in effect it already has it cached it, i can see it would feed you what it has from before. – BugFinder May 22 '16 at 14:35
  • Adding `--disable-web-security --user-data-dir` to chrome seems to fix this – Jeanluca Scaljeri May 23 '16 at 07:27
  • Requestly Developer here, Please have a look at this: https://github.com/requestly/chrome-extension/issues/127. It simply proves the point about modification in response headers do work but are not visible in Developer tools. – Sachin Jain Jun 04 '16 at 01:31

0 Answers0