npm package: @kieranhunt/crul
Description: Extract browser cookies and write them as a Netscape-format cookie jar file for curl/wget
Author: Kieran Hunt
Latest version: 0.1.2

# crul

[![npm version](https://img.shields.io/npm/v/@kieranhunt/crul)](https://www.npmjs.com/package/@kieranhunt/crul)
[![CI](https://github.com/KieranHunt/crul/actions/workflows/ci.yml/badge.svg)](https://github.com/KieranHunt/crul/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Node.js >= 18](https://img.shields.io/badge/node-%3E%3D18-brightgreen)](https://nodejs.org/)

Extract browser cookies and write them as a Netscape-format cookie jar file, compatible with `curl -b`, `wget --load-cookies`, and other tools that speak the Netscape cookie file format.

Uses [@steipete/sweet-cookie](https://github.com/steipete/sweet-cookie) under the hood to read cookies from Chrome, Edge, Firefox, and Safari.

## Install

```bash
npm install -g @kieranhunt/crul
```

Or run directly without installing:

```bash
npx @kieranhunt/crul --url https://example.com
```

## Usage

```bash
# Extract all cookies for a URL, print to stdout
npx @kieranhunt/crul --url https://example.com

# Write to a file (created with 0600 permissions)
npx @kieranhunt/crul --url https://example.com --output cookies.txt

# Use a specific browser
npx @kieranhunt/crul --url https://example.com --browsers chrome

# Filter to specific cookie names
npx @kieranhunt/crul --url https://example.com --names session --names csrf

# Multiple origins (useful for SSO/OAuth flows)
npx @kieranhunt/crul --url https://app.example.com \
  --origins https://login.example.com \
  --origins https://accounts.example.com

# Pipe directly into curl
curl -b <(npx @kieranhunt/crul --url https://example.com) https://example.com/api
```

## Options

All option names mirror the [`GetCookiesOptions`](https://github.com/steipete/sweet-cookie) API from sweet-cookie.

| Option | Description |
|---|---|
| `--url <url>` | **(required)** URL to extract cookies for |
| `--output <path>` | Output file path. Omit to write to stdout |
| `--browsers <browsers...>` | Browser backends: `chrome`, `edge`, `firefox`, `safari` |
| `--names <names...>` | Filter to specific cookie names |
| `--origins <urls...>` | Additional origins to include |
| `--profile <profile>` | Alias for `--chrome-profile` |
| `--chrome-profile <profile>` | Chrome profile name, directory, or Cookies DB path |
| `--edge-profile <profile>` | Edge profile name, directory, or Cookies DB path |
| `--firefox-profile <profile>` | Firefox profile name or directory path |
| `--safari-cookies-file <path>` | Override path to Safari `Cookies.binarycookies` |
| `--chromium-browser <browser>` | macOS Chromium target: `chrome`, `brave`, `arc`, `chromium` |
| `--mode <mode>` | `merge` (default) or `first` |
| `--include-expired` | Include expired cookies |
| `--timeout-ms <ms>` | Timeout for OS helper calls (keychain/keyring/DPAPI) |
| `--inline-cookies-file <path>` | Read inline cookie payload from file |
| `--inline-cookies-json <json>` | Inline cookie payload as JSON string |
| `--inline-cookies-base64 <b64>` | Inline cookie payload as base64-encoded JSON |
| `--debug` | Print extra warnings to stderr |

## Output format

The output follows the [Netscape cookie file format](https://curl.se/docs/http-cookies.html) -- one cookie per line, TAB-delimited:

```
# Netscape HTTP Cookie File
# https://curl.se/docs/http-cookies.html
# This file was generated by crul.
# Edit at your own risk.

#HttpOnly_.example.com	TRUE	/	TRUE	1735689600	session	abc123
example.com	FALSE	/	FALSE	0	csrf	xyz
```

Fields: `domain`, `subdomain flag`, `path`, `secure`, `expires` (unix seconds, 0 = session), `name`, `value`.

Cookies with `httpOnly` set get the `#HttpOnly_` prefix on the domain (recognized by curl, Firefox, etc).

## License

MIT