From 9038a471109a7e42ba3dd37ce93f812d9453f751 Mon Sep 17 00:00:00 2001 From: Malte <42342921+ccev@users.noreply.github.com> Date: Tue, 23 Apr 2024 22:56:45 +0200 Subject: [PATCH] update the extension --- xilriws-proxy/background.js | 61 ++++++++++++++++++++++++++----------- xilriws-proxy/manifest.json | 4 ++- 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/xilriws-proxy/background.js b/xilriws-proxy/background.js index 27af59e..2056951 100644 --- a/xilriws-proxy/background.js +++ b/xilriws-proxy/background.js @@ -1,5 +1,3 @@ -console.log("test") - const ws = new WebSocket('ws://127.0.0.1:9091'); let currentProxyCreds = { @@ -16,13 +14,17 @@ ws.onmessage = (event) => { password: data.password } startProxy(data.host, data.port) -}; +} + +function sendWs(action, detail) { + ws.send(JSON.stringify({action: action, detail: detail})) +} function startProxy(host, port) { - const config = { - mode: "fixed_servers", + const proxyConfig = { + mode: "system", rules: { - singleProxy: { + proxyForHttps: { scheme: "http", host: host, port: port, @@ -31,20 +33,45 @@ function startProxy(host, port) { }, }; chrome.proxy.settings.set( - {value: config, scope: "regular"}, - function () { + {value: proxyConfig}, + () => { + sendWs('finish:proxy', host + ':' + port) }, - ); -} - -function callbackFn(details) { - return { - authCredentials: currentProxyCreds, - }; + ) } chrome.webRequest.onAuthRequired.addListener( - callbackFn, + () => { + return { + authCredentials: currentProxyCreds + } + }, {urls: [""]}, ["blocking"], -); \ No newline at end of file +) + +chrome.tabs.onRemoved.addListener( + () => { + chrome.storage.local.clear(() => console.log('deleted local storage')) + chrome.cookies.getAll({}, cookies => { + console.log('Deleting ' + cookies.length + ' cookies') + let goal = cookies.length + + function deleteCallback() { + goal -= 1 + + if (goal <= 0) { + console.log('Deleted all cookies') + sendWs('finish:cookiePurge', null) + } + } + + cookies.forEach(cookie => chrome.cookies.remove({ + name: cookie.name, + url: `${cookie.secure ? 'https' : 'http'}://${cookie.domain}${cookie.path}`, + storeId: cookie.storeId + }, deleteCallback)) + } + ) + } +) diff --git a/xilriws-proxy/manifest.json b/xilriws-proxy/manifest.json index d643821..e1ed20a 100644 --- a/xilriws-proxy/manifest.json +++ b/xilriws-proxy/manifest.json @@ -10,7 +10,9 @@ "", "webRequest", "webRequestBlocking", - "devtools" + "devtools", + "cookies", + "storage" ], "background": { "scripts": ["background.js"]