{"record":{"id":"42c102eeda750460","repo":"grafana/k6","slug":"no-cookies-provided","errorCode":null,"errorMessage":"no cookies provided","messagePattern":"no cookies provided","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/browser_context.go","lineNumber":460,"sourceCode":"\t\t\t\tout <- p\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunc (b *BrowserContext) getSession(id target.SessionID) *Session {\n\treturn b.browser.conn.getSession(id)\n}\n\n// AddCookies adds cookies into this browser context.\n// All pages within this context will have these cookies installed.\nfunc (b *BrowserContext) AddCookies(cookies []*Cookie) error {\n\tb.logger.Debugf(\"BrowserContext:AddCookies\", \"bctxid:%v\", b.id)\n\n\t// skip work if no cookies provided.\n\tif len(cookies) == 0 {\n\t\treturn fmt.Errorf(\"no cookies provided\")\n\t}\n\n\tcookiesToSet := make([]*network.CookieParam, 0, len(cookies))\n\tfor _, c := range cookies {\n\t\tif c.Name == \"\" {\n\t\t\treturn fmt.Errorf(\"cookie name must be set: %#v\", c)\n\t\t}\n\t\tif c.Value == \"\" {\n\t\t\treturn fmt.Errorf(\"cookie value must be set: %#v\", c)\n\t\t}\n\t\t// if URL is not set, both Domain and Path must be provided\n\t\tif c.URL == \"\" && (c.Domain == \"\" || c.Path == \"\") {\n\t\t\tconst msg = \"if cookie URL is not provided, both domain and path must be specified: %#v\"\n\t\t\treturn fmt.Errorf(msg, c)\n\t\t}\n\t\t// calculate the cookie expiration date, session cookie if not set.\n\t\tvar ts *cdp.TimeSinceEpoch\n\t\tif c.Expires > 0 {","sourceCodeStart":442,"sourceCodeEnd":478,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/browser_context.go#L442-L478","documentation":"Validation error from BrowserContext.AddCookies: the cookies argument was an empty array, so the method refuses to make the CDP Storage.setCookies call at all. k6 treats 'add no cookies' as a caller mistake rather than a no-op, matching the strict input validation style of the cookie API.","triggerScenarios":"Calling browserContext.addCookies([]) with a literal empty array, or with a variable that is empty at runtime (e.g. parsed from a file or built in a loop that matched nothing).","commonSituations":"Dynamically building a cookie list from shared state, an HTTP response, or a JSON fixture that turns out empty; refactoring that leaves a placeholder addCookies([]) call; passing cookies to the wrong context before they are set.","solutions":["Skip the call when the list is empty: if (cookies.length) context.addCookies(cookies).","If you expected cookies, debug why the array is empty (check the parsing/fixture code that populates it) before calling addCookies.","Ensure each cookie object has at least name and value plus url or domain+path."],"exampleFix":"// before\ncontext.addCookies(cookiesFromLogin); // empty at runtime\n\n// after\nif (cookiesFromLogin.length > 0) {\n  context.addCookies(cookiesFromLogin);\n}","handlingStrategy":"validation","validationCode":"if (!Array.isArray(cookies) || cookies.length === 0) {\n  // nothing to install; skip the call (k6 rejects empty arrays)\n} else {\n  context.addCookies(cookies);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Guard dynamic cookie lists with a length check before calling addCookies.","Log a warning when skipping so silent 'no cookies installed' states are visible.","Assert that login/setup steps actually produced cookies before replaying them."],"tags":["cookies","validation","browser-context"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}