{"record":{"id":"d812330a89f5ef1e","repo":"grafana/k6","slug":"retrieving-cookies-w","errorCode":null,"errorMessage":"retrieving cookies: %w","messagePattern":"retrieving cookies: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/browser_context.go","lineNumber":534,"sourceCode":"}\n\n// Cookies returns all cookies.\n// Some of them can be added with the AddCookies method and some of them are\n// automatically taken from the browser context when it is created. And some of\n// them are set by the page, i.e., using the Set-Cookie HTTP header or via\n// JavaScript like document.cookie.\nfunc (b *BrowserContext) Cookies(urls ...string) ([]*Cookie, error) {\n\tb.logger.Debugf(\"BrowserContext:Cookies\", \"bctxid:%v\", b.id)\n\n\t// get cookies from this browser context.\n\tgetCookies := storage.\n\t\tGetCookies().\n\t\tWithBrowserContextID(b.id)\n\tnetworkCookies, err := getCookies.Do(\n\t\tcdp.WithExecutor(b.ctx, b.browser.conn),\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"retrieving cookies: %w\", err)\n\t}\n\t// return if no cookies found so we don't have to needlessly convert them.\n\t// users can still work with cookies using the empty slice.\n\t// like this: cookies.length === 0.\n\tif len(networkCookies) == 0 {\n\t\treturn nil, nil\n\t}\n\n\t// convert the received CDP cookies to the browser API format.\n\tcookies := make([]*Cookie, len(networkCookies))\n\tfor i, c := range networkCookies {\n\t\tcookies[i] = &Cookie{\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\tExpires:  int64(c.Expires),\n\t\t\tHTTPOnly: c.HTTPOnly,","sourceCodeStart":516,"sourceCodeEnd":552,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/browser/common/browser_context.go#L516-L552","documentation":"The CDP Storage.getCookies command failed while retrieving cookies for the browser context. This wraps a protocol-level error: lost WebSocket connection, closed browser, or an invalid context — not a cookie filtering problem.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/browser_context.go:534 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the browser connection is alive before calling cookies()","Re-create the context if it was closed","Inspect the wrapped CDP error for the exact protocol failure"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}