Skip to content

fix: Add temporary cookie for Safari browser cookie retrieval#357

Open
GundamDr1ver wants to merge 2 commits into
Moustachauve:masterfrom
GundamDr1ver:master
Open

fix: Add temporary cookie for Safari browser cookie retrieval#357
GundamDr1ver wants to merge 2 commits into
Moustachauve:masterfrom
GundamDr1ver:master

Conversation

@GundamDr1ver

Copy link
Copy Markdown

fix: Add temporary cookie for Safari browser cookie retrieval

Changes:

  • Added addTemporarySafariCookie() method in CookieHandlerPopup class
  • The temporary cookie is named 'zcookie-editor' with a 'z' prefix to sort it to the end of the cookie list, preventing it from interfering with other cookies
  • The cookie value is a descriptive message indicating it's a temporary cookie for Safari compatibility
  • The method is called during initialization only for Safari browser
  • Errors during cookie creation are handled gracefully with console warnings

This workaround addresses a Safari browser limitation(or Bug?) ,where the cookies API fails to return all cookies on the first request without a preceding manual cookie operation.

Co-authored-by: Copilot

WangPeng and others added 2 commits June 9, 2026 12:33
This commit adds a temporary session-level cookie when Cookie Editor initializes in Safari browser to resolve the issue where Safari cannot correctly retrieve all cookies without a manual cookie addition first.

Changes:
- Added addTemporarySafariCookie() method in CookieHandlerPopup class
- The temporary cookie is named 'zcookie-editor' with a 'z' prefix to sort it to the end of the cookie list, preventing it from interfering with other cookies
- The cookie value is a descriptive message indicating it's a temporary cookie for Safari compatibility
- The method is called during initialization only for Safari browser
- Errors during cookie creation are handled gracefully with console warnings

This workaround addresses a Safari browser limitation where the cookies API fails to return all cookies on the first request without a preceding manual cookie operation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a workaround for Safari by adding a temporary session-level cookie (zcookie-editor) during initialization to ensure proper cookie retrieval. The review feedback suggests several key improvements: guarding against a potentially undefined currentTab using optional chaining, reusing the inherited this.saveCookie method to handle store IDs and API compatibility, and reducing the cookie value size to minimize HTTP header overhead.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +55 to +73
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);
}
};

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);
}
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant