-
Notifications
You must be signed in to change notification settings - Fork 2
/
inline.js
32 lines (30 loc) · 1.19 KB
/
inline.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
"use strict";
function ChangeContentDispositionHeaderToInline(e) {
let found_content_disposition_header = false;
let found_content_type_header = false;
for (const header of e.responseHeaders) {
if (header.name.toLowerCase() === 'content-disposition') {
found_content_disposition_header = true;
header.value = 'inline';
}
if (header.name.toLowerCase() === 'content-type') {
found_content_type_header = true;
header.value = 'application/pdf';
}
}
if (!found_content_disposition_header) {
console.debug("Did not find Content-Disposition header. Adding the header.");
e.responseHeaders.push({"name":"content-disposition", "value": "inline"});
}
if (!found_content_type_header){
console.debug("Did not find Content-Type header. Adding the header.");
e.responseHeaders.push({"name":"content-type", "value": "application/pdf"});
}
console.debug(e.responseHeaders);
return {responseHeaders: e.responseHeaders};
}
browser.webRequest.onHeadersReceived.addListener(
ChangeContentDispositionHeaderToInline,
{urls: ["*://*/*.pdf*"]},
["blocking", "responseHeaders"]
);