diff --git a/manifest.json b/manifest.json index 42d0386..03c3ff1 100644 --- a/manifest.json +++ b/manifest.json @@ -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" diff --git a/popup.html b/popup.html new file mode 100644 index 0000000..877e4ec --- /dev/null +++ b/popup.html @@ -0,0 +1,3 @@ + +
+ diff --git a/popup.js b/popup.js new file mode 100644 index 0000000..2c4d0bd --- /dev/null +++ b/popup.js @@ -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}
`) + ); + output.innerHTML = output_txt; +} + +chrome.runtime.sendMessage({ msg: "get_memory" }, (memory) => { + render(memory); +}); + +clean.onclick = () => { + chrome.runtime.sendMessage({ msg: "clear_memory" }, render); +}; diff --git a/problematic.js b/problematic.js index 060c452..a9fc3f3 100644 --- a/problematic.js +++ b/problematic.js @@ -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: [""] }, ["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 = {}; + } +});