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

Fix: Zero cookie issue. #671

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 0 additions & 28 deletions packages/extension/src/serviceWorker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,6 @@ chrome.runtime.onStartup.addListener(async () => {
syncCookieStore = new SynchnorousCookieStore();
}

// Sync cookie data between popup and Devtool.
// @todo Only send the data from the active tab and the differences.
setInterval(() => {
const data = syncCookieStore?.tabsData ?? {};

if (Object.keys(data).length === 0) {
return;
}

Object.keys(data).forEach((key) => {
syncCookieStore?.sendUpdatedDataToPopupAndDevTools(Number(key));
});
}, 1200);

if (Object.keys(storage).includes('allowedNumberOfTabs')) {
tabMode = storage.allowedNumberOfTabs;
}
Expand Down Expand Up @@ -302,20 +288,6 @@ chrome.runtime.onInstalled.addListener(async (details) => {
syncCookieStore = new SynchnorousCookieStore();
syncCookieStore?.clear();

// @see https://developer.chrome.com/blog/longer-esw-lifetimes#whats_changed
// Doing this to keep the service worker alive so that we dont loose any data and introduce any bug.

// @todo Send tab data of the active tab only, also if sending only the difference would make it any faster.
setInterval(() => {
if (Object.keys(syncCookieStore?.tabsData ?? {}).length === 0) {
return;
}

Object.keys(syncCookieStore?.tabsData ?? {}).forEach((key) => {
syncCookieStore?.sendUpdatedDataToPopupAndDevTools(Number(key));
});
}, 1200);

if (details.reason === 'install') {
await chrome.storage.sync.clear();
await chrome.storage.sync.set({
Expand Down
23 changes: 20 additions & 3 deletions packages/extension/src/store/synchnorousCookieStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ class SynchnorousCookieStore {
};
} = {};

constructor() {
// Sync cookie data between popup and Devtool.
// @todo Only send the data from the active tab and the differences.
setInterval(() => {
const data = this?.tabsData ?? {};

if (Object.keys(data).length === 0) {
return;
}

Object.keys(data).forEach((key) => {
this?.sendUpdatedDataToPopupAndDevTools(Number(key));
});
}, 1200);
}

/**
* Update cookie store.
* @param {number} tabId Tab id.
Expand Down Expand Up @@ -351,9 +367,10 @@ class SynchnorousCookieStore {

try {
if (
this.tabs[tabId].devToolsOpenState ||
(this.tabs[tabId].popupOpenState &&
(overrideForInitialSync || this.tabs[tabId].newUpdates > 0))
((this.tabs[tabId].devToolsOpenState ||
this.tabs[tabId].popupOpenState) &&
this.tabs[tabId].newUpdates > 0) ||
overrideForInitialSync
) {
sentMessageAnyWhere = true;

Expand Down
Loading