Skip to content

Add browse cookies commands for cookie management#1908

Open
derekmeegan wants to merge 3 commits intomainfrom
derek/add_cookies_command
Open

Add browse cookies commands for cookie management#1908
derekmeegan wants to merge 3 commits intomainfrom
derek/add_cookies_command

Conversation

@derekmeegan
Copy link
Copy Markdown
Contributor

Summary

  • Adds browse cookies get [urls...] to inspect cookies (including httpOnly), with optional URL filtering
  • Adds browse cookies set <json> to add cookies from a JSON array
  • Adds browse cookies clear to remove all cookies, or filter by --name, --domain, --path
  • Uses Understudy's existing context.cookies(), addCookies(), clearCookies() methods

Usage

browse cookies get                              # all cookies
browse cookies get https://example.com          # filtered by URL
browse cookies set '[{"name":"session","value":"abc","url":"https://example.com"}]'
browse cookies clear                            # clear all
browse cookies clear --domain example.com       # clear by domain

Test results

Test Local Browserbase
cookies get (empty) [] []
cookies set (add 1 cookie) {added: 1} {added: 1}
cookies get (verify set) Shows cookie with correct name/value/domain Same
cookies get <url> (URL filter) Filters correctly Filters correctly
cookies clear --domain Cleared, verified empty Cleared, verified empty

🤖 Generated with Claude Code

Adds cookies get/set/clear subcommands using Understudy's existing
context.cookies(), addCookies(), and clearCookies() methods.

Usage:
  browse cookies get                    # all cookies
  browse cookies get https://example.com # filtered by URL
  browse cookies set '[{"name":"a","value":"b","url":"https://..."}]'
  browse cookies clear                  # clear all
  browse cookies clear --domain example.com  # filtered clear

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 29, 2026

🦋 Changeset detected

Latest commit: 1ac94ce

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Confidence score: 3/5

  • There is a concrete regression risk in packages/cli/src/index.ts: using a truthiness check for filter presence means an empty-string option can be interpreted as "no filter," which may unexpectedly clear all cookies.
  • Given the severity (6/10) and high confidence (8/10), this is user-impacting behavior rather than a minor edge-case, so the merge risk is moderate until the condition is tightened.
  • Pay close attention to packages/cli/src/index.ts - filter handling should distinguish empty-string values from an absent filter to avoid unintended cookie clearing.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/cli/src/index.ts">

<violation number="1" location="packages/cli/src/index.ts:2833">
P2: The filter-presence check uses truthiness, so empty-string option values are treated as “no filter” and can trigger clearing all cookies unexpectedly.</violation>
</file>
Architecture diagram
sequenceDiagram
    participant User as User / Shell
    participant CLI as CLI Command Handler
    participant Executor as executeCommand (Router)
    participant Context as Understudy Context
    participant Browser as Browser (Local/Remote)

    Note over User, Browser: NEW: Cookie Management Flow

    User->>CLI: browse cookies get [urls]
    CLI->>Executor: runCommand("cookies_get", [urls])
    Executor->>Context: CHANGED: context.cookies(urls)
    Context->>Browser: Request cookies (filtered by URL)
    Browser-->>Context: Return cookie array
    Context-->>Executor: Return cookies
    Executor-->>CLI: { cookies: [...] }
    CLI-->>User: Output JSON/Text

    User->>CLI: browse cookies set <json>
    CLI->>CLI: JSON.parse(json)
    alt Invalid JSON
        CLI-->>User: Error: must be JSON array
    else Valid JSON
        CLI->>Executor: runCommand("cookies_set", [cookies])
        Executor->>Context: CHANGED: context.addCookies(cookieParams)
        Context->>Browser: Inject cookies into session
        Context-->>Executor: void
        Executor-->>CLI: { added: count }
        CLI-->>User: Success message
    end

    User->>CLI: browse cookies clear --domain <d>
    CLI->>Executor: runCommand("cookies_clear", [{domain: d}])
    Executor->>Context: CHANGED: context.clearCookies(filters)
    Context->>Browser: Remove cookies matching filters
    Context-->>Executor: void
    Executor-->>CLI: { cleared: true }
    CLI-->>User: Confirmation
Loading

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

derekmeegan and others added 2 commits March 29, 2026 14:30
Prevents empty-string option values from being treated as absent,
which would bypass the filter and clear all cookies unexpectedly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant