{"record":{"id":"623884747499b762","repo":"projectdiscovery/katana","slug":"could-not-create-temporary-chrome-data-directory","errorCode":null,"errorMessage":"could not create temporary chrome data directory","messagePattern":"could not create temporary chrome data directory","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/engine/headless/browser/browser.go","lineNumber":386,"sourceCode":"\treturn err\n}\n\nfunc (l *Launcher) createBrowserPageFunc() (*BrowserPage, error) {\n\t// When using ChromeWSUrl, we don't need temp directories\n\t// since we're connecting to an existing browser\n\tvar tempDir string\n\tshouldCleanupTempDir := false\n\n\tif l.opts.ChromeWSUrl == \"\" {\n\t\tif l.opts.UserDataDir != \"\" {\n\t\t\t// Use user-provided data directory (preserve sessions/cookies)\n\t\t\ttempDir = l.opts.UserDataDir\n\t\t\tshouldCleanupTempDir = false\n\t\t} else if l.opts.ChromeUser != nil {\n\t\t\tvar err error\n\t\t\ttempDir, err = os.MkdirTemp(l.opts.ChromeUser.HomeDir, \"chrome-data-*\")\n\t\t\tif err != nil {\n\t\t\t\treturn nil, errors.Wrap(err, \"could not create temporary chrome data directory\")\n\t\t\t}\n\n\t\t\tuid, err := strconv.Atoi(l.opts.ChromeUser.Uid)\n\t\t\tif err != nil {\n\t\t\t\t_ = os.RemoveAll(tempDir)\n\t\t\t\treturn nil, errors.Wrap(err, \"invalid user ID\")\n\t\t\t}\n\t\t\tgid, err := strconv.Atoi(l.opts.ChromeUser.Gid)\n\t\t\tif err != nil {\n\t\t\t\t_ = os.RemoveAll(tempDir)\n\t\t\t\treturn nil, errors.Wrap(err, \"invalid group ID\")\n\t\t\t}\n\t\t\tif err := os.Chown(tempDir, uid, gid); err != nil {\n\t\t\t\t_ = os.RemoveAll(tempDir)\n\t\t\t\treturn nil, errors.Wrap(err, \"could not change ownership of chrome data directory\")\n\t\t\t}\n\t\t\tshouldCleanupTempDir = true\n\t\t} else {","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/projectdiscovery/katana/blob/e3e742739c3746f085943ce918fb4e2b8daf6fe6/pkg/engine/headless/browser/browser.go#L368-L404","documentation":"Thrown when os.MkdirTemp fails to create a temporary Chrome profile directory inside ChromeUser.HomeDir. Katana needs a writable per-run data dir to launch headless Chrome; without it the page cannot start. The wrap preserves the underlying OS error (e.g. permission denied, no such directory).","triggerScenarios":"LauncherOptions.ChromeUser is set (non-nil) and os.MkdirTemp(l.opts.ChromeUser.HomeDir, \"chrome-data-*\") returns an error — HomeDir does not exist, is not writable by the current process, or the filesystem is full/read-only.","commonSituations":"Running katana as a different user than the owner of ChromeUser.HomeDir; container images where the chrome user's home was never created; read-only root filesystem; disk quota exhausted; account missing on the host so user.Lookup-derived HomeDir is invalid.","solutions":["Verify ChromeUser.HomeDir exists and is writable by the process user (ls -ld; touch a test file).","If running in Docker, ensure the home directory is created (useradd -m) or mount a writable volume there.","Run the process as the ChromeUser or grant write permission on HomeDir (chown/chmod, securityContext).","Check disk space (df -h) and that the filesystem is not mounted read-only.","If a dedicated chrome user is unnecessary, leave ChromeUser nil so katana uses the default system temp dir."],"exampleFix":"// before\nu, _ := user.Lookup(\"chrome\")\nopts.ChromeUser = u // home may not exist\n// after\nif _, err := os.Stat(u.HomeDir); err != nil {\n    os.MkdirAll(u.HomeDir, 0o700)\n    os.Chown(u.HomeDir, mustAtoi(u.Uid), mustAtoi(u.Gid))\n}\nopts.ChromeUser = u","handlingStrategy":"validation","validationCode":"if opts.ChromeUser != nil {\n    if _, err := os.Stat(opts.ChromeUser.HomeDir); err != nil {\n        os.MkdirAll(opts.ChromeUser.HomeDir, 0o700) // or fall back to ChromeUser=nil\n    }\n}","typeGuard":"func usableDir(p string) bool {\n    fi, err := os.Stat(p)\n    return err == nil && fi.IsDir()\n}","tryCatchPattern":"page, err := l.createBrowserPageFunc(...)\nif err != nil && strings.Contains(err.Error(), \"temporary chrome data directory\") {\n    l.opts.ChromeUser = nil // fall back to default temp dir\n    page, err = l.createBrowserPageFunc(...)\n}","preventionTips":["Create and chown the chrome user's home directory in your image/entrypoint before launching.","Run the process under the same user whose home you pass as ChromeUser.","Monitor disk space on the volume hosting the home dir.","Only set ChromeUser when a dedicated chrome user is actually required."],"tags":["filesystem","permissions","chrome","headless"],"backgroundTag":"temp-dir-creation-failed","analyzedSha":"e3e742739c3746f085943ce918fb4e2b8daf6fe6","analyzedAt":"2026-09-03T14:55:13.248Z","contentChangedAt":"2026-09-03T14:55:13.248Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}