Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Extension UI and Service Worker. #519

Merged
merged 49 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
d652125
Refactor chrome.webRequest listeners.
amovar18 Feb 13, 2024
adcf792
Refactor Chrome debugger listener.
amovar18 Feb 13, 2024
b82734a
Add early return to CDP listener.
amovar18 Feb 13, 2024
1d4669a
Change message type to constants.
amovar18 Feb 16, 2024
1882bbb
Fix tsc error.
amovar18 Feb 16, 2024
a736f59
Prettify
amovar18 Feb 16, 2024
868cefa
Prettify and use Yoda conditions.
amovar18 Feb 16, 2024
874d1fc
Move frame getter to separate utility function.
amovar18 Feb 19, 2024
8118527
Remove comments.
amovar18 Feb 19, 2024
13be2d4
Add no tabId condition to the messagePassingListener.
amovar18 Feb 19, 2024
da8487d
Remove tabId as a state.
amovar18 Feb 19, 2024
4a80183
Organise cookies section.
amovar18 Feb 19, 2024
6a0f4e3
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Feb 21, 2024
af49eaf
Change name of folders in stateProviders or popup.
amovar18 Feb 21, 2024
484c6f8
Add new settings provider to popup.
amovar18 Feb 21, 2024
fb78e3b
Replace references for context-selectors.
amovar18 Feb 21, 2024
0edbd3d
Replace cookie provider:
amovar18 Feb 21, 2024
2b7bb51
Replace settings provider:
amovar18 Feb 21, 2024
7f97a5e
Replace references for cookie, settings context selector.
amovar18 Feb 21, 2024
d9fb87d
Fix tests.
amovar18 Feb 21, 2024
84d782f
Fix failing test and fix other references.
amovar18 Feb 21, 2024
eace9c8
Fix 2 step reload action.
amovar18 Feb 22, 2024
59bc53c
Fix console errors and fix analyse this tab.
amovar18 Feb 22, 2024
6ecbe7b
Move hardcoded string to constant.
amovar18 Feb 23, 2024
fff7609
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Feb 26, 2024
b2a8e26
Fix references after develop merge.
amovar18 Feb 26, 2024
bbb348f
Fix derivation of the domain if domain not specified in the set-cooki…
amovar18 Feb 26, 2024
4ee3a41
Fix add await to chrome.storage.session.set
amovar18 Feb 29, 2024
8cf3cca
expose settingsChanged directly.
amovar18 Feb 29, 2024
d497a6c
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Mar 1, 2024
d489f12
Fix cookie tests.
amovar18 Mar 1, 2024
d6655c7
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Mar 1, 2024
7f7c2c4
Fix failing tests.
amovar18 Mar 1, 2024
94c41f4
Fix import.
amovar18 Mar 7, 2024
b0f80b8
Fix typo.
amovar18 Mar 7, 2024
f3677ba
Fix condition and make it more readable.
amovar18 Mar 7, 2024
ab76d77
Fix correct section for cookies.
amovar18 Mar 7, 2024
0a33459
Prettify cookie landing for cli.
amovar18 Mar 7, 2024
c374d48
Fix blockedCookies section.
amovar18 Mar 8, 2024
b6c1c6d
Fix blockedCookies section.
amovar18 Mar 8, 2024
464c3b0
Fix data-testid.
amovar18 Mar 8, 2024
a022c66
Fix cookie section info icon.
amovar18 Mar 8, 2024
2368355
Fix the problem of inconsistent state of settings in popup and devtools.
amovar18 Mar 8, 2024
67edc70
Revert settingsChanged setter.
amovar18 Mar 11, 2024
71f45ce
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Mar 12, 2024
fa866ed
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Mar 21, 2024
1f58d83
Make allowedListProvider uniform.
amovar18 Mar 21, 2024
54323be
Move type name to constant.
amovar18 Mar 21, 2024
d50ee55
Keep only one isValidUrl.
amovar18 Mar 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* External dependencies
*/
import React from 'react';
import {
CookiesLandingContainer,
CookiesMatrix,
MessageBox,
prepareCookieStatsComponents,
prepareCookiesCount,
type DataMapping,
} from '@ps-analysis-tool/design-system';
import type { TabCookies, TabFrames } from '@ps-analysis-tool/common';

interface BlockedCookiesSectionProps {
tabCookies: TabCookies | null;
affectedCookies: TabCookies | null;
tabFrames: TabFrames | null;
}
const BlockedCookiesSection = ({
tabCookies,
affectedCookies,
tabFrames,
}: BlockedCookiesSectionProps) => {
const cookiesStats = prepareCookiesCount(tabCookies);

const cookiesStatsComponents = prepareCookieStatsComponents(cookiesStats);

const cookieBlockedDataMapping: DataMapping[] = [
{
title: 'Blocked cookies',
count: cookiesStats.blockedCookies.total,
data: cookiesStatsComponents.blocked,
},
];

const blockedCookieStats = prepareCookiesCount(affectedCookies);
const blockedCookiesStatsComponents =
prepareCookieStatsComponents(blockedCookieStats);

return (
<CookiesLandingContainer
dataMapping={cookieBlockedDataMapping}
testId="blocked-cookies-insights"
>
{!cookiesStats ||
(cookiesStats?.firstParty.total === 0 &&
cookiesStats?.thirdParty.total === 0 && (
<MessageBox
headerText="No cookies found on this page"
bodyText="Please try reloading the page"
/>
))}
<CookiesMatrix
tabCookies={affectedCookies}
componentData={cookiesStatsComponents.blockedCookiesLegend}
tabFrames={tabFrames}
description=""
infoIconTitle="Cookies that have been blocked by the browser.(The total count might not be same as cumulative reason count because cookie might be blocked due to more than 1 reason)."
showInfoIcon={true}
showHorizontalMatrix={false}
allowExpand={true}
/>
<CookiesMatrix
tabCookies={affectedCookies}
componentData={blockedCookiesStatsComponents.legend}
tabFrames={tabFrames}
description=""
showInfoIcon={false}
showHorizontalMatrix={false}
allowExpand={false}
/>
</CookiesLandingContainer>
);
};
export default BlockedCookiesSection;
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* External dependencies
*/
import React from 'react';
import {
CookiesLandingContainer,
CookiesMatrix,
MessageBox,
prepareCookieDataMapping,
prepareCookieStatsComponents,
prepareCookiesCount,
} from '@ps-analysis-tool/design-system';
import type { TabCookies, TabFrames } from '@ps-analysis-tool/common';
/**
* Internal dependencies
*/

interface CookiesSectionProps {
tabCookies: TabCookies | null;
tabFrames: TabFrames | null;
}
const CookiesSection = ({ tabCookies, tabFrames }: CookiesSectionProps) => {
const cookieStats = prepareCookiesCount(tabCookies);
const cookiesStatsComponents = prepareCookieStatsComponents(cookieStats);
const cookieClassificationDataMapping = prepareCookieDataMapping(
cookieStats,
cookiesStatsComponents
);

return (
<CookiesLandingContainer
dataMapping={cookieClassificationDataMapping}
testId="cookies-insights"
>
{!cookieStats ||
(cookieStats?.firstParty.total === 0 &&
cookieStats?.thirdParty.total === 0 && (
<MessageBox
headerText="No cookies found on this page"
bodyText="Please try reloading the page"
/>
))}
<CookiesMatrix
tabCookies={tabCookies}
componentData={cookiesStatsComponents.legend}
tabFrames={tabFrames}
description=""
showInfoIcon={true}
showHorizontalMatrix={false}
allowExpand={true}
/>
</CookiesLandingContainer>
);
};
export default CookiesSection;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { default as CookiesSection } from './cookiesSection';
export { default as BlockedCookiesSection } from './blockedCookiesSection';
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@
* External dependencies.
*/
import React from 'react';
import {
Button,
CookiesLanding,
CookiesMatrix,
prepareCookiesCount,
prepareCookieStatsComponents,
} from '@ps-analysis-tool/design-system';
import { Button, CookiesLanding } from '@ps-analysis-tool/design-system';
import type { TabCookies, TabFrames } from '@ps-analysis-tool/common';
/**
* Internal dependencies
*/
import { CookiesSection, BlockedCookiesSection } from './cookieLanding';

interface CookiesLandingContainerProps {
tabFrames: TabFrames;
Expand All @@ -51,33 +49,13 @@ const CookiesLandingContainer = ({
/>
</div>
)}
<CookiesLanding
tabFrames={tabFrames}
tabCookies={tabCookies}
showInfoIcon={false}
showBlockedInfoIcon={true}
associatedCookiesCount={Object.values(tabFrames).length}
showMessageBoxBody={false}
showBlockedCookiesSection
cookieClassificationTitle="Categories"
>
<div className="flex flex-col">
<div className="pt-4">
<CookiesMatrix
tabCookies={affectedCookies}
componentData={
prepareCookieStatsComponents(
prepareCookiesCount(affectedCookies)
).legend
}
tabFrames={tabFrames}
description=""
showInfoIcon={false}
showHorizontalMatrix={false}
allowExpand={false}
/>
</div>
</div>
<CookiesLanding>
amovar18 marked this conversation as resolved.
Show resolved Hide resolved
<CookiesSection tabCookies={tabCookies} tabFrames={tabFrames} />
<BlockedCookiesSection
tabCookies={tabCookies}
affectedCookies={affectedCookies}
tabFrames={tabFrames}
/>
</CookiesLanding>
</>
);
Expand Down
16 changes: 9 additions & 7 deletions packages/common/src/utils/parseRequestWillBeSentExtraInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,32 @@ import isFirstParty from './isFirstParty';

/**
* Parses Network.requestWillBeSentExtraInfo to get extra information about a cookie.
* @param {object} request Request to be parsed to get extra information about a cookie.
* @param {object} associatedCookies Cookies associated with the request being parsed.
* @param {object} cookieDB Cookie database to find analytics from.
* @param {object} requestMap An object for requestId to url.
* @param {string} tabUrl - The top-level URL (URL in the tab's address bar).
* @param {string} requestId - The requestId of the request being processed
* @returns {object} parsed cookies.
*/
export default function parseRequestWillBeSentExtraInfo(
request: Protocol.Network.RequestWillBeSentExtraInfoEvent,
associatedCookies: Protocol.Network.RequestWillBeSentExtraInfoEvent['associatedCookies'],
cookieDB: CookieDatabase,
requestMap: { [requestId: string]: string },
tabUrl: string
tabUrl: string,
requestId: string
) {
const cookies: CookieData[] = [];

request.associatedCookies.forEach(({ blockedReasons, cookie }) => {
associatedCookies.forEach(({ blockedReasons, cookie }) => {
const effectiveExpirationDate = calculateEffectiveExpiryDate(
cookie.expires
);

let domain,
url = '';

if (requestMap && requestMap[request?.requestId]) {
url = requestMap[request?.requestId] ?? '';
if (requestMap && requestMap[requestId]) {
url = requestMap[requestId] ?? '';
}

if (cookie?.domain) {
Expand All @@ -75,7 +77,7 @@ export default function parseRequestWillBeSentExtraInfo(
requestEvents: [
{
type: REQUEST_EVENT.CDP_REQUEST_WILL_BE_SENT_EXTRA_INFO,
requestId: request.requestId,
requestId,
url: url,
blocked: blockedReasons.length !== 0,
timeStamp: Date.now(),
Expand Down
25 changes: 15 additions & 10 deletions packages/common/src/utils/parseResponseReceivedExtraInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,31 @@ import isFirstParty from './isFirstParty';

/**
* Parse Network.responseReceivedExtraInfo for extra information about a cookie.
* @param {object} response Response to be parsed to get extra information about a cookie.
* @param {object} headers Headers of resonse to be parsed to get extra information about a cookie.
* @param {object} blockedCookies Blocked Cookies associated with the response being parsed.
* @param {string|undefined} cookiePartitionKey Partittion key for the response.
* @param {object} requestMap An object for requestId to url.
* @param {string} tabUrl - The top-level URL (URL in the tab's address bar).
* @param {object} cookieDB Cookie database to find analytics from.
* @param {string} requestId - The requestId of the request being processed
* @returns {object} parsed cookies.
*/
export default function parseResponseReceivedExtraInfo(
response: Protocol.Network.ResponseReceivedExtraInfoEvent,
headers: Protocol.Network.ResponseReceivedExtraInfoEvent['headers'],
blockedCookies: Protocol.Network.ResponseReceivedExtraInfoEvent['blockedCookies'],
cookiePartitionKey: Protocol.Network.ResponseReceivedExtraInfoEvent['cookiePartitionKey'],
requestMap: { [requestId: string]: string },
tabUrl: string,
cookieDB: CookieDatabase
cookieDB: CookieDatabase,
requestId: string
) {
const cookies: CookieData[] = [];
const responseToParse =
response.headers['set-cookie'] ?? response.headers['Set-Cookie'];
const responseToParse = headers['set-cookie'] ?? headers['Set-Cookie'];

responseToParse?.split('\n').forEach((headerLine: string) => {
let parsedCookie: CookieData['parsedCookie'] = parse(headerLine);

const blockedCookie = response.blockedCookies.find((c) => {
const blockedCookie = blockedCookies.find((c) => {
if (c.cookie) {
return c.cookie?.name === parsedCookie.name;
} else {
Expand All @@ -68,15 +73,15 @@ export default function parseResponseReceivedExtraInfo(
if (headerLine.toLowerCase().includes('partitioned')) {
parsedCookie = {
...parsedCookie,
partitionKey: response?.cookiePartitionKey,
partitionKey: cookiePartitionKey,
};
}

let domain,
url = '';

if (requestMap && requestMap[response?.requestId]) {
url = requestMap[response?.requestId] ?? '';
if (requestMap && requestMap[requestId]) {
url = requestMap[requestId] ?? '';
}

if (parsedCookie?.domain) {
Expand All @@ -99,7 +104,7 @@ export default function parseResponseReceivedExtraInfo(
responseEvents: [
{
type: RESPONSE_EVENT.CDP_RESPONSE_RECEIVED_EXTRA_INFO,
requestId: response.requestId,
requestId,
url: url,
blocked: blockedCookie ? true : false,
timeStamp: Date.now(),
Expand Down
Loading
Loading