{"record":{"id":"45d45dc261151427","repo":"grafana/k6","slug":"filtering-cookies-w","errorCode":null,"errorMessage":"filtering cookies: %w","messagePattern":"filtering cookies: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/browser_context.go","lineNumber":560,"sourceCode":"\n\t// convert the received CDP cookies to the browser API format.\n\tcookies := make([]*Cookie, len(networkCookies))\n\tfor i, c := range networkCookies {\n\t\tcookies[i] = &Cookie{\n\t\t\tName:     c.Name,\n\t\t\tValue:    c.Value,\n\t\t\tDomain:   c.Domain,\n\t\t\tPath:     c.Path,\n\t\t\tExpires:  int64(c.Expires),\n\t\t\tHTTPOnly: c.HTTPOnly,\n\t\t\tSecure:   c.Secure,\n\t\t\tSameSite: CookieSameSite(c.SameSite),\n\t\t}\n\t}\n\t// filter cookies by the provided URLs.\n\tcookies, err = filterCookies(cookies, urls...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"filtering cookies: %w\", err)\n\t}\n\tif len(cookies) == 0 {\n\t\treturn nil, nil\n\t}\n\n\treturn cookies, nil\n}\n\n// filterCookies filters the given cookies based on URLs.\n// If an error occurs while parsing the cookie URLs, the error is returned.\nfunc filterCookies(cookies []*Cookie, urls ...string) ([]*Cookie, error) {\n\tif len(urls) == 0 || len(cookies) == 0 {\n\t\treturn cookies, nil\n\t}\n\n\tpurls, err := parseURLs(urls...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"parsing urls: %w\", err)","sourceCodeStart":542,"sourceCodeEnd":578,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/browser_context.go#L542-L578","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nconst cookies = context.cookies(['example.com']); // no scheme -> error\n\n// after\nconst cookies = context.cookies(['https://example.com']);","handlingStrategy":"validation","validationCode":"const validUrls = urls.map((u) => u.trim()).filter((u) => /^https?:\\/\\/\\S+$/.test(u));\nif (validUrls.length !== urls.length) {\n  throw new Error('all URLs must be absolute, e.g. https://example.com');\n}\ncontext.cookies(validUrls);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["cookies","url","validation","browser-context"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}