Skip to content
Open
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
27 changes: 27 additions & 0 deletions interface/popup/cookieHandlerPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,39 @@ export class CookieHandlerPopup extends GenericCookieHandler {
api.tabs.onActivated.addListener(this.onTabActivated);
if (!this.browserDetector.isSafari()) {
api.cookies.onChanged.addListener(this.onCookiesChanged);
} else {
// Safari requires a temporary cookie to be added before retrieving all cookies
this.addTemporarySafariCookie();
}

this.emit('ready');
this.isReady = true;
};

/**
* Adds a temporary session-level cookie for Safari to ensure proper cookie retrieval.
* The cookie is named with a 'z' prefix to sort it to the end of the list.
*/
addTemporarySafariCookie = () => {
try {
const tempCookie = {
url: this.currentTab.url,
name: 'zcookie-editor',
value:
'Temporary cookie added to ensure Cookie Editor works correctly in Safari, please ignore it',
path: '/',
};
this.browserDetector
.getApi()
.cookies.set(tempCookie)
.catch(error => {
console.warn('Failed to set temporary Safari cookie:', error);
});
} catch (error) {
console.warn('Error adding temporary Safari cookie:', error);
}
};
Comment on lines +55 to +73

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Improvement Opportunities:

  1. Guard against null/undefined currentTab: During initialization, this.currentTab might not be fully populated yet. Accessing this.currentTab.url directly can throw a TypeError. Adding an optional chaining guard (this.currentTab?.url) prevents this.
  2. Reuse this.saveCookie: Instead of calling cookies.set directly, reuse the inherited this.saveCookie method. This automatically:
    • Resolves the correct storeId (e.g., for container tabs or private windows) via prepareCookie.
    • Handles Promise vs. callback compatibility via supportsPromises() check already implemented in the base class.
  3. Reduce Cookie Value Size: The current value is a 91-character string. Since cookies are sent to the server with every subsequent HTTP request to that domain, this adds unnecessary header overhead. Reducing it to a minimal value like '1' avoids this bandwidth bloat.
Suggested change
addTemporarySafariCookie = () => {
try {
const tempCookie = {
url: this.currentTab.url,
name: 'zcookie-editor',
value:
'Temporary cookie added to ensure Cookie Editor works correctly in Safari, please ignore it',
path: '/',
};
this.browserDetector
.getApi()
.cookies.set(tempCookie)
.catch(error => {
console.warn('Failed to set temporary Safari cookie:', error);
});
} catch (error) {
console.warn('Error adding temporary Safari cookie:', error);
}
};
addTemporarySafariCookie = () => {
if (!this.currentTab?.url) {
return;
}
try {
const tempCookie = {
name: 'zcookie-editor',
value: '1',
path: '/',
};
this.saveCookie(tempCookie, this.currentTab.url, error => {
if (error) {
console.warn('Failed to set temporary Safari cookie:', error);
}
});
} catch (error) {
console.warn('Error adding temporary Safari cookie:', error);
}
};


/**
* Handles events that is triggered when a cookie changes.
* @param {object} changeInfo An object containing details of the change that
Expand Down