npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mks2508/binary-cookies-parser

v2.0.1

Published

Universal cookie parser supporting Netscape (cookies.txt), JSON, and macOS binary (.binarycookies) formats with auto-detection.

Readme

binary-cookies-parser 🍪

npm version License: MIT TypeScript Bun

A modern, TypeScript-native parser for macOS binary cookies files (.binarycookies). Parse Safari and macOS app cookies with full type safety and zero dependencies.

Features

  • Zero Dependencies - Pure TypeScript implementation
  • Dual Package - ESM and CommonJS support
  • Fast - Built with Bun, works with Node.js
  • macOS Native - Handles Safari and native app cookies
  • Simple API - One function to parse cookies

Installation

# npm
npm install binary-cookies-parser

# bun
bun add binary-cookies-parser

# yarn
yarn add binary-cookies-parser

# pnpm
pnpm add binary-cookies-parser

Usage

Basic Parsing

import { parseBinaryCookies } from 'binary-cookies-parser';
import { homedir } from 'node:os';
import { join } from 'node:path';

// Parse Safari cookies
const safariCookies = await parseBinaryCookies(
  join(homedir(), 'Library/Cookies/Cookies.binarycookies')
);

// Each cookie has:
// - name: string
// - value: string
// - url: string (domain)
// - path: string
// - flags: number (0=none, 1=secure, 4=httpOnly, 5=both)
// - expiration: Date
// - creation: Date

Filtering Cookies

// Filter by domain
const googleCookies = cookies.filter(c => c.url.includes('google.com'));

// Filter by secure flag
const secureCookies = cookies.filter(c => c.flags & 1);

// Filter by expiration
const validCookies = cookies.filter(c => c.expiration > new Date());

Converting to Playwright Format

const playwrightCookies = cookies.map(c => ({
  name: c.name,
  value: c.value,
  domain: c.url,
  path: c.path,
  expires: Math.floor(c.expiration.getTime() / 1000),
  httpOnly: !!(c.flags & 4),
  secure: !!(c.flags & 1),
  sameSite: 'Lax' as const
}));

// Use with Playwright
await context.addCookies(playwrightCookies);

Using the Class API

import { BinaryCookiesParser } from 'binary-cookies-parser';

const parser = new BinaryCookiesParser();
const cookies = await parser.parse('/path/to/Cookies.binarycookies');

API Reference

parseBinaryCookies(cookiePath: string): Promise<BinaryCookie[]>

Parses a binary cookies file and returns an array of cookies.

Parameters:

  • cookiePath - Absolute path to the .binarycookies file

Returns:

  • Promise<BinaryCookie[]> - Array of parsed cookies

Throws:

  • Error if file doesn't exist
  • Error if file format is invalid

BinaryCookie Interface

interface BinaryCookie {
  name: string;        // Cookie name
  value: string;       // Cookie value
  url: string;         // Domain (e.g., ".apple.com")
  path: string;        // Path (e.g., "/")
  flags: number;       // Flags (0=none, 1=secure, 4=httpOnly, 5=both)
  expiration: Date;    // Expiration date
  creation: Date;      // Creation date
}

Cookie Flags

| Flag | Meaning | |------|---------| | 0 | No flags | | 1 | Secure cookie | | 4 | HttpOnly cookie | | 5 | Secure + HttpOnly |

Common Use Cases

Extract Safari Cookies for Automation

import { parseBinaryCookies } from 'binary-cookies-parser';
import { homedir } from 'node:os';
import { join } from 'node:path';

const cookies = await parseBinaryCookies(
  join(homedir(), 'Library/Cookies/Cookies.binarycookies')
);

// Use with Puppeteer, Playwright, etc.

Parse macOS App Cookies

import { parseBinaryCookies } from 'binary-cookies-parser';
import { homedir } from 'node:os';
import { join } from 'node:path';

// Example: Amazon Prime Video app
const primeCookies = await parseBinaryCookies(
  join(
    homedir(),
    'Library/Containers/com.amazon.aiv.AIVApp/Data/Library/Cookies/Cookies.binarycookies'
  )
);

Cookie Migration

// Export cookies from Safari
const cookies = await parseBinaryCookies('/path/to/safari/cookies');

// Convert to JSON for backup
await Bun.write('cookies-backup.json', JSON.stringify(cookies, null, 2));

// Filter and import to another browser
const importCookies = cookies.filter(c =>
  c.url.includes('important-domain.com')
);

Platform Support

  • macOS - ✅ Full support (Safari, native apps)
  • Linux - ❌ Not applicable (no .binarycookies files)
  • Windows - ❌ Not applicable (no .binarycookies files)

This library is specifically for parsing macOS binary cookies files. For cross-platform cookie management, consider using browser automation tools.

Examples

See the examples/ directory for complete working examples:

  • basic-usage.ts - Parse Safari cookies and convert to Playwright format

Run examples:

bun run examples/basic-usage.ts

Development

# Install dependencies
bun install

# Run tests
bun test

# Build for npm
bun run build

# Generate types
bun run types

Technical Details

Binary Format

The .binarycookies format is a proprietary Apple format used by Safari and macOS applications. This parser implements the complete specification:

  • File header validation (cook magic bytes)
  • Multi-page cookie storage
  • Mac epoch time conversion (978307200 offset)
  • Cookie flag parsing
  • Null-terminated string extraction

Performance

  • Zero external dependencies
  • Single-pass parsing
  • Efficient buffer operations
  • Minimal memory allocations

Credits

Inspired by the original node-binary-cookies by Jonathan Lipps, but completely rewritten in modern TypeScript with:

  • Full type safety
  • Async/await API
  • Zero dependencies
  • Dual ESM/CJS support
  • Bun optimization

License

MIT © 2025 MKS2508

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Links