Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
Validate skill install destination first
Laith Weinbergerf197139aec5d
diff --git a/browser_use/skill_cli/commands/skill.py b/browser_use/skill_cli/commands/skill.pyindex f7faabccf..adad84111 100644--- a/browser_use/skill_cli/commands/skill.py+++ b/browser_use/skill_cli/commands/skill.py@@ -108,6 +108,14 @@ def _resolve_output_paths(target: str, custom_path: Path | None) -> list[Path]:return [path / 'SKILL.md']+def _validate_output_paths(output_paths: list[Path]) -> None:+ for output_path in output_paths:+ if output_path.exists() and output_path.is_dir():+ raise RuntimeError(f'{output_path} is a directory, expected a SKILL.md file path.')+ if output_path.parent.exists() and not output_path.parent.is_dir():+ raise RuntimeError(f'{output_path.parent} is not a directory.')++def handle(argv: list[str]) -> int:parser = _build_parser()args = parser.parse_args(argv)@@ -125,6 +133,8 @@ def handle(argv: list[str]) -> int:if command == 'install':try:+ output_paths = _resolve_output_paths(args.target, args.path)+ _validate_output_paths(output_paths)if not args.no_install:_install_browser_harness_tool()text = _load_skill_text_from_browser_harness_cli()@@ -132,7 +142,7 @@ def handle(argv: list[str]) -> int:print(f'Error: {exc}', file=sys.stderr)return 1- for output_path in _resolve_output_paths(args.target, args.path):+ for output_path in output_paths:output_path.parent.mkdir(parents=True, exist_ok=True)output_path.write_text(text, encoding='utf-8')print(f'Installed Browser Use skill to {output_path}')diff --git a/tests/ci/test_browser_use_skill_install_docs.py b/tests/ci/test_browser_use_skill_install_docs.pyindex 6364e1714..6e233b8bc 100644--- a/tests/ci/test_browser_use_skill_install_docs.py+++ b/tests/ci/test_browser_use_skill_install_docs.py@@ -120,6 +120,32 @@ def test_browser_use_skill_cli_installs_browser_harness_package_skill(tmp_path):assert installed.read_text(encoding='utf-8') == expected+def test_browser_use_skill_cli_validates_destination_before_installing_harness(tmp_path):+ bin_dir = _fake_browser_harness_tools(tmp_path, '---\nname: browser-harness\n---\n\n# Browser Harness\n')+ blocking_file = tmp_path / 'not-a-directory'+ blocking_file.write_text('blocks skill directory creation', encoding='utf-8')++ uv_args = tmp_path / 'uv-args.txt'+ env = os.environ.copy()+ env['HOME'] = str(tmp_path / 'home')+ env['PATH'] = os.pathsep.join(part for part in (str(bin_dir), env.get('PATH', '')) if part)+ env['PYTHONPATH'] = os.pathsep.join(part for part in (str(ROOT), env.get('PYTHONPATH', '')) if part)+ env['UV_TOOL_INSTALL_ARGS_FILE'] = str(uv_args)++ result = subprocess.run(+ [sys.executable, '-m', 'browser_use.skill_cli.main', 'skill', 'install', '--path', str(blocking_file)],+ cwd=ROOT,+ env=env,+ capture_output=True,+ text=True,+ timeout=10,+ )++ assert result.returncode == 1+ assert 'is not a directory' in result.stderr+ assert not uv_args.exists()++def test_browser_use_skill_cli_uses_real_subcommand_index_when_session_is_named_skill(tmp_path):bin_dir = _fake_browser_harness_tools(tmp_path, '---\nname: browser-harness\n---\n\n# browser-harness\n')