Automation with get-cookie
get-cookie is useful when a local, user-initiated task needs the same authenticated session that already exists in your browser. It reads browser storage on the current machine; it is not a credential-management system.
CAUTION
A browser cookie can grant account access. Use cookies only for accounts and sites you are authorized to access. Keep them in memory, do not print or persist them, and prefer official API tokens for unattended or CI workflows.
Choose a path
- MCP server lets agents find matching browser profiles and make authenticated requests using your existing session.
- Shell scripts cover status-only local preflights and redacted metadata checks.
- Browser automation covers metadata-only readiness checks and why automatic Playwright cookie replay is not documented.
- CLI usage documents query, browser, profile, container, and output flags.
- API reference documents the exported TypeScript surface.
Two building blocks
For local inspection, name one known cookie and target domain. --render serializes matches as a Cookie-header string:
get-cookie sessionid example.com --render--render is not a safe generic outgoing-request helper: the query result does not prove path, secure-context, or exact-destination applicability. --url is broader still because it can inspect hostname and parent-domain matches without stopping at public suffixes. Keep rendered output local.
For programmatic use, query by cookie name and domain:
import { getCookie } from "@mherod/get-cookie";
const cookies = await getCookie({
name: "sessionid",
domain: "example.com",
});getCookie returns an array. An empty array is a normal result when no matching cookie is available, so automation should stop rather than continue without authentication.
Safe operating rules
- Run automation on the same local machine and user account as the browser session.
- Request only the domain and cookie names needed for the current task.
- Keep cookie values in process memory; never write them to files, logs, screenshots, traces, or shell history.
- Check for an empty result before continuing a local task.
- Unset shell variables and discard returned arrays as soon as the task ends.