wvg/background.js

63 lines
1.5 KiB
JavaScript
Raw Normal View History

2024-04-30 18:23:08 +00:00
window.psshs=[];
window.requests=[];
window.bodys=[];
window.pageURL="";
2024-04-08 22:58:09 +00:00
function convertHeaders(obj){
2024-04-18 20:48:32 +00:00
return JSON.stringify(Object.fromEntries(obj.map(header => [header.name, header.value])))
2024-04-08 22:58:09 +00:00
}
2024-04-26 01:53:24 +00:00
//Get URL and headers from POST requests
2024-04-08 22:58:09 +00:00
chrome.webRequest.onBeforeSendHeaders.addListener(
function(details) {
if (details.method === "POST") {
2024-04-30 18:23:08 +00:00
window.requests.push({
2024-04-08 22:58:09 +00:00
url:details.url,
2024-04-26 01:53:24 +00:00
headers:convertHeaders(details.requestHeaders),
2024-04-30 18:23:08 +00:00
body:window.bodys.find((b) => b.id == details.requestId).body
2024-04-08 22:58:09 +00:00
});
}
},
{urls: ["<all_urls>"]},
["requestHeaders"]
);
2024-04-26 01:53:24 +00:00
//Get requestBody from POST requests
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
if (details.method === "POST") {
2024-04-30 18:23:08 +00:00
window.bodys.push({
2024-04-26 01:53:24 +00:00
body:btoa(String.fromCharCode(...new Uint8Array(details.requestBody.raw[0]['bytes']))),
id:details.requestId
});
}
},
{urls: ["<all_urls>"]},
["requestBody"]
);
2024-04-08 22:58:09 +00:00
//Receive PSSH from content.js
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
switch(request.type){
case "RESET":
2024-04-30 18:23:08 +00:00
window.psshs=[];
window.requests=[];
window.bodys=[];
2024-04-08 22:58:09 +00:00
break;
case "PSSH":
2024-04-30 18:23:08 +00:00
window.psshs.push(request.text)
window.pageURL=request.pageURL
2024-04-08 22:58:09 +00:00
break;
}
}
);
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.windows.create({
2024-04-24 18:48:34 +00:00
url: "popup.html",
type: "popup",
width: 820,
height: 600
2024-04-08 22:58:09 +00:00
});
});