MCPcopy
hub / github.com/reflex-dev/reflex / get_chrome_path

Function get_chrome_path

tests/integration/lighthouse_utils.py:809–857  ·  view source on GitHub ↗

Resolve the Chromium executable used by Lighthouse. Returns: The path to the Chromium executable Lighthouse should launch.

()

Source from the content-addressed store, hash-verified

807
808
809def get_chrome_path() -> str:
810 """Resolve the Chromium executable used by Lighthouse.
811
812 Returns:
813 The path to the Chromium executable Lighthouse should launch.
814 """
815 if chrome_path := os.environ.get(LIGHTHOUSE_CHROME_PATH_ENV_VAR):
816 resolved_path = Path(chrome_path).expanduser()
817 if not resolved_path.exists():
818 pytest.skip(
819 f"{LIGHTHOUSE_CHROME_PATH_ENV_VAR} points to a missing binary: {resolved_path}"
820 )
821 return str(resolved_path)
822
823 sync_api = pytest.importorskip(
824 "playwright.sync_api",
825 reason="Playwright is required to locate a Chromium binary for Lighthouse.",
826 )
827 candidates: list[Path] = []
828 with sync_api.sync_playwright() as playwright:
829 candidates.append(Path(playwright.chromium.executable_path))
830
831 browser_cache_dirs = [
832 Path.home() / ".cache" / "ms-playwright",
833 Path.home() / "Library" / "Caches" / "ms-playwright",
834 ]
835 if local_app_data := os.environ.get("LOCALAPPDATA"):
836 browser_cache_dirs.append(Path(local_app_data) / "ms-playwright")
837
838 browser_glob_patterns = [
839 "chromium_headless_shell-*/*/chrome-headless-shell",
840 "chromium-*/*/chrome",
841 "chromium-*/*/chrome.exe",
842 "chromium-*/*/Chromium.app/Contents/MacOS/Chromium",
843 ]
844 for cache_dir in browser_cache_dirs:
845 if not cache_dir.exists():
846 continue
847 for pattern in browser_glob_patterns:
848 candidates.extend(sorted(cache_dir.glob(pattern), reverse=True))
849
850 for resolved_path in candidates:
851 if resolved_path.exists():
852 return str(resolved_path)
853
854 pytest.skip(
855 "Playwright Chromium is not installed. "
856 "Run `uv run playwright install chromium --only-shell` first."
857 )
858
859
860def get_category_failure_details(report: dict[str, Any], category_name: str) -> str:

Callers 1

run_lighthouseFunction · 0.85

Calls 3

PathClass · 0.85
existsMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected