-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
38 lines (30 loc) · 910 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
33
34
35
36
37
38
/**
When we receive the message, add referer to Request Header
*/
var urlfield = "";
var refererfield = "";
function rewriteReferer(e) {
if (e.url !== urlfield) return {};
e.requestHeaders.push({
name: "Referer",
value: refererfield
});
browser.webRequest.onBeforeSendHeaders.removeListener(rewriteReferer);
return {requestHeaders: e.requestHeaders};
}
function handleMessage(request, sender, sendResponse) {
urlfield = request.urlfield;
refererfield = request.refererfield;
if (sender.url !== browser.runtime.getURL("/hackbar/ui.html")) {
return;
}
browser.webRequest.onBeforeSendHeaders.addListener(
rewriteReferer,
{urls: ["<all_urls>"], types: ["main_frame"]},
["blocking", "requestHeaders"]
);
}
/**
Listen for messages from our devtools panel.
*/
browser.runtime.onMessage.addListener(handleMessage);