grafana/k6 · error

no cookies provided

Error message

no cookies provided

What it means

AddCookies rejects an empty cookie list before making any CDP call: 'skip work if no cookies provided' is enforced as an error, not a no-op. k6 requires at least one cookie object in the array passed to browserContext.addCookies().

Solutions

  1. Guard the call: only invoke addCookies when the array is non-empty
  2. Fix the upstream source so the cookie list is actually populated before the browser step
  3. Log the cookie list length before calling to catch empty inputs early

Example fix

// before
const cookies = []; // forgot to populate from response
ctx.addCookies(cookies); // throws 'no cookies provided'

// after
if (cookies.length > 0) {
  ctx.addCookies(cookies);
}
Defensive patterns

Strategy: validation

Validate before calling

if (!Array.isArray(cookies) || cookies.length === 0) {
  throw new Error('addCookies requires a non-empty cookie array');
}
ctx.addCookies(cookies);

Type guard

const hasCookies = (arr) => Array.isArray(arr) && arr.length > 0;

Prevention

When it happens

Trigger: browserContext.addCookies([]) or addCookies() with an empty array; a variable expected to hold cookies from an HTTP response or fixture that is actually empty at runtime.

Common situations: Seeding cookies from an upstream HTTP request that returned no Set-Cookie headers; conditional code paths where the cookie list was never populated; parsing a JSON cookie fixture that yielded an empty array.

Related errors


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/42c102eeda750460. Report an issue: GitHub.

Appendix: 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 01ffac6f24)