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

Feature: Complete migration to CDP #539

Merged
merged 82 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
a6cde09
Shift service worker to use CDP completely.
amovar18 Feb 27, 2024
dbcc23c
Fix JS cookies for CDP.
amovar18 Feb 27, 2024
0217951
Fix JS cookies.
amovar18 Feb 27, 2024
5067aff
Remove optional chaining for frame id
amovar18 Feb 27, 2024
1a692e9
Fix condition for frame filtering.
amovar18 Feb 28, 2024
9cea675
Fix frameId association.
amovar18 Feb 29, 2024
32e8ba8
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Mar 1, 2024
9cf229b
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Mar 1, 2024
b3715fb
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Mar 26, 2024
3164869
Fix deletion of data at correct event.
amovar18 Mar 26, 2024
ab77f08
Get all cookies for current tab via CDP.
amovar18 Mar 27, 2024
9905de5
Add multitab support.
amovar18 Mar 28, 2024
1b5aae0
Add tab data when extension is updated.
amovar18 Mar 28, 2024
17b162e
Make multitab work
amovar18 Mar 29, 2024
684b8a6
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Mar 29, 2024
1cfc4ad
Fix multi-tab analysis methodology for CDP.
amovar18 Mar 29, 2024
dda7c25
Keep previous frame.
amovar18 Mar 29, 2024
c66d6e6
Fix the inconsistency in frame and cookie association.
amovar18 Apr 1, 2024
f9aa67b
Fix removal of frameIdUrlSet.
amovar18 Apr 1, 2024
5e6f804
Add some conditions.
amovar18 Apr 4, 2024
514d4f3
Use loaderid to load other cookies.
amovar18 Apr 8, 2024
3cbda3d
Fix frame mapping of cookies.
amovar18 Apr 8, 2024
9b6d72e
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Apr 8, 2024
ac5282d
Test fix.
amovar18 Apr 8, 2024
cec0c1d
revert test fix
amovar18 Apr 8, 2024
e060dfe
Destructure code to make it pretty.
amovar18 Apr 9, 2024
0ecfa13
Enable CDP by default
amovar18 Apr 9, 2024
341cb5d
Refactor code to make it pretty.
amovar18 Apr 9, 2024
0a900a7
Fix failing tests.
amovar18 Apr 9, 2024
ca5f652
Revert some changes
amovar18 Apr 9, 2024
84b45a4
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Apr 10, 2024
7d3515b
Revert using loader id.
amovar18 Apr 10, 2024
3b92595
More precise mapping of data.
amovar18 Apr 10, 2024
9ed2c5f
Collect resource urls.
amovar18 Apr 11, 2024
2e5c2a3
collect frame resource urls.
amovar18 Apr 11, 2024
7a69eaa
Send cookies from resources.
amovar18 Apr 11, 2024
c15d4a3
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Apr 11, 2024
adcdc39
Reinsert adding extra frame urls from service worker.
amovar18 Apr 11, 2024
73d33ac
Add comments explaining each thing in the chrome.debugger.
amovar18 Apr 11, 2024
a718b65
Fix some redundant issues remove auditsIssuesStore.
amovar18 Apr 11, 2024
fd04c4a
Fix errors thrown on extension page.
amovar18 Apr 12, 2024
be8c6c2
Add proper frameIds to map the cookies to frames better.
amovar18 Apr 12, 2024
eb86fd8
- Remove parentChildFrameAssociation from service worker.
amovar18 Apr 12, 2024
8b83745
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Apr 18, 2024
7481b67
Fix some variable additions.
amovar18 Apr 18, 2024
a923e3e
Move all listeners to separate files.
amovar18 Apr 18, 2024
b2aa6a4
Split serviceworker into more listeners.
amovar18 Apr 18, 2024
b01ed48
Fix bug.
amovar18 Apr 18, 2024
64dfbaf
Fix failing tests.
amovar18 Apr 18, 2024
6463e78
Reintroduce webRequest API.
amovar18 Apr 22, 2024
324e914
Fix cli tsc problems.
amovar18 Apr 22, 2024
233bea0
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Apr 22, 2024
f603733
create separate functions for listeners.
amovar18 Apr 23, 2024
ebd8bfb
Bug fix frame id association.
amovar18 Apr 23, 2024
aad04fc
Fix frame management after extension update.
amovar18 Apr 25, 2024
9f19a93
Add service worker test.
amovar18 Apr 26, 2024
076148a
Revert jest config.
amovar18 Apr 26, 2024
dd5d9be
Revert parsing method.
amovar18 Apr 29, 2024
f019676
Remove use of mainFrameId.
amovar18 Apr 29, 2024
1938f4d
Rearrange functions in sync cookie store.
amovar18 Apr 29, 2024
7009cac
Refactor code.
amovar18 Apr 29, 2024
a670de8
update frameId logic
amovar18 Apr 29, 2024
b8fa697
Revert logic of frame addition.
amovar18 Apr 29, 2024
579cd23
Refactor code and fix js cookie.
amovar18 Apr 30, 2024
34439bc
Move cookieDB to synchnorous cookie store.
amovar18 Apr 30, 2024
e71ff22
Fix arguments in getAndParseNetworkCookies
amovar18 Apr 30, 2024
50d1b1f
Fix failing tests.
amovar18 Apr 30, 2024
7f23040
Make non cdp environement work.
amovar18 May 1, 2024
63f23a6
Fix failing tests.
amovar18 May 1, 2024
efe88e0
Detach debugger from targets when cdp is switched off
amovar18 May 1, 2024
64b6be7
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 May 1, 2024
1bcacbe
Revert setting cdp as default true.
amovar18 May 1, 2024
f6edb0b
Remove exclude from exclusion reason.
amovar18 May 1, 2024
390fb6d
Delete cdpURLMapping.
amovar18 May 1, 2024
b0184f1
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 May 17, 2024
9576087
Add jsdoc.
amovar18 May 22, 2024
eb22bc7
Use optional chaining.
amovar18 May 22, 2024
24da1cc
Fix jsdoc comment in index.ts
amovar18 May 22, 2024
1d2d359
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
mohdsayed May 28, 2024
0ecb591
Small refactoring
mohdsayed May 28, 2024
51938c0
Assign target in the chrome.debugger event.
amovar18 May 28, 2024
fa3804d
Add comments.
amovar18 May 29, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Get all cookies for current tab via CDP.
  • Loading branch information
amovar18 committed Mar 27, 2024
commit ab77f08c995ba405fbeba1c34e1751eb6968ef5a
32 changes: 32 additions & 0 deletions packages/extension/src/serviceWorker/attachCDP.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.
*/
/**
* This function will attach the debugger to the given target.
* @param {{ [key: string]: number | string }} target The target where debugger needs to be attached.
*/
export default async function attachCDP(target: {
[key: string]: number | string;
}) {
await chrome.debugger.attach(target, '1.3');
await chrome.debugger.sendCommand(target, 'Target.setAutoAttach', {
autoAttach: false,
flatten: true,
waitForDebuggerOnStart: true,
});
await chrome.debugger.sendCommand(target, 'Network.enable');
await chrome.debugger.sendCommand(target, 'Audits.enable');
await chrome.debugger.sendCommand(target, 'Page.enable');
}
39 changes: 24 additions & 15 deletions packages/extension/src/serviceWorker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import { getTab } from '../utils/getTab';
import getQueryParams from '../utils/getQueryParams';
import reloadCurrentTab from '../utils/reloadCurrentTab';
import createCookieFromAuditsIssue from '../utils/createCookieFromAuditsIssue';
import attachCDP from './attachCDP';
import { getCurrentTabId } from '../utils/getCurrentTabId';

let cookieDB: CookieDatabase | null = null;
let syncCookieStore: SynchnorousCookieStore | undefined;
Expand Down Expand Up @@ -199,11 +201,7 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {

try {
if (globalIsUsingCDP) {
await chrome.debugger.attach({ tabId }, '1.3');
await chrome.debugger.sendCommand({ tabId }, 'Network.enable');
await chrome.debugger.sendCommand({ tabId }, 'Audits.enable');
await chrome.debugger.sendCommand({ tabId }, 'Page.enable');
await chrome.debugger.sendCommand({ tabId }, 'DOM.enable');
await attachCDP({ tabId });
} else {
await chrome.debugger.detach({ tabId });
}
Expand Down Expand Up @@ -296,15 +294,29 @@ chrome.debugger.onEvent.addListener(async (source, method, params) => {
return;
}

let tabId = '';
let tabId = await getCurrentTabId();
try {
const targets = await chrome.debugger.getTargets();
await Promise.all(
targets.map(async ({ id }) => {
await chrome.debugger.attach({ targetId: id }, '1.3');
await chrome.debugger.sendCommand({ targetId: id }, 'Network.enable');
await chrome.debugger.sendCommand({ targetId: id }, 'Audits.enable');
})
);
} catch (error) {
//Fail silently since it gives only one kind of error. Debugger already attached to tabId.
}

if (!source?.tabId) {
return;
if (source?.tabId) {
tabId = source?.tabId?.toString();
}

const url = syncCookieStore?.getTabUrl(source?.tabId);
if (!tabId) {
return;
}

tabId = source?.tabId?.toString();
const url = syncCookieStore?.getTabUrl(Number(tabId));

if (tabMode && tabMode !== 'unlimited' && tabToRead !== tabId) {
return;
Expand Down Expand Up @@ -359,10 +371,7 @@ chrome.debugger.onEvent.addListener(async (source, method, params) => {
return;
}

if (
requestIdToCDPURLMapping[tabId][requestParams?.requestId].frameId &&
requestIdToCDPURLMapping[tabId][requestParams?.requestId].url
) {
if (requestIdToCDPURLMapping[tabId][requestParams?.requestId]) {
const cookies: CookieData[] = parseRequestWillBeSentExtraInfo(
requestParams,
cookieDB ?? {},
Expand Down Expand Up @@ -411,7 +420,6 @@ chrome.debugger.onEvent.addListener(async (source, method, params) => {
cookieDB ?? {},
requestIdToCDPURLMapping[tabId][request.requestId]?.frameId
);

syncCookieStore?.update(Number(tabId), cookies);

delete unParsedRequestHeaders[tabId][request.requestId];
Expand All @@ -429,6 +437,7 @@ chrome.debugger.onEvent.addListener(async (source, method, params) => {
if (cookieObjectToUpdate) {
syncCookieStore?.update(Number(tabId), [cookieObjectToUpdate]);
}

delete auditsIssueForTab[tabId][request.requestId];
}

Expand Down
33 changes: 33 additions & 0 deletions packages/extension/src/store/synchnorousCookieStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class SynchnorousCookieStore {
devToolsOpenState: boolean;
popupOpenState: boolean;
newUpdates: number;
frameIdSet: {
[frameUrl: string]: string[];
};
};
} = {};

Expand Down Expand Up @@ -182,6 +185,35 @@ class SynchnorousCookieStore {
return this.tabs[tabId].url;
}

/**
* Gets the frameIDSet for the given tab id if tab exists.
* @param {number} tabId Tab id.
* @returns {string | null} The url of the tab if exists else null.
*/
getFrameIDSet(tabId: number): { [frameUrl: string]: string[] } | null {
if (!this.tabs[tabId]) {
return null;
}

return this.tabs[tabId].frameIdSet;
}

/**
* Update FrameId set for a given url for a given tab.
* @param {number} tabId The url whose url needs to be update.
* @param {string} frameUrl The URL where frameId needs to be added.
* @param {string} frameIdToAdd The new frameId to be added.
*/
updateFrameIdSet(tabId: number, frameUrl: string, frameIdToAdd: string) {
if (!this.tabs[tabId]) {
return;
} else {
this.tabs[tabId].frameIdSet[frameUrl] = [
...new Set([...this.tabs[tabId].frameIdSet[frameUrl], frameIdToAdd]),
];
}
}

/**
* Update tab url for given tab
* @param {number} tabId The url whose url needs to be update.
Expand Down Expand Up @@ -304,6 +336,7 @@ class SynchnorousCookieStore {
devToolsOpenState: false,
popupOpenState: false,
newUpdates: 0,
frameIdSet: {},
};
}

Expand Down
Loading