Fixing Wails Cookie Issues on macOS: A Debug and Workaround Guide
Wails is a project that allows you to build desktop applications using Go and web technologies. Recently, while developing the AsBot client on macOS, everything worked fine in development mode, but after compiling and packaging, cookies stopped working.
I had already packaged the Windows client before this, and no such issue existed there. It appears to be a bug. I have reported the issue to the author and am waiting for further confirmation.

Debugging Wails
According to the official Wails documentation on build commands, you can add the -debug parameter during packaging to retain debug information in the application. This allows the use of developer tools within the application window.
The complete build command is:
wails build -debug
This enables you to continue using browser debugging mode to analyze and troubleshoot issues in the packaged build (note: adding the -debug parameter is not recommended for production).
Reproducing the Issue
The project uses the vue3-cookies library. Initially, I suspected this library was the problem, so I switched to using native JavaScript methods:
document.cookie = "username=John Doe; expires=" + new Date(new Date().getTime() + (24 * 60 * 60 * 1000)).toUTCString() + "; path=/";
The following issue still occurred (specific to macOS):
wails dev(development mode): Everything works normally, and cookies are set successfully.wails build(compiled package): Cookies cannot be set or stored, and no errors are thrown.
Wails Environment and Version Information
The environment details where this bug occurred are as follows:
Wails CLI v2.4.1
Scanning system - Please wait (this may take a long time)...Done.
# System
OS | MacOS
Version | 13.3.1
ID | 22E261
Go Version | go1.20.3
Platform | darwin
Architecture | amd64
# Wails
Version | v2.4.1
# Dependencies
Dependency | Package Name | Status | Version
Xcode command line tools | N/A | Installed | 2397
npm | N/A | Installed | 9.5.0
*Xcode | N/A | Available |
*upx | N/A | Installed | upx 4.0.2
*nsis | N/A | Available |
* - Optional Dependency
Issue Reporting
I raised an issue on the author's project, see: https://github.com/wailsapp/wails/issues/2590
The author has not yet provided a clear response, and I am still unsure of the exact cause.
Workaround and Solution
I temporarily abandoned the cookie approach and switched to using the browser's built-in localStorage property. Compared to cookies, localStorage is simpler to use but less flexible and secure. For example, localStorage cannot set expiration times or support HttpOnly flags like cookies.
For reference on using
localStorage, see: Window localStorage property
Conclusion
Overall, if you are familiar with Golang and frontend development, Wails is a great tool for building desktop applications. However, you may encounter issues like the inability to set cookies on macOS. In such cases, switching to localStorage can be an effective solution. I hope this article helps Wails developers.