wvg/background.js

75 lines
1.6 KiB
JavaScript
Raw Normal View History

2024-04-08 22:58:09 +00:00
let psshs=[];
let requests=[];
2024-04-26 01:53:24 +00:00
let bodys=[];
2024-04-24 18:37:31 +00:00
let 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") {
requests.push({
url:details.url,
2024-04-26 01:53:24 +00:00
headers:convertHeaders(details.requestHeaders),
body: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") {
bodys.push({
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":
psshs=[];
requests=[];
2024-04-26 01:53:24 +00:00
bodys=[];
2024-04-08 22:58:09 +00:00
break;
case "PSSH":
psshs.push(request.text)
2024-04-24 18:37:31 +00:00
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
});
});
window.getPsshs = () => {
return psshs;
};
window.getRequests = () => {
return requests;
};
2024-04-24 18:37:31 +00:00
window.getPageURL = () => {
return pageURL;
};