Browser-Specific Details ๐ โ
Understanding how get-cookie works with different browsers and platforms.
Platform Support Matrix โ
Browser | macOS | Linux | Windows |
---|---|---|---|
Chrome | โ | โ | โ |
Firefox | โ | โ | โ |
Safari | โ | โ | โ |
โ Full Support | โ Not Supported
Chrome (macOS Only) โ
Storage Location โ
Chrome stores cookies in an SQLite database:
macOS:
~/Library/Application Support/Google/Chrome/Default/Cookies
Security Model โ
- Cookies are encrypted using Chrome Safe Storage
- Encryption key stored in macOS Keychain
- Each profile has a unique encryption key
- Requires Keychain access permission
- Chrome must be installed and configured
- Profile must be unlocked and accessible
Profile Support โ
- Multiple profiles supported
- Default profile: "Default"
- Profile list in
Local State
file - Each profile requires:
- Separate cookie database
- Unique encryption key
- Independent Keychain access
Limitations โ
- macOS only (no Linux/Windows support)
- Requires Keychain access
- Chrome must be installed
- Session cookies not accessible
- Incognito mode not supported
- Profile must be unlocked
- Fails silently if encryption key unavailable
Firefox (macOS & Linux) โ
Storage Location โ
Firefox uses SQLite for cookie storage:
macOS:
~/Library/Application Support/Firefox/Profiles/<profile>/cookies.sqlite
Linux:
~/.mozilla/firefox/<profile>/cookies.sqlite
Security Model โ
- SQLite database with no additional encryption
- File system permissions-based security
- Database locking mechanism for concurrent access
- Platform-specific profile paths
- Direct database access required
- Handles database busy states gracefully
Profile Support โ
- Multiple profiles supported
- Profile list in
profiles.ini
- Each profile is separate directory
- Custom profile paths supported
- Cross-platform profile handling
- Automatic profile discovery
Limitations โ
- Database must be unlocked
- Firefox must be installed
- Profile directory must be readable
- Some cookies may be protected
- Database may be temporarily locked
- Fails gracefully if database is busy
Safari (macOS Only) โ
Storage Location โ
Safari uses a binary cookie format:
~/Library/Containers/com.apple.Safari/Data/Library/Cookies/Cookies.binarycookies
Security Model โ
- Custom binary format
- Container-based security
- System-level permissions
- No additional encryption
- macOS container isolation
- Requires container access permission
Profile Support โ
- Single profile only
- System-wide cookie store
- No multi-profile support
- All cookies in one file
- Shared between instances
- No profile separation
Limitations โ
- macOS only
- Binary format can change between versions
- Safari must be installed
- Container permissions needed
- No profile separation
- Some cookies may be restricted
- Fails silently if container inaccessible
Implementation Examples โ
Chrome Strategy (macOS) โ
typescript
import { ChromeCookieQueryStrategy } from "@mherod/get-cookie";
// Create strategy
const strategy = new ChromeCookieQueryStrategy();
try {
// Query cookies (macOS only)
const cookies = await strategy.queryCookies("auth", "example.com");
} catch (error) {
if (error.message.includes("platform")) {
console.error("Chrome cookies only supported on macOS");
} else if (error.message.includes("keychain")) {
console.error("Keychain access denied");
} else {
console.error("Failed to query cookies:", error);
}
}
Firefox Strategy (Cross-Platform) โ
typescript
import { FirefoxCookieQueryStrategy } from "@mherod/get-cookie";
// Create strategy
const strategy = new FirefoxCookieQueryStrategy();
try {
// Works on macOS and Linux
const cookies = await strategy.queryCookies("auth", "example.com");
} catch (error) {
if (error.message.includes("SQLITE_BUSY")) {
console.error("Database is locked");
} else if (error.message.includes("EACCES")) {
console.error("Permission denied");
} else {
console.error("Failed to query cookies:", error);
}
}
Safari Strategy (macOS) โ
typescript
import { SafariCookieQueryStrategy } from "@mherod/get-cookie";
// Create strategy
const strategy = new SafariCookieQueryStrategy();
try {
// macOS only
const cookies = await strategy.queryCookies("auth", "example.com");
} catch (error) {
if (error.message.includes("container")) {
console.error("Safari container access denied");
} else if (error.message.includes("format")) {
console.error("Invalid cookie file format");
} else {
console.error("Failed to query cookies:", error);
}
}
Best Practices โ
Error Handling โ
Always use try-catch blocks
typescripttry { const cookies = await getCookie({ name: "auth", domain: "example.com", }); } catch (error) { // Handle specific error types console.error("Cookie extraction failed:", error); }
Check platform compatibility
typescriptif (process.platform !== "darwin") { console.warn("Some features only work on macOS"); }
Handle browser-specific errors
typescriptif (error.message.includes("SQLITE_BUSY")) { // Retry after delay await new Promise((resolve) => setTimeout(resolve, 1000)); }
Security Considerations โ
Keychain Access (Chrome)
- Request user permission for Keychain access
- Handle denied access gracefully
- Don't store Keychain passwords
Database Access (Firefox)
- Check file permissions before access
- Handle locked database states
- Implement retry mechanisms
Container Access (Safari)
- Verify container permissions
- Handle format version changes
- Don't modify cookie store directly
Troubleshooting โ
Platform-Specific Issues โ
macOS โ
- Check Keychain status
- Verify container access
- Monitor profile changes
- Handle encryption errors
Linux (Firefox) โ
- Check file permissions
- Monitor database locks
- Handle profile paths
- Verify SQLite access
Common Problems โ
Access Denied
- Check user permissions
- Verify browser installation
- Review security settings
- Check file ownership
Browser Issues
- Verify browser version
- Check profile status
- Monitor file locks
- Handle updates
Data Issues
- Validate cookie format
- Check encryption status
- Monitor file integrity
- Handle corruption