Working popup
This commit is contained in:
parent
750b68fa24
commit
4070fac3e0
|
@ -16,7 +16,7 @@
|
|||
"browser_action": {
|
||||
"default_icon": "border-48.png",
|
||||
"default_title": "Pokaż problematyczne requesty",
|
||||
"default_popup": "popup/choose_beast.html"
|
||||
"default_popup": "popup.html"
|
||||
},
|
||||
"icons": {
|
||||
"48": "icons/border-48.png"
|
||||
|
|
3
popup.html
Normal file
3
popup.html
Normal file
|
@ -0,0 +1,3 @@
|
|||
<button id="clean">clean memory</button>
|
||||
<div id="output"></div>
|
||||
<script src="popup.js"></script>
|
29
popup.js
Normal file
29
popup.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
output.innerHTML = "loading...";
|
||||
let tabid = null;
|
||||
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
|
||||
var currTab = tabs[0];
|
||||
if (currTab) {
|
||||
// Sanity check
|
||||
/* document.write(JSON.stringify(currTab)); */
|
||||
tabid = currTab.id;
|
||||
}
|
||||
});
|
||||
|
||||
function render(memory = {}) {
|
||||
let output_txt = "";
|
||||
if (!memory?.[tabid]) {
|
||||
output_txt = "No data for this tab";
|
||||
}
|
||||
Object.keys(memory[tabid]).forEach(
|
||||
(host) => (output_txt += /* HTML */ `${host}</br>`)
|
||||
);
|
||||
output.innerHTML = output_txt;
|
||||
}
|
||||
|
||||
chrome.runtime.sendMessage({ msg: "get_memory" }, (memory) => {
|
||||
render(memory);
|
||||
});
|
||||
|
||||
clean.onclick = () => {
|
||||
chrome.runtime.sendMessage({ msg: "clear_memory" }, render);
|
||||
};
|
|
@ -1,5 +1,7 @@
|
|||
console.log("PROBLEMATIC REQUESTS");
|
||||
|
||||
let memory = {};
|
||||
|
||||
// const isThirdParty = (arg) => arg.urlClassification.thirdParty.length > 0;
|
||||
async function isThirdParty(request) {
|
||||
const request_url = new URL(request.url);
|
||||
|
@ -18,7 +20,7 @@ const getReferer = (arg) =>
|
|||
|
||||
const getOrigin = async (arg) => {
|
||||
let url;
|
||||
if (arg.tabId) {
|
||||
if (arg.tabId && arg.tabId >= 0) {
|
||||
const tab = await browser.tabs.get(arg.tabId);
|
||||
url = tab.url;
|
||||
} else {
|
||||
|
@ -40,16 +42,31 @@ browser.webRequest.onBeforeSendHeaders.addListener(
|
|||
(await exposesOrigin(request))
|
||||
) {
|
||||
const has_cookie = hasCookie(request);
|
||||
fn = has_cookie ? console.warn : console.log;
|
||||
fn(
|
||||
"Leaked referrer! Has cookie:",
|
||||
hasCookie(request),
|
||||
request.url,
|
||||
"referer was",
|
||||
getReferer(request)
|
||||
);
|
||||
if (!memory[request.tabId]) {
|
||||
memory[request.tabId] = {};
|
||||
}
|
||||
const shorthost = new URL(request.url).host
|
||||
.match(/((\.[^.]+){2}$)/)[0]
|
||||
.slice(1);
|
||||
if (!memory[request.tabId][shorthost]) {
|
||||
memory[request.tabId][shorthost] = [];
|
||||
}
|
||||
memory[request.tabId][shorthost].push({ url: request.url, has_cookie });
|
||||
}
|
||||
},
|
||||
{ urls: ["<all_urls>"] },
|
||||
["requestHeaders"]
|
||||
);
|
||||
|
||||
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
|
||||
if (sender.tab) {
|
||||
return;
|
||||
}
|
||||
console.log("got message!", request);
|
||||
if (request?.msg === "get_memory") {
|
||||
sendResponse(memory);
|
||||
} else if (request?.msg === "clear_memory") {
|
||||
console.log("memory cleared");
|
||||
memory = {};
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user