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
Parameters
Required
context_idstringrequiredThe unique identifier of the browser context (e.g., 'ctx_000001')
urlstringrequiredURL 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'
namestringrequiredThe cookie name. Case-sensitive identifier for the cookie. Example: 'session_id', 'auth_token'
valuestringrequiredThe cookie value. Can be any string data. For security tokens, use the exact value from authentication
Optional
domainstringCookie domain scope. If empty, creates a host-only cookie. With leading dot (e.g., '.example.com'), the cookie is visible to all subdomains
pathstringURL path that must exist in the request URL for the cookie to be sent. Default: '/' (all paths). Example: '/api' restricts cookie to /api/* paths
securebooleanIf true, cookie is only sent over HTTPS connections. Set to true for sensitive cookies. Default: false
httpOnlybooleanIf true, cookie cannot be accessed via JavaScript (document.cookie). Protects against XSS. Default: false
sameSiteenumnonelaxstrictCross-site request restriction: 'strict' (only same-site), 'lax' (same-site + top-level navigation), 'none' (allow cross-site, requires secure=true). Default: 'lax'
expiresstringUnix 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>
}