-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
33 lines (22 loc) · 922 Bytes
/
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
/* global chrome */
const filter = { urls: [ '<all_urls>' ] };
const opt_extraInfoSpec = [ 'blocking', 'responseHeaders' ];
const updateResponseHeaders = responseDetails => {
const { url, responseHeaders } = responseDetails;
// force URLs that end in .json but have other "application" type content-types to json content-type
if(url.match(/\.json$/)) {
const contentTypeHeader = responseHeaders.find(header => header.name.toLowerCase() === 'content-type');
if(contentTypeHeader) {
if(!contentTypeHeader.value || contentTypeHeader.value.startsWith('application/')) {
contentTypeHeader.value = 'application/json';
}
}
else {
responseHeaders.push({ name: 'content-type', value: 'application/json'});
}
}
return {
responseHeaders: responseHeaders,
};
};
chrome.webRequest.onHeadersReceived.addListener(updateResponseHeaders, filter, opt_extraInfoSpec);