Skip to content

Instantly share code, notes, and snippets.

@amitmbee
Created January 30, 2018 11:48
Show Gist options
  • Select an option

  • Save amitmbee/4258e73d7da3a9823d2250c7feed8fa2 to your computer and use it in GitHub Desktop.

Select an option

Save amitmbee/4258e73d7da3a9823d2250c7feed8fa2 to your computer and use it in GitHub Desktop.
[Set response headers on Chrome extensions API]
chrome.webRequest.onHeadersReceived.addListener(//For getting responses : use onHeadersReceived Event
callback,
{
urls: ["<all_urls>"],
types: ["xmlhttprequest"],
},
["blocking", "responseHeaders"]// For response event use ["blocking", "responseHeaders"] filters and return {responseHeaders: details.responseHeaders}; to block and modify requests
);
function callback(details){
details.responseHeaders.find((headerType,index) => {
console.log(headerType)
if(headerType.name == 'status'){
headerType.value = '404'
}
if(headerType.name === "content-type"){
headerType.value = ""
}
if(headerType.name === "pragma"){
headerType.value = ""
}
if(headerType.name === "expires"){
headerType.value = ""
}
})
return { responseHeaders: details.responseHeaders };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment