Skip to content

Bug: openclaw browser cookies set --url broken — parent command captures --url option #24811

@jonathangu

Description

@jonathangu

Summary

openclaw browser cookies set <name> <value> --url <target-url> always fails with:

error: required option '--url <url>' not specified

Even though --url is clearly passed. The cookie value is never set.

Root Cause

In src/cli/browser-cli.ts (line ~44), addGatewayClientOptions(browser) adds a --url <url> option to the parent browser command (for the gateway WebSocket URL). Commander.js captures --url at the parent level before the set subcommand can see it.

In src/cli/browser-cli-state.cookies-storage.ts (line ~61), the set subcommand adds .requiredOption("--url <url>", ...) for the target cookie URL. But the parent already consumed it.

The existing test at browser-cli-state.option-collisions.test.ts (line ~67) passes because it does not include addGatewayClientOptions in its mock setup — so the collision is never exercised.

Impact

  • /cookies/set HTTP endpoint works correctly — Playwright's context.addCookies() properly injects cookies into the networking context
  • The CLI is the only broken path — the --url collision prevents the endpoint from being reached
  • Agents that need authenticated browser testing (HttpOnly session cookies) have no working CLI path
  • Workaround: Use the gateway WebSocket RPC directly to call /cookies/set, or navigate through the login UI manually

Suggested Fix

Use the existing inheritOptionFromParent() pattern from command-options.ts (already used for --target-id collision):

  1. Change set subcommand from .requiredOption("--url") to .option("--url")
  2. Add a resolveCookieUrl() helper that checks local opts first, then walks ancestors via inheritOptionFromParent()
  3. Also check --browser-profile propagation to nested subcommands (same root cause)
  4. Update the test to include addGatewayClientOptions in the mock so the real collision is covered

Reproduction

# This should set a cookie but fails:
openclaw browser cookies set "connect.sid" "s%3Axyz" --url "https://example.com"
# error: required option '--url <url>' not specified

# The HTTP endpoint works fine:
curl -X POST http://127.0.0.1:18789/browser/cookies/set \
  -H "Content-Type: application/json" \
  -d '{"cookie": {"name": "connect.sid", "value": "s%3Axyz", "url": "https://example.com"}}'

Environment

  • OpenClaw 2026.2.23 (commit a6a2a92)
  • macOS 15.3 (arm64)
  • Node v25.5.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions