grafana/k6 · error
no cookies provided
Error message
no cookies provided
What it means
Validation error from BrowserContext.AddCookies: the cookies argument was an empty array, so the method refuses to make the CDP Storage.setCookies call at all. k6 treats 'add no cookies' as a caller mistake rather than a no-op, matching the strict input validation style of the cookie API.
Source
Thrown at internal/js/modules/k6/browser/common/browser_context.go:460
out <- p
return
}
}
}
}
func (b *BrowserContext) getSession(id target.SessionID) *Session {
return b.browser.conn.getSession(id)
}
// AddCookies adds cookies into this browser context.
// All pages within this context will have these cookies installed.
func (b *BrowserContext) AddCookies(cookies []*Cookie) error {
b.logger.Debugf("BrowserContext:AddCookies", "bctxid:%v", b.id)
// skip work if no cookies provided.
if len(cookies) == 0 {
return fmt.Errorf("no cookies provided")
}
cookiesToSet := make([]*network.CookieParam, 0, len(cookies))
for _, c := range cookies {
if c.Name == "" {
return fmt.Errorf("cookie name must be set: %#v", c)
}
if c.Value == "" {
return fmt.Errorf("cookie value must be set: %#v", c)
}
// if URL is not set, both Domain and Path must be provided
if c.URL == "" && (c.Domain == "" || c.Path == "") {
const msg = "if cookie URL is not provided, both domain and path must be specified: %#v"
return fmt.Errorf(msg, c)
}
// calculate the cookie expiration date, session cookie if not set.
var ts *cdp.TimeSinceEpoch
if c.Expires > 0 {View on GitHub (pinned to 93accf6570)
Solutions
- Skip the call when the list is empty: if (cookies.length) context.addCookies(cookies).
- If you expected cookies, debug why the array is empty (check the parsing/fixture code that populates it) before calling addCookies.
- Ensure each cookie object has at least name and value plus url or domain+path.
Example fix
// before
context.addCookies(cookiesFromLogin); // empty at runtime
// after
if (cookiesFromLogin.length > 0) {
context.addCookies(cookiesFromLogin);
} Defensive patterns
Strategy: validation
Validate before calling
if (!Array.isArray(cookies) || cookies.length === 0) {
// nothing to install; skip the call (k6 rejects empty arrays)
} else {
context.addCookies(cookies);
} Prevention
- Guard dynamic cookie lists with a length check before calling addCookies.
- Log a warning when skipping so silent 'no cookies installed' states are visible.
- Assert that login/setup steps actually produced cookies before replaying them.
When it happens
Trigger: Calling browserContext.addCookies([]) with a literal empty array, or with a variable that is empty at runtime (e.g. parsed from a file or built in a loop that matched nothing).
Common situations: Dynamically building a cookie list from shared state, an HTTP response, or a JSON fixture that turns out empty; refactoring that leaves a placeholder addCookies([]) call; passing cookies to the wrong context before they are set.
Related errors
- cookie name must be set: %#v
- cookie value must be set: %#v
- if cookie URL is not provided, both domain and path must be
- filtering cookies: %w
- parsing urls: %w
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/42c102eeda750460.
Report an issue: GitHub.