{"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/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/browser/common/browser_context.go#L451-L487","documentation":"Client-side validation in AddCookies: a cookie with a non-empty name was given an empty Value, and k6 requires a non-empty value even though empty-valued cookies technically exist in HTTP. The cookie is printed with %#v. The batch is rejected before any CDP call.","triggerScenarios":"browserContext.addCookies([{ name: 'session', url: '...' }]) with value omitted; value computed from a response header or variable that turned out empty; value field mis-keyed (e.g. val).","commonSituations":"Mapping Set-Cookie headers where some cookie had no '=' value; values derived from JSON fixtures with missing properties; intentionally trying to set a valueless flag-style cookie (not supported here).","solutions":["Give every cookie a non-empty value, even a placeholder like '-' if the test only needs the name present","Validate the array up front: name and value must be non-empty strings","Fix the upstream extraction so empty values are filtered out or defaulted"],"exampleFix":"// before\nctx.addCookies([{ name: 'session', url: 'https://example.com' }]); // value missing\n\n// after\nctx.addCookies([{ name: 'session', value: 'abc123', url: 'https://example.com' }]);","handlingStrategy":"validation","validationCode":"function validateCookies(cookies) {\n  for (const c of cookies) {\n    if (typeof c.value !== 'string' || c.value === '') {\n      throw new Error(`cookie '${c.name}' missing value`);\n    }\n  }\n}\nvalidateCookies([{ name: 'session', value: 'abc', url: 'https://example.com' }]);\nctx.addCookies([{ name: 'session', value: 'abc', url: 'https://example.com' }]);","typeGuard":"const isValuedCookie = (c) =>\n  c != null && typeof c === 'object' && typeof c.value === 'string' && c.value.length > 0;","tryCatchPattern":null,"preventionTips":["k6 requires non-empty values even for flag-style cookies — use a placeholder like '-'","Filter out valueless cookies when importing from document.cookie-style sources","Validate name AND value together in one pre-call check"],"tags":["browser","cookies","validation"],"backgroundTag":"cookie-validation-failed","analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}