{"record":{"id":"b2dc1b7d443e5028","repo":"grafana/k6","slug":"cookie-name-must-be-set-v","errorCode":null,"errorMessage":"cookie name must be set: %#v","messagePattern":"cookie name must be set: %#v","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/browser_context.go","lineNumber":466,"sourceCode":"\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 {\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,","sourceCodeStart":448,"sourceCodeEnd":484,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/browser_context.go#L448-L484","documentation":"Validation error from BrowserContext.AddCookies: a cookie in the provided list has an empty name field. Before converting cookies to CDP network.CookieParam, k6 requires every cookie to have a non-empty Name; the offending cookie struct is printed with %#v so you can identify it. The whole addCookies call fails atomically.","triggerScenarios":"Calling browserContext.addCookies([{ value: 'abc', url: 'https://example.com' }]) or with a cookie whose name is undefined/null/empty string (undefined struct fields unmarshal to empty in the JS-to-Go mapping).","commonSituations":"Typos in the cookie object keys (e.g. key 'Name' or 'cookieName' instead of 'name' — keys are case-sensitive per the js tags); building cookies dynamically where the name comes from a variable that is sometimes empty; data-driven tests consuming malformed cookie fixtures.","solutions":["Set a non-empty name on every cookie: { name: 'session', value: '...', url: 'https://example.com' }.","Check for exact, lowercase field names: name, value, url, domain, path, expires, httpOnly, secure, sameSite.","Validate/filter the array before the call when cookies come from external data."],"exampleFix":"// before\ncontext.addCookies([{ nane: 'session', value: 'abc', url: 'https://example.com' }]); // typo -> empty name\n\n// after\ncontext.addCookies([{ name: 'session', value: 'abc', url: 'https://example.com' }]);","handlingStrategy":"validation","validationCode":"function hasValidName(c) {\n  return typeof c.name === 'string' && c.name.length > 0;\n}\nif (!cookies.every(hasValidName)) {\n  throw new Error('every cookie needs a non-empty \"name\"');\n}\ncontext.addCookies(cookies);","typeGuard":"function isCookieWithName(c) {\n  return c != null && typeof c === 'object' && typeof c.name === 'string' && c.name !== ''; \n}","tryCatchPattern":null,"preventionTips":["Use the exact lowercase keys k6 expects: name, value, url, domain, path, expires, httpOnly, secure, sameSite.","Lint cookie fixtures for required fields in CI.","Beware 'nane'/'Name' typos — field names are case-sensitive."],"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"}