From d2f540d593b6d4479e771d9f4cb1ac9d7030440f Mon Sep 17 00:00:00 2001 From: Mohammad Taqui Sayed <6297436+mohdsayed@users.noreply.github.com> Date: Tue, 27 Feb 2024 13:51:08 +0530 Subject: [PATCH 1/2] Fix: Allow listed rows to highlight after frame change (#531) --- .../cookies/cookiesListing/useCookieListing/useHighlighting.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/extension/src/view/devtools/components/cookies/cookiesListing/useCookieListing/useHighlighting.tsx b/packages/extension/src/view/devtools/components/cookies/cookiesListing/useCookieListing/useHighlighting.tsx index 7653beb63..e5f7b5972 100644 --- a/packages/extension/src/view/devtools/components/cookies/cookiesListing/useCookieListing/useHighlighting.tsx +++ b/packages/extension/src/view/devtools/components/cookies/cookiesListing/useCookieListing/useHighlighting.tsx @@ -54,7 +54,7 @@ const useHighlighting = ( } return prevState; }); - }, [cookies, handleHighlighting, setTableData]); + }, [cookies, handleHighlighting, setTableData, domainsInAllowList?.size]); }; export default useHighlighting; From 6853b8e70e9c59cac9e5d01f94d74ac092391b4d Mon Sep 17 00:00:00 2001 From: Mayank Rana <58820001+mayan-000@users.noreply.github.com> Date: Tue, 27 Feb 2024 17:47:35 +0530 Subject: [PATCH 2/2] Fix: Process ccTLDs and update UI in RWS (#523) * fix: update UI and logic to process ccTLD * ref: wrap url with anchor tag * test: add testscases for ccTlds --- .../extension/src/utils/findRWSURLSets.ts | 71 ++++++++-- .../relatedWebsiteSets/insights/index.tsx | 43 ++++-- .../insights/utils/checkURLInRWS.ts | 21 ++- .../insights/utils/tests/checkURLInRWS.ts | 125 ++++++++++++++---- 4 files changed, 209 insertions(+), 51 deletions(-) diff --git a/packages/extension/src/utils/findRWSURLSets.ts b/packages/extension/src/utils/findRWSURLSets.ts index d24dd8456..d02f87ffe 100644 --- a/packages/extension/src/utils/findRWSURLSets.ts +++ b/packages/extension/src/utils/findRWSURLSets.ts @@ -23,21 +23,72 @@ import { getDomain } from 'tldts'; */ import type { RelatedWebsiteSetType } from '../@types'; +export type RWSSetOutputType = RelatedWebsiteSetType & { + ccTLDParent?: string; +}; + const findRWSURLSets = ( domain: string | null, rwsSets: RelatedWebsiteSetType[] -): RelatedWebsiteSetType | undefined => { - return rwsSets.find((rws: RelatedWebsiteSetType) => { - const rwsDomains: string[] = Object.keys(rws.rationaleBySite || {}).map( - (_url) => getDomain(_url) || '' - ); - - if (domain === getDomain(rws.primary)) { - return true; +): RWSSetOutputType | undefined => { + if (!domain) { + return undefined; + } + + let ccTLDParentURL = ''; + + const res: RWSSetOutputType | undefined = rwsSets.find( + (rws: RelatedWebsiteSetType) => { + if (domain === getDomain(rws.primary)) { + return true; + } + + const rwsDomains: string[] = Object.keys(rws.rationaleBySite || {}).map( + (_url) => getDomain(_url) || '' + ); + + if (rwsDomains.includes(domain)) { + return true; + } + + const ccTLDs = Object.entries(rws.ccTLDs || {}).reduce( + (acc, [ccTLDParent, _ccTLDs]: [string, string[]]) => { + const ccTLDsObj = _ccTLDs.reduce( + (ccTLDAcc, ccTLD) => { + const ccTLDDomain = getDomain(ccTLD) || ''; + + if (ccTLDDomain) { + ccTLDAcc[ccTLDDomain] = ccTLDParent; + } + + return ccTLDAcc; + }, + {} as { + [ccTLD: string]: string; + } + ); + + return { ...acc, ...ccTLDsObj }; + }, + {} as { + [ccTLD: string]: string; + } + ); + + if (ccTLDs[domain]) { + ccTLDParentURL = ccTLDs[domain]; + return true; + } + + return false; } + ); + + if (ccTLDParentURL && res) { + res.ccTLDParent = ccTLDParentURL; + } - return domain ? rwsDomains.includes(domain) : false; - }); + return res; }; export default findRWSURLSets; diff --git a/packages/extension/src/view/devtools/components/siteBoundaries/relatedWebsiteSets/insights/index.tsx b/packages/extension/src/view/devtools/components/siteBoundaries/relatedWebsiteSets/insights/index.tsx index 64ecd82ce..1b1935d66 100644 --- a/packages/extension/src/view/devtools/components/siteBoundaries/relatedWebsiteSets/insights/index.tsx +++ b/packages/extension/src/view/devtools/components/siteBoundaries/relatedWebsiteSets/insights/index.tsx @@ -110,18 +110,37 @@ const Insights = () => {

{!insightsData.primary ? ( <> - {Object.entries( - insightsData.relatedWebsiteSet?.rationaleBySite || {} - ) - .filter( - ([domain]) => getDomain(domain) === insightsData.domain - ) - .map(([domain, value]) => ( -

- Rationale:{' '} - {value as string} -

- ))} + {insightsData.isccTLD ? ( +

+ This site is a ccTLD of{' '} + + {insightsData.relatedWebsiteSet?.ccTLDParent} + + . +

+ ) : ( + <> + {Object.entries( + insightsData.relatedWebsiteSet?.rationaleBySite || {} + ) + .filter( + ([domain]) => + getDomain(domain) === insightsData.domain + ) + .map(([domain, value]) => ( +

+ Rationale:{' '} + {value as string} +

+ ))} + + )} ) : (

diff --git a/packages/extension/src/view/devtools/components/siteBoundaries/relatedWebsiteSets/insights/utils/checkURLInRWS.ts b/packages/extension/src/view/devtools/components/siteBoundaries/relatedWebsiteSets/insights/utils/checkURLInRWS.ts index a5245caee..d45d6776b 100644 --- a/packages/extension/src/view/devtools/components/siteBoundaries/relatedWebsiteSets/insights/utils/checkURLInRWS.ts +++ b/packages/extension/src/view/devtools/components/siteBoundaries/relatedWebsiteSets/insights/utils/checkURLInRWS.ts @@ -24,21 +24,23 @@ import { getDomain } from 'tldts'; */ import fetchRWSInfo from '../../../../../../../utils/fetchRWSInfo'; import getInspectedTabDomain from './getInspectedTabDomain'; -import type { RelatedWebsiteSetType } from '../../../../../../../@types'; -import findRWSURLSets from '../../../../../../../utils/findRWSURLSets'; +import findRWSURLSets, { + type RWSSetOutputType, +} from '../../../../../../../utils/findRWSURLSets'; export type CheckURLInRWSOutputType = { isURLInRWS: boolean; primary?: boolean; domain?: string; - relatedWebsiteSet?: RelatedWebsiteSetType; + isccTLD?: boolean; + relatedWebsiteSet?: RWSSetOutputType; }; const checkURLInRWS = async () => { const tabDomain = (await getInspectedTabDomain()) || ''; - const rwsSets: RelatedWebsiteSetType[] = (await fetchRWSInfo()).sets || []; + const rwsSets: RWSSetOutputType[] = (await fetchRWSInfo()).sets || []; - const urlInRWS: RelatedWebsiteSetType | undefined = findRWSURLSets( + const urlInRWS: RWSSetOutputType | undefined = findRWSURLSets( tabDomain, rwsSets ); @@ -58,6 +60,15 @@ const checkURLInRWS = async () => { } as CheckURLInRWSOutputType; } + if (urlInRWS.ccTLDParent) { + return { + isURLInRWS: true, + isccTLD: true, + domain: tabDomain, + relatedWebsiteSet: urlInRWS, + } as CheckURLInRWSOutputType; + } + return { isURLInRWS: true, primary: false, diff --git a/packages/extension/src/view/devtools/components/siteBoundaries/relatedWebsiteSets/insights/utils/tests/checkURLInRWS.ts b/packages/extension/src/view/devtools/components/siteBoundaries/relatedWebsiteSets/insights/utils/tests/checkURLInRWS.ts index 48dec3dca..2871557d0 100644 --- a/packages/extension/src/view/devtools/components/siteBoundaries/relatedWebsiteSets/insights/utils/tests/checkURLInRWS.ts +++ b/packages/extension/src/view/devtools/components/siteBoundaries/relatedWebsiteSets/insights/utils/tests/checkURLInRWS.ts @@ -20,61 +20,138 @@ import checkURLInRWS from '../checkURLInRWS'; describe('checkURLInRWS', () => { - beforeAll(() => { - globalThis.chrome = { - devtools: { - inspectedWindow: { - tabId: 1, + globalThis.chrome = { + devtools: { + inspectedWindow: { + tabId: 1, + }, + }, + tabs: { + get: () => ({ url: 'https://hindustantimes.com' }), + }, + runtime: { + getURL: () => 'data/related_website_sets.json', + }, + } as unknown as typeof chrome; + + globalThis.fetch = (): Promise => + Promise.resolve({ + json: () => + Promise.resolve({ + sets: [ + { + contact: 'prashant.tiwari@htdigital.in', + primary: 'https://hindustantimes.com', + associatedSites: ['https://livemint.com'], + rationaleBySite: { + 'https://livemint.com': 'Specialized Platform for economics', + }, + }, + ], + }), + } as Response); + + test('should return true if the tab domain is the same as the primary domain', async () => { + const result = await checkURLInRWS(); + + expect(result).toEqual({ + isURLInRWS: true, + primary: true, + domain: 'hindustantimes.com', + relatedWebsiteSet: { + contact: 'prashant.tiwari@htdigital.in', + primary: 'https://hindustantimes.com', + associatedSites: ['https://livemint.com'], + rationaleBySite: { + 'https://livemint.com': 'Specialized Platform for economics', }, }, + }); + }); + + test('should return false if tab domain not present in RWS', async () => { + globalThis.chrome = { + ...globalThis.chrome, tabs: { - get: () => ({ url: 'https://hindustantimes.com' }), + get: () => ({ url: 'https://indianexpress.com' }), }, - runtime: { - getURL: () => 'data/related_website_sets.json', + } as unknown as typeof chrome; + + const result = await checkURLInRWS(); + + expect(result).toEqual({ + isURLInRWS: false, + }); + }); + + test('should return true if the tab domain is a ccTLD', async () => { + globalThis.chrome = { + ...globalThis.chrome, + tabs: { + get: () => ({ url: 'https://mercadolibre.com.ec' }), }, } as unknown as typeof chrome; + globalThis.fetch = (): Promise => Promise.resolve({ json: () => Promise.resolve({ sets: [ { - contact: 'prashant.tiwari@htdigital.in', - primary: 'https://hindustantimes.com', - associatedSites: ['https://livemint.com'], - rationaleBySite: { - 'https://livemint.com': 'Specialized Platform for economics', + contact: 'infraestructura@mercadolibre.com', + primary: 'https://mercadolibre.com', + associatedSites: [], + rationaleBySite: {}, + ccTLDs: { + 'https://mercadolibre.com': [ + 'https://mercadolibre.com.ar', + 'https://mercadolibre.com.mx', + 'https://mercadolibre.com.bo', + 'https://mercadolibre.cl', + 'https://mercadolibre.com.co', + 'https://mercadolibre.co.cr', + 'https://mercadolibre.com.do', + 'https://mercadolibre.com.ec', + ], }, }, ], }), } as Response); - }); - test('should return true if the tab domain is the same as the primary domain', async () => { const result = await checkURLInRWS(); expect(result).toEqual({ isURLInRWS: true, - primary: true, - domain: 'hindustantimes.com', + isccTLD: true, + domain: 'mercadolibre.com.ec', relatedWebsiteSet: { - contact: 'prashant.tiwari@htdigital.in', - primary: 'https://hindustantimes.com', - associatedSites: ['https://livemint.com'], - rationaleBySite: { - 'https://livemint.com': 'Specialized Platform for economics', + contact: 'infraestructura@mercadolibre.com', + primary: 'https://mercadolibre.com', + ccTLDParent: 'https://mercadolibre.com', + associatedSites: [], + rationaleBySite: {}, + ccTLDs: { + 'https://mercadolibre.com': [ + 'https://mercadolibre.com.ar', + 'https://mercadolibre.com.mx', + 'https://mercadolibre.com.bo', + 'https://mercadolibre.cl', + 'https://mercadolibre.com.co', + 'https://mercadolibre.co.cr', + 'https://mercadolibre.com.do', + 'https://mercadolibre.com.ec', + ], }, }, }); }); - test('should return false if tab domain not present in RWS', async () => { + test('should return false if the tab domain is not a ccTLD', async () => { globalThis.chrome = { ...globalThis.chrome, tabs: { - get: () => ({ url: 'https://indianexpress.com' }), + get: () => ({ url: 'https://mercadolibre.com.arg' }), }, } as unknown as typeof chrome;