{"record":{"id":"c3ca5b2212354af8","repo":"grafana/k6","slug":"q-w","errorCode":null,"errorMessage":"%q: %w","messagePattern":"%q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/browser_context.go","lineNumber":679,"sourceCode":"\t// the scheme is not HTTPS, unless it's localhost.\n\tif uri.Scheme != \"https\" && uri.Hostname() != \"localhost\" && c.Secure {\n\t\treturn false\n\t}\n\n\t// Keep the cookie.\n\treturn true\n}\n\n// parseURLs parses the given URLs.\n// If an error occurs while parsing a URL, the error is returned.\nfunc parseURLs(urls ...string) ([]*url.URL, error) {\n\tpurls := make([]*url.URL, len(urls))\n\tfor i, u := range urls {\n\t\turi, err := url.ParseRequestURI(\n\t\t\tstrings.TrimSpace(u),\n\t\t)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"%q: %w\", u, err)\n\t\t}\n\t\tpurls[i] = uri\n\t}\n\n\treturn purls, nil\n}\n","sourceCodeStart":661,"sourceCodeEnd":686,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/browser_context.go#L661-L686","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\ncontext.cookies(['  example.com  ']); // trims to 'example.com', still no scheme -> error\n\n// after\ncontext.cookies(['https://example.com']);","handlingStrategy":"validation","validationCode":"function isParsableRequestUri(u) {\n  try {\n    const parsed = new URL(String(u).trim());\n    return parsed.protocol === 'http:' || parsed.protocol === 'https:';\n  } catch {\n    return false;\n  }\n}\nif (!urls.every(isParsableRequestUri)) throw new Error('invalid URL for cookies()');","typeGuard":"function isAbsoluteHttpUrl(u) {\n  try {\n    const p = new URL(String(u).trim()).protocol;\n    return p === 'http:' || p === 'https:';\n  } catch {\n    return false;\n  }\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["url","validation","cookies"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}