forked from GoogleChrome/chrome-extensions-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
38 lines (33 loc) · 1.11 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
// Simple extension to remove 'Cookie' request header and 'Set-Cookie' response
// header.
function removeHeader(headers, name) {
for (var i = 0; i < headers.length; i++) {
if (headers[i].name.toLowerCase() == name) {
console.log('Removing "' + name + '" header.');
headers.splice(i, 1);
break;
}
}
}
chrome.webRequest.onBeforeSendHeaders.addListener(
function(details) {
removeHeader(details.requestHeaders, 'cookie');
return {requestHeaders: details.requestHeaders};
},
// filters
{urls: ['https://*/*', 'http://*/*']},
// extraInfoSpec
['blocking', 'requestHeaders', 'extraHeaders']);
chrome.webRequest.onHeadersReceived.addListener(
function(details) {
removeHeader(details.responseHeaders, 'set-cookie');
return {responseHeaders: details.responseHeaders};
},
// filters
{urls: ['https://*/*', 'http://*/*']},
// extraInfoSpec
['blocking', 'responseHeaders', 'extraHeaders']);