forked from devcer/httpboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
49 lines (42 loc) · 1.37 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
39
40
41
42
43
44
45
46
47
48
49
var target = "<all_urls>";
var httpTextResponse="";
function logResponse(response) {
//calculate time from UNIX epoch timeStamp in milliseconds
var responseTimeStamp = new Date();
responseTimeStamp.setTime(response.timeStamp);
//for parameter :response.fromCache
var responseCache="NOT ";
if(response.fromCache){
responseCache="";
}
//fetch Array objects of responseHeaders
function objToString (obj) {
var str = '';
var str2 = '';
for (var p in obj) {
if (obj.hasOwnProperty(p)){
var q = obj[p];
var tempstr = '';
for(var r in q){
if (q.hasOwnProperty(r)){
if (tempstr== ''){
tempstr = q[r] + ": ";
str = tempstr;
}
else
str +=q[r]+ "\n";
}
}
}
str2 +=str;
}
return str2;
}
httpTextResponse = "You entered :" + response.originUrl + "\n\nRequest Method: " + response.method + "\nStatus: " + response.statusCode + "\nStatus line:" + response.statusLine + "\nIP Address: " + response.ip +"\nDate: "+ responseTimeStamp + "\nTarget Url:" + response.url + "\nResponse type: "+ response.type + "\nRequest ID: " + response.requestId + "\nResponse was "+ responseCache +"fetched from disk cache.\n" + objToString(response.responseHeaders) + "\n\n";
console.log(httpTextResponse);
}
browser.webRequest.onCompleted.addListener(
logResponse,
{urls: [target]},
["responseHeaders"]
);