{"record":{"id":"abe71e079c8201e6","repo":"grafana/k6","slug":"parsing-urls-w","errorCode":null,"errorMessage":"parsing urls: %w","messagePattern":"parsing urls: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/browser_context.go","lineNumber":578,"sourceCode":"\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)\n\t}\n\n\t// the following algorithm is like a sorting algorithm,\n\t// but instead of sorting, it filters the cookies slice\n\t// in place, without allocating a new slice. this is\n\t// done to avoid unnecessary allocations and copying\n\t// of data.\n\t//\n\t// n is used to remember the last cookie that should be\n\t// kept in the cookies slice. all cookies before n should\n\t// be kept, all cookies after n should be removed. it\n\t// constantly shifts cookies to be kept to the left in the\n\t// slice, overwriting cookies that should be removed.\n\t//\n\t// if a cookie should not be kept, it will be overwritten\n\t// by the next cookie that should be kept. if no cookies\n\t// should be kept, a nil slice is returned. otherwise,\n\t// the slice is truncated to the last cookie that should","sourceCodeStart":560,"sourceCodeEnd":596,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/browser_context.go#L560-L596","documentation":"Thrown by filterCookies (reached via BrowserContext.Cookies) when the URL list cannot be prepared: parseURLs returns an error and it is wrapped as 'parsing urls'. This is a pure input-validation failure — the cookie data itself was already retrieved successfully.","triggerScenarios":"browserContext.cookies(urls) with any URL string that url.ParseRequestURI rejects: missing scheme (plain 'example.com'), spaces or control characters, 'http://exa mple.com', or an empty-after-trim value. Note the implementation trims whitespace before parsing, so only genuinely malformed URLs fail.","commonSituations":"Dynamic URL lists assembled from config, CSV/JSON data, or env variables that contain hostnames instead of URLs; copy-paste artifacts like quotes or trailing commas inside the URL string.","solutions":["Give every URL a scheme: 'https://example.com/path' rather than 'example.com/path'.","Sanitize the list up front: trim strings, prefix a scheme when missing, drop empties.","Log the offending URL — the nested error includes it in quotes."],"exampleFix":"// before\nconst urls = ['example.com', 'http://ok.example'];\ncontext.cookies(...urls); // first entry fails\n\n// after\nconst urls = ['https://example.com', 'http://ok.example'];\ncontext.cookies(...urls);","handlingStrategy":"validation","validationCode":"function toAbsoluteUrl(u) {\n  const t = String(u).trim();\n  return /^https?:\\/\\//.test(t) ? t : `https://${t}`;\n}\ncontext.cookies(urls.map(toAbsoluteUrl));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass absolute URIs only — ParseRequestURI rejects bare hostnames and relative paths.","Trim and validate URL lists from env vars and fixtures.","Unit-test URL normalization helpers against the exact strings used in tests."],"tags":["url","validation","cookies","browser-context"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}