grafana/k6 · error
filtering cookies: %w
Error message
filtering cookies: %w
What it means
Thrown by BrowserContext.Cookies when post-retrieval URL filtering fails. After the CDP cookies are fetched and converted, filterCookies parses the caller-supplied URLs to match cookies against them; any failure in that step is wrapped as 'filtering cookies'. In practice the wrapped cause is always a URL parsing error.
Source
Thrown at internal/js/modules/k6/browser/common/browser_context.go:560
// convert the received CDP cookies to the browser API format.
cookies := make([]*Cookie, len(networkCookies))
for i, c := range networkCookies {
cookies[i] = &Cookie{
Name: c.Name,
Value: c.Value,
Domain: c.Domain,
Path: c.Path,
Expires: int64(c.Expires),
HTTPOnly: c.HTTPOnly,
Secure: c.Secure,
SameSite: CookieSameSite(c.SameSite),
}
}
// filter cookies by the provided URLs.
cookies, err = filterCookies(cookies, urls...)
if err != nil {
return nil, fmt.Errorf("filtering cookies: %w", err)
}
if len(cookies) == 0 {
return nil, nil
}
return cookies, nil
}
// filterCookies filters the given cookies based on URLs.
// If an error occurs while parsing the cookie URLs, the error is returned.
func filterCookies(cookies []*Cookie, urls ...string) ([]*Cookie, error) {
if len(urls) == 0 || len(cookies) == 0 {
return cookies, nil
}
purls, err := parseURLs(urls...)
if err != nil {
return nil, fmt.Errorf("parsing urls: %w", err)View on GitHub (pinned to 93accf6570)
Solutions
- Pass fully-qualified URLs with scheme: context.cookies(['https://example.com']).
- Normalize/validate the URL list before calling cookies().
- Read the inner error message — it names the exact offending URL (see the '%q: %w' parse error).
Example fix
// before const cookies = context.cookies(['example.com']); // no scheme -> error // after const cookies = context.cookies(['https://example.com']);
Defensive patterns
Strategy: validation
Validate before calling
const validUrls = urls.map((u) => u.trim()).filter((u) => /^https?:\/\/\S+$/.test(u));
if (validUrls.length !== urls.length) {
throw new Error('all URLs must be absolute, e.g. https://example.com');
}
context.cookies(validUrls); Prevention
- Always pass full URLs (with scheme) to context.cookies().
- Normalize URLs from config/data sources before use.
- Remember the error nests the real cause — read the tail of the message.
When it happens
Trigger: Calling browserContext.cookies(urls) where one of the URLs is not parseable by Go's url.ParseRequestURI — e.g. 'example.com' with no scheme, a string with spaces, or garbage input. The CDP part already succeeded; only the filtering stage failed.
Common situations: Passing bare hostnames instead of full URLs; constructing the URL list from user input or env vars without normalizing; trailing whitespace or stray characters in configured URLs.
Related errors
- parsing urls: %w
- no cookies provided
- cookie name must be set: %#v
- cookie value must be set: %#v
- if cookie URL is not provided, both domain and path must be
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/45d45dc261151427.
Report an issue: GitHub.