From ee87773ce2e24bf7762b7ffefcb5f7fe5f14dc14 Mon Sep 17 00:00:00 2001 From: kkapsner Date: Sun, 21 Feb 2021 11:49:29 +0100 Subject: [PATCH] Limit periodical rnd clearing Periodical persistent rnd clearing does not clear in active tabs. Fixes #518 --- lib/main.js | 2 +- lib/persistentRndStorage.js | 4 ++-- lib/randomSupplies.js | 23 +++++++++++++++++++---- options/options.js | 2 +- releaseNotes.txt | 2 +- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/main.js b/lib/main.js index 262f1de..1c38902 100644 --- a/lib/main.js +++ b/lib/main.js @@ -90,7 +90,7 @@ } } if (data["canvasBlocker-clear-domain-rnd"]){ - persistentRndStorage.clear(); + persistentRndStorage.clear(data["canvasBlocker-clear-domain-rnd"] === "force"); if (keys.length === 1){ return; } diff --git a/lib/persistentRndStorage.js b/lib/persistentRndStorage.js index 6c8aa3f..b5ed50a 100644 --- a/lib/persistentRndStorage.js +++ b/lib/persistentRndStorage.js @@ -123,14 +123,14 @@ scope.persistentIncognitoRnd = Object.create(null); settings.persistentIncognitoRndStorage = JSON.stringify(scope.persistentIncognitoRnd); } - function clear(){ + function clear(force = false){ logging.verbose("domain rnd cleared"); scope.persistentRnd = Object.create(null); settings.persistentRndStorage = JSON.stringify(scope.persistentRnd); settings.lastPersistentRndClearing = Date.now(); clearIncognito(); registerTimeout(); - broadcast({"canvasBlocker-clear-domain-rnd": true}); + broadcast({"canvasBlocker-clear-domain-rnd": force? "force": true}); } function setDomainData(domain, incognito, rnd){ logging.verbose("got new domain rnd for ", domain, " (incognito:", incognito, "):", rnd); diff --git a/lib/randomSupplies.js b/lib/randomSupplies.js index 9e9c4cf..7d5a2a4 100644 --- a/lib/randomSupplies.js +++ b/lib/randomSupplies.js @@ -82,6 +82,12 @@ let persistentRnd = Object.create(null); let cookieStoreId = false; + function getCookieStoreId(){ + while (cookieStoreId === false){ + extension.waitSync("to wait for cookie store id"); + } + return cookieStoreId; + } settings.onloaded(function(){ try { let storedData = JSON.parse( @@ -116,15 +122,24 @@ } } if (data["canvasBlocker-clear-domain-rnd"]){ + const domain = getCookieStoreId() + getDomain(window); + let ownPersistendRnd = data["canvasBlocker-clear-domain-rnd"] !== "force"? persistentRnd[domain]: false; persistentRnd = Object.create(null); + if (ownPersistendRnd){ + persistentRnd[domain] = ownPersistendRnd; + extension.message.send({ + "canvasBlocker-new-domain-rnd": { + domain, + incognito: extension.inIncognitoContext, + rnd: Array.from(persistentRnd[domain]) + } + }); + } } }); return function getPersistentRnd(window){ - while (cookieStoreId === false){ - extension.waitSync("to wait for cookie store id"); - } - const domain = cookieStoreId + getDomain(window); + const domain = getCookieStoreId() + getDomain(window); if (!persistentRnd[domain]){ // create the (sub-)domains random numbers if not existing persistentRnd[domain] = new Uint8Array(128); diff --git a/options/options.js b/options/options.js index c55ea3b..c156dcb 100644 --- a/options/options.js +++ b/options/options.js @@ -36,7 +36,7 @@ logging.notice("empty storage"); settings.persistentRndStorage = ""; logging.notice("send message to main script"); - extension.message.send({"canvasBlocker-clear-domain-rnd": true}); + extension.message.send({"canvasBlocker-clear-domain-rnd": "force"}); }, clearPersistentRndForContainer: async function(){ const identities = await browser.contextualIdentities.query({}); diff --git a/releaseNotes.txt b/releaseNotes.txt index e3ad123..e708dff 100644 --- a/releaseNotes.txt +++ b/releaseNotes.txt @@ -1,6 +1,6 @@ Version 1.6: changes: - - + - periodical persistent rnd clearing does not clear in active tabs new features: - try to not break tabs when updating