From f257af7c12f5d28afe03160c24d1c7804b5698c3 Mon Sep 17 00:00:00 2001 From: Dale Wahl Date: Wed, 29 Nov 2023 12:52:45 +0100 Subject: [PATCH 1/4] this checks both source_url and source_platform_url as possible registered modules while checking both keys is annoying, this resolves a bug where the source_platform_url is not the expected platform domain as it was linked from outside the domain (e.g., you click a link to TikTok from elsewhere). --- js/zs-background.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/js/zs-background.js b/js/zs-background.js index 7b88ca4..054fb17 100644 --- a/js/zs-background.js +++ b/js/zs-background.js @@ -52,7 +52,9 @@ window.zeeschuimer = { let decoder = new TextDecoder("utf-8"); let full_response = ''; let source_url = details.url; + let base_source_key = 'zs-enabled-' + source_url.split('://').pop().split('/')[0].replace(/^www\./, '').toLowerCase(); let source_platform_url = details.hasOwnProperty("originUrl") ? details.originUrl : source_url; + let base_source_platform_key = 'zs-enabled-' +source_platform_url.split('://').pop().split('/')[0].replace(/^www\./, '').toLowerCase(); filter.ondata = event => { let str = decoder.decode(event.data, {stream: true}); @@ -61,11 +63,16 @@ window.zeeschuimer = { } filter.onstop = async (event) => { - let base_url = source_platform_url ? source_platform_url : source_url; - let source_platform = base_url.split('://').pop().split('/')[0].replace(/^www\./, '').toLowerCase(); - let enabled_key = 'zs-enabled-' + source_platform; - let is_enabled = await browser.storage.local.get(enabled_key); - let enabled = is_enabled.hasOwnProperty(enabled_key) && !!parseInt(is_enabled[enabled_key]); + // check if the source URL is enabled + let is_source_url_enabled = await browser.storage.local.get(base_source_key); + let enabled = is_source_url_enabled.hasOwnProperty(base_source_key) && !!parseInt(is_source_url_enabled[base_source_key]); + if (!enabled) { + // check if the source platform URL is enabled + let is_platform_url_enabled = await browser.storage.local.get(base_source_platform_key); + enabled = is_platform_url_enabled.hasOwnProperty(base_source_platform_key) && !!parseInt(is_platform_url_enabled[base_source_platform_key]); + } + //console.log(`source_url ${source_url}; source_platform_url ${source_platform_url} is ${enabled}`); + if (enabled) { zeeschuimer.parse_request(full_response, source_platform_url, source_url, details.tabId); } @@ -73,6 +80,11 @@ window.zeeschuimer = { full_response = ''; } + filter.onerror = event => { + console.error("Error filtering request", event); + filter.disconnect(); + } + return {}; }, From 8d85349584d222e607a020de8c7f18e6e5b822df Mon Sep 17 00:00:00 2001 From: Dale Wahl Date: Wed, 29 Nov 2023 13:01:36 +0100 Subject: [PATCH 2/4] minor browser-breaking bug fix :hushed: --- js/zs-background.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/zs-background.js b/js/zs-background.js index 054fb17..82a2357 100644 --- a/js/zs-background.js +++ b/js/zs-background.js @@ -54,7 +54,7 @@ window.zeeschuimer = { let source_url = details.url; let base_source_key = 'zs-enabled-' + source_url.split('://').pop().split('/')[0].replace(/^www\./, '').toLowerCase(); let source_platform_url = details.hasOwnProperty("originUrl") ? details.originUrl : source_url; - let base_source_platform_key = 'zs-enabled-' +source_platform_url.split('://').pop().split('/')[0].replace(/^www\./, '').toLowerCase(); + let base_source_platform_key = source_platform_url ? 'zs-enabled-' + source_platform_url.split('://').pop().split('/')[0].replace(/^www\./, '').toLowerCase() : ''; filter.ondata = event => { let str = decoder.decode(event.data, {stream: true}); @@ -66,7 +66,7 @@ window.zeeschuimer = { // check if the source URL is enabled let is_source_url_enabled = await browser.storage.local.get(base_source_key); let enabled = is_source_url_enabled.hasOwnProperty(base_source_key) && !!parseInt(is_source_url_enabled[base_source_key]); - if (!enabled) { + if (!enabled && base_source_platform_key) { // check if the source platform URL is enabled let is_platform_url_enabled = await browser.storage.local.get(base_source_platform_key); enabled = is_platform_url_enabled.hasOwnProperty(base_source_platform_key) && !!parseInt(is_platform_url_enabled[base_source_platform_key]); From b4324d1dd6bc560e47862db3444d0dac1348317a Mon Sep 17 00:00:00 2001 From: Dale Wahl Date: Wed, 29 Nov 2023 13:05:10 +0100 Subject: [PATCH 3/4] remove log --- js/zs-background.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/js/zs-background.js b/js/zs-background.js index 82a2357..f923cba 100644 --- a/js/zs-background.js +++ b/js/zs-background.js @@ -80,11 +80,6 @@ window.zeeschuimer = { full_response = ''; } - filter.onerror = event => { - console.error("Error filtering request", event); - filter.disconnect(); - } - return {}; }, From 90a1f3566696c81bb611bd73a5bb59d3825753a6 Mon Sep 17 00:00:00 2001 From: Stijn Peeters Date: Thu, 30 Nov 2023 18:12:29 +0100 Subject: [PATCH 4/4] Explain extra check --- js/zs-background.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/zs-background.js b/js/zs-background.js index f923cba..0aa34d5 100644 --- a/js/zs-background.js +++ b/js/zs-background.js @@ -68,10 +68,12 @@ window.zeeschuimer = { let enabled = is_source_url_enabled.hasOwnProperty(base_source_key) && !!parseInt(is_source_url_enabled[base_source_key]); if (!enabled && base_source_platform_key) { // check if the source platform URL is enabled + // this extra check is necessary e.g. if the request was initiated from another domain + // unrelated to the website (which then wouldn't match the domain that this platform + // is recognised by) let is_platform_url_enabled = await browser.storage.local.get(base_source_platform_key); enabled = is_platform_url_enabled.hasOwnProperty(base_source_platform_key) && !!parseInt(is_platform_url_enabled[base_source_platform_key]); } - //console.log(`source_url ${source_url}; source_platform_url ${source_platform_url} is ${enabled}`); if (enabled) { zeeschuimer.parse_request(full_response, source_platform_url, source_url, details.tabId);