fix: Add temporary cookie for Safari browser cookie retrieval#357
fix: Add temporary cookie for Safari browser cookie retrieval#357GundamDr1ver wants to merge 2 commits into
Conversation
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>
There was a problem hiding this comment.
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.
| 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); | ||
| } | ||
| }; |
There was a problem hiding this comment.
Improvement Opportunities:
- Guard against null/undefined
currentTab: During initialization,this.currentTabmight not be fully populated yet. Accessingthis.currentTab.urldirectly can throw aTypeError. Adding an optional chaining guard (this.currentTab?.url) prevents this. - Reuse
this.saveCookie: Instead of callingcookies.setdirectly, reuse the inheritedthis.saveCookiemethod. This automatically:- Resolves the correct
storeId(e.g., for container tabs or private windows) viaprepareCookie. - Handles Promise vs. callback compatibility via
supportsPromises()check already implemented in the base class.
- Resolves the correct
- 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.
| 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); | |
| } | |
| }; |
fix: Add temporary cookie for Safari browser cookie retrieval
Changes:
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