-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.js
33 lines (29 loc) · 873 Bytes
/
main.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
const findJsonMimeType = (header) => {
if (header.name === undefined) {
return false;
}
return (
header.name.toLowerCase() === 'content-type' &&
header.value.includes('json')
);
};
const overrideJsonHeader = (request) =>
new Promise((resolve) => {
if (request.responseHeaders.find(findJsonMimeType)) {
const jsonHeader = {
name: 'Content-Type',
value: 'application/json',
};
request.responseHeaders.push(jsonHeader);
}
resolve({ responseHeaders: request.responseHeaders });
});
browser.webRequest.onHeadersReceived.addListener(
overrideJsonHeader,
{
urls: ['<all_urls>'],
},
['blocking', 'responseHeaders'],
);
exports.findJsonMimeType = findJsonMimeType;
exports.overrideJsonHeader = overrideJsonHeader;