Resolves browser-harness home, config, runtime, tmp, and workspace directories with XDG and env overrides, creating private 0700 dirs. Reuse for consistent, secure app directory resolution.
# Source: https://github.com/browser-use/browser-harness | License: MIT | Copyright 2026 Browser Use
# Provided via justclaw.it.com; keep this notice with the code.
"""browser-harness filesystem layout."""
from __future__ import annotations
import os
import sys
from pathlib import Path
def home_dir() -> Path:
raw = os.environ.get("BH_HOME") or os.environ.get("BROWSER_HARNESS_HOME")
if raw:
return Path(raw).expanduser().resolve()
base = os.environ.get("XDG_CONFIG_HOME")
if base:
return (Path(base).expanduser() / "browser-harness").resolve()
return (Path.home() / ".config" / "browser-harness").resolve()
def ensure_private_dir(path: Path) -> Path:
existed = path.exists()
path.mkdir(parents=True, exist_ok=True)
if not existed and sys.platfor
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key