grafana/k6 · error
%q: %w
Error message
%q: %w
What it means
The innermost parse error from parseURLs: Go's url.ParseRequestURI rejected the string, and the error is formatted as "<raw-url>: <cause>". ParseRequestURI demands an absolute URI with a scheme, so relative or bare strings are refused. The raw (untrimmed) original string is shown, which makes spotting the bad character easy.
Source
Thrown at internal/js/modules/k6/browser/common/browser_context.go:679
// the scheme is not HTTPS, unless it's localhost.
if uri.Scheme != "https" && uri.Hostname() != "localhost" && c.Secure {
return false
}
// Keep the cookie.
return true
}
// parseURLs parses the given URLs.
// If an error occurs while parsing a URL, the error is returned.
func parseURLs(urls ...string) ([]*url.URL, error) {
purls := make([]*url.URL, len(urls))
for i, u := range urls {
uri, err := url.ParseRequestURI(
strings.TrimSpace(u),
)
if err != nil {
return nil, fmt.Errorf("%q: %w", u, err)
}
purls[i] = uri
}
return purls, nil
}
View on GitHub (pinned to 93accf6570)
Solutions
- Use absolute URLs with an explicit scheme (http/https) everywhere you pass URLs to cookies().
- Normalize inputs: u = u.trim(); if (!/^https?:\/\//.test(u)) u = 'https://' + u;
- Check the quoted URL in the error message for invisible characters if it looks correct.
Example fix
// before context.cookies([' example.com ']); // trims to 'example.com', still no scheme -> error // after context.cookies(['https://example.com']);
Defensive patterns
Strategy: validation
Validate before calling
function isParsableRequestUri(u) {
try {
const parsed = new URL(String(u).trim());
return parsed.protocol === 'http:' || parsed.protocol === 'https:';
} catch {
return false;
}
}
if (!urls.every(isParsableRequestUri)) throw new Error('invalid URL for cookies()'); Type guard
function isAbsoluteHttpUrl(u) {
try {
const p = new URL(String(u).trim()).protocol;
return p === 'http:' || p === 'https:';
} catch {
return false;
}
} Prevention
- Require a scheme on every URL string passed into the browser cookie APIs.
- Prefer new URL() in a guard to catch typos before the browser call fails.
- Beware invisible characters (smart quotes, non-breaking spaces) in pasted URLs.
When it happens
Trigger: Any URL passed to browserContext.cookies() that is not an absolute URI: 'www.example.com', '/pathonly', 'example.com/path', 'http://exa mple.com', or a string that is only whitespace after trim.
Common situations: Env-var-driven URL configuration where someone stored just the hostname; URLs scraped from page content that turn out relative; locales/typographic characters (unicode quotes, non-breaking spaces) pasted into configs.
Related errors
- filtering cookies: %w
- parsing urls: %w
- urlTemplate must contain {key} placeholder
- urlTemplate must be an absolute URL with a scheme (e.g., htt
- cookie: is null
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/c3ca5b2212354af8.
Report an issue: GitHub.