03568c88e3
- frontend/functions/core/format_datetime_short.md - frontend/functions/core/format_datetime_short.test.ts - frontend/functions/core/format_datetime_short.ts - frontend/functions/core/format_duration.md - frontend/functions/core/format_duration.test.ts - frontend/functions/core/format_duration.ts - frontend/functions/core/month_grid.md - frontend/functions/core/month_grid.test.ts - frontend/functions/core/month_grid.ts - frontend/functions/core/string_hash_palette.md - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
50 lines
1.6 KiB
Markdown
50 lines
1.6 KiB
Markdown
---
|
|
id: cdp_set_cookie_go_browser
|
|
name: cdp_set_cookie
|
|
kind: function
|
|
lang: go
|
|
domain: browser
|
|
purity: impure
|
|
version: 1.0.0
|
|
tested: false
|
|
description: "Establece una cookie en el browser via Network.setCookie del protocolo CDP. Soporta cookies HttpOnly. Util para tests e2e que necesitan autenticar el browser sin pasar por la UI de login."
|
|
tags: [cdp, browser, cookie, e2e, auth]
|
|
signature: "func CdpSetCookie(c *CDPConn, name, value, domain, path string, httpOnly bool) error"
|
|
uses_functions: []
|
|
uses_types:
|
|
- cdp_conn_go_browser
|
|
returns: ""
|
|
returns_optional: false
|
|
error_type: error_go_core
|
|
imports: []
|
|
file_path: "functions/browser/cdp_set_cookie.go"
|
|
example: |
|
|
conn, _ := browser.CdpConnect(9222)
|
|
defer browser.CdpClose(conn, 0)
|
|
// Tras hacer login HTTP en el test:
|
|
if err := browser.CdpSetCookie(conn, "session", token, "localhost", "/", true); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
browser.CdpNavigate(conn, "http://localhost:8080/dashboard")
|
|
params:
|
|
- name: c
|
|
desc: Conexion CDP abierta (de CdpConnect)
|
|
- name: name
|
|
desc: Nombre de la cookie
|
|
- name: value
|
|
desc: Valor de la cookie (token de sesion, etc.)
|
|
- name: domain
|
|
desc: Dominio sin protocolo (ej. "localhost", "example.com")
|
|
- name: path
|
|
desc: Path scope. Vacio se trata como "/"
|
|
- name: httpOnly
|
|
desc: Si true, cookie HttpOnly (no accesible desde JS)
|
|
output: "error si Network.setCookie falla; nil en exito"
|
|
---
|
|
|
|
## Notas
|
|
|
|
- Network.setCookie es un comando CDP nativo, no requiere JS evaluate.
|
|
- Permite cookies HttpOnly que `document.cookie` no puede setear desde JS.
|
|
- Necesita que el dominio coincida con la URL a la que se navegara despues.
|