DocsCookie Managementbrowser_set_cookie

browser_set_cookie

Browser Set Cookie

Set a cookie in the browser context with full control over all attributes. Supports domain, path, secure, httpOnly, sameSite, and expiration settings. Useful for injecting session tokens or test cookies.

Usage Example

1234567891011121314
import asyncio
from owl_browser import OwlBrowser, RemoteConfig
# Async usage
async with OwlBrowser(config) as browser:
context = await browser.create_context()
context_id = context["context_id"]
await browser.set_cookie(
context_id=context_id,
url="https://example.com",
name="value",
value="value"
)

Parameters

Required

context_idstringrequired

The unique identifier of the browser context (e.g., 'ctx_000001')

urlstringrequired

URL to associate with the cookie for domain validation. The cookie's domain must match or be a parent of this URL's domain. Example: 'https://example.com'

namestringrequired

The cookie name. Case-sensitive identifier for the cookie. Example: 'session_id', 'auth_token'

valuestringrequired

The cookie value. Can be any string data. For security tokens, use the exact value from authentication

Optional

domainstring

Cookie domain scope. If empty, creates a host-only cookie. With leading dot (e.g., '.example.com'), the cookie is visible to all subdomains

pathstring

URL path that must exist in the request URL for the cookie to be sent. Default: '/' (all paths). Example: '/api' restricts cookie to /api/* paths

secureboolean

If true, cookie is only sent over HTTPS connections. Set to true for sensitive cookies. Default: false

httpOnlyboolean

If true, cookie cannot be accessed via JavaScript (document.cookie). Protects against XSS. Default: false

sameSiteenum
nonelaxstrict

Cross-site request restriction: 'strict' (only same-site), 'lax' (same-site + top-level navigation), 'none' (allow cross-site, requires secure=true). Default: 'lax'

expiresstring

Unix timestamp (seconds since epoch) when the cookie expires. Use -1 or omit for session cookie (deleted when browser closes). Example: 1735689600 for a future date

Response

Returns a JSON object with the operation result.

{
  "success": true,
  "result": <value>
}