{"record":{"id":"5dc963d700cdbb41","repo":"grafana/k6","slug":"setting-downloads-path-w","errorCode":null,"errorMessage":"setting downloads path: %w","messagePattern":"setting downloads path: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/browser_context.go","lineNumber":157,"sourceCode":"\t\tlogger:           logger,\n\t\ttimeoutSettings:  NewTimeoutSettings(nil),\n\t}\n\n\tif len(opts.Permissions) > 0 {\n\t\terr := b.GrantPermissions(opts.Permissions, GrantPermissionsOptions{})\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\n\tif err := b.AddInitScript(js.WebVitalIIFEScript); err != nil {\n\t\treturn nil, fmt.Errorf(\"adding web vital script to new browser context: %w\", err)\n\t}\n\tif err := b.AddInitScript(js.WebVitalInitScript); err != nil {\n\t\treturn nil, fmt.Errorf(\"adding web vital init script to new browser context: %w\", err)\n\t}\n\tif err := b.setDownloadsPath(opts.DownloadsPath); err != nil {\n\t\treturn nil, fmt.Errorf(\"setting downloads path: %w\", err)\n\t}\n\n\treturn &b, nil\n}\n\n// AddInitScript adds a script that will be initialized on all new pages.\nfunc (b *BrowserContext) AddInitScript(script string) error {\n\tb.logger.Debugf(\"BrowserContext:AddInitScript\", \"bctxid:%v\", b.id)\n\n\tb.evaluateOnNewDocumentSources = append(b.evaluateOnNewDocumentSources, script)\n\n\tfor _, p := range b.browser.getPages() {\n\t\tif err := p.evaluateOnNewDocument(script); err != nil {\n\t\t\treturn fmt.Errorf(\"adding init script to browser context: %w\", err)\n\t\t}\n\t}\n\n\treturn nil","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/browser/common/browser_context.go#L139-L175","documentation":"NewBrowserContext wraps setDownloadsPath, which assigns an explicit path directly (no error) or creates a temp directory when no downloadsPath is configured. This error therefore surfaces the temp-directory creation failure (see [615]) one level up, at the point the context is being constructed.","triggerScenarios":"Creating any browser context (including the default one at connect) with no explicit downloads path while the OS temp dir is unwritable, full, or fd-exhausted on the k6 runner.","commonSituations":"Read-only /tmp in CI containers; disk-full agents; TMPDIR pointing at a missing path; high concurrency exhausting file descriptors.","solutions":["Set TMPDIR to a writable directory with free space","Free disk space and inodes on the runner","Raise open-file limits (ulimit -n / container pids/fd limits)","Configure an explicit downloads path in the browser options so no temp dir is created"],"exampleFix":"# before\nk6 run script.js # runner has read-only /tmp -> setting downloads path: ...\n\n# after\nTMPDIR=/var/tmp/k6 k6 run script.js  # /var/tmp/k6 exists and is writable","handlingStrategy":"validation","validationCode":"# Ensure a usable downloads/temp location pre-run\ntest -w \"${TMPDIR:-/tmp}\" || export TMPDIR=/var/tmp/k6 && mkdir -p \"$TMPDIR\"\nk6 run script.js","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set TMPDIR to a known-writable path in CI","Configure an explicit downloads path in browser options","Check disk space and fd limits before browser-heavy runs"],"tags":["temp-dir","filesystem","browser-context","downloads","configuration"],"backgroundTag":"temp-dir-creation-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"}