{"record":{"id":"02eab7f1774875c4","repo":"grafana/k6","slug":"cookie-value-must-be-set-v","errorCode":null,"errorMessage":"cookie value must be set: %#v","messagePattern":"cookie value must be set: %#v","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/browser_context.go","lineNumber":469,"sourceCode":"}\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 {\n\t\t\tt := cdp.TimeSinceEpoch(time.Unix(c.Expires, 0))\n\t\t\tts = &t\n\t\t}\n\t\tcookiesToSet = append(cookiesToSet, &network.CookieParam{\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\tURL:      c.URL,","sourceCodeStart":451,"sourceCodeEnd":487,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/browser_context.go#L451-L487","documentation":"Validation error from BrowserContext.AddCookies: a cookie in the list has an empty Value. Together with the name check, k6 requires both fields to be non-empty strings before it will forward cookies to the browser via CDP Storage.setCookies; the failing cookie is printed with %#v.","triggerScenarios":"Calling browserContext.addCookies with a cookie object missing the value key, or with value: '' — including values that arrive empty from a previous step, e.g. reading document.cookie of a page that has not set the cookie yet, or a login response that returned no session token.","commonSituations":"Session-injection patterns where cookies are harvested from one context/page and replayed into another, but the harvest happened too early; API changes on the target site leaving the cookie value blank; misspelled 'value' key in a fixture.","solutions":["Populate value with a non-empty string, e.g. from the Set-Cookie response header of your login request.","If the value is legitimately empty in your flow, wait until the cookie is actually set before harvesting and re-adding it.","Filter or assert on cookie values before calling addCookies when the data source is dynamic."],"exampleFix":"// before\nconst sessionCookie = { name: 'sid', value: loginResponse.cookies.sid || '', url: 'https://example.com' };\ncontext.addCookies([sessionCookie]); // empty value -> error\n\n// after\nif (!loginResponse.cookies.sid) throw new Error('login did not set sid cookie');\ncontext.addCookies([{ name: 'sid', value: loginResponse.cookies.sid[0].value, url: 'https://example.com' }]);","handlingStrategy":"validation","validationCode":"if (!cookies.every((c) => typeof c.value === 'string' && c.value !== '')) {\n  throw new Error('every cookie needs a non-empty \"value\"');\n}\ncontext.addCookies(cookies);","typeGuard":"function isFilledCookie(c) {\n  return typeof c.name === 'string' && c.name !== '' &&\n         typeof c.value === 'string' && c.value !== '';\n}","tryCatchPattern":null,"preventionTips":["Fail fast with a clear message when a login step yields no session token instead of passing an empty value through.","Harvest cookies only after the page/site has actually set them.","Validate fixtures in CI so empty values never reach the browser."],"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"}