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
fix: harden generated skill output
MagMueller872ca53d04bb
diff --git a/browser_use/skills/browser_use.py b/browser_use/skills/browser_use.pyindex 03001fced..1a1bb76b7 100644--- a/browser_use/skills/browser_use.py+++ b/browser_use/skills/browser_use.py@@ -6,26 +6,34 @@ import refrom importlib import resourcesfrom pathlib import Path-OPENCLAW_METADATA = (- 'metadata:\n'- ' {\n'- ' "openclaw":\n'- ' {\n'- ' "emoji": "🌐",\n'- ' "requires": { "bins": ["browser-use"] },\n'- ' "install":\n'- ' [\n'- ' {\n'- ' "id": "uv",\n'- ' "kind": "uv",\n'- ' "package": "browser-use",\n'- ' "bins": ["browser-use"],\n'- ' "label": "Install Browser Use CLI (uv)",\n'- ' },\n'- ' ],\n'- ' },\n'- ' }'-)++def _canonical_skill_path() -> Path:+ return Path(__file__).resolve().parent / 'browser-use' / 'SKILL.md'+++def _canonical_metadata_lines() -> list[str]:+ """Read the metadata block from the canonical Browser Use skill."""+ skill_path = _canonical_skill_path()+ if not skill_path.exists():+ return []++ try:+ _, frontmatter, _ = skill_path.read_text(encoding='utf-8').split('---\n', 2)+ except ValueError:+ return []++ lines = frontmatter.splitlines()+ try:+ start = lines.index('metadata:')+ except ValueError:+ return []++ end = len(lines)+ for index in range(start + 1, len(lines)):+ if lines[index] and not lines[index][0].isspace():+ end = index+ break+ return lines[start:end]def as_browser_use_skill(text: str) -> str:@@ -63,7 +71,7 @@ def as_browser_use_skill(text: str) -> str:if not any(line.startswith('homepage:') for line in lines):lines.append('homepage: https://browser-use.com')if not any(line.startswith('metadata:') for line in lines):- lines.extend(OPENCLAW_METADATA.splitlines())+ lines.extend(_canonical_metadata_lines())body = body.replace('# browser-harness', '# Browser Use', 1).replace('# Browser Harness', '# Browser Use', 1)# Rebrand every mention except repo URLs (github.com/browser-use/browser-harness/...)@@ -75,7 +83,7 @@ def as_browser_use_skill(text: str) -> str:def skill_text() -> str:"""Return the canonical Browser Use skill."""- skill_path = Path(__file__).resolve().parent / 'browser-use' / 'SKILL.md'+ skill_path = _canonical_skill_path()if skill_path.exists():return skill_path.read_text(encoding='utf-8')diff --git a/browser_use/skills/install.py b/browser_use/skills/install.pyindex 6b44d806f..9d67ff3ad 100644--- a/browser_use/skills/install.py+++ b/browser_use/skills/install.py@@ -152,11 +152,16 @@ def _print_skill_text(text: str) -> None:# Windows consoles commonly default to cp1252, which cannot encode the emoji# in OpenClaw skill metadata. Prefer UTF-8 when stdout supports reconfiguration.reconfigure = getattr(sys.stdout, 'reconfigure', None)+ reconfigured = Falseif callable(reconfigure):try:- reconfigure(encoding='utf-8')- except OSError:+ reconfigure(encoding='utf-8', errors='replace')+ reconfigured = True+ except (OSError, TypeError, ValueError):pass+ if not reconfigured:+ encoding = getattr(sys.stdout, 'encoding', None) or 'utf-8'+ text = text.encode(encoding, errors='replace').decode(encoding)print(text, end='')diff --git a/tests/ci/test_browser_use_skill_install_docs.py b/tests/ci/test_browser_use_skill_install_docs.pyindex 562fc9c09..f83e6c3e6 100644--- a/tests/ci/test_browser_use_skill_install_docs.py+++ b/tests/ci/test_browser_use_skill_install_docs.py@@ -150,3 +150,41 @@ def test_skill_show_reconfigures_windows_stdout_to_utf8(monkeypatch):windows_stdout.flush()assert buffer.getvalue().decode('utf-8') == 'Browser Use 🌐\n'+++def test_skill_show_replaces_unsupported_characters_without_reconfigure(monkeypatch):+ from browser_use.skills import install++ class LegacyStdout:+ encoding = 'cp1252'++ def __init__(self):+ self.buffer = BytesIO()++ def write(self, text: str) -> int:+ data = text.encode(self.encoding)+ self.buffer.write(data)+ return len(text)++ class FailingReconfigureStdout(LegacyStdout):+ def reconfigure(self, **kwargs):+ raise OSError('legacy stream cannot be reconfigured')++ for legacy_stdout in (LegacyStdout(), FailingReconfigureStdout()):+ monkeypatch.setattr(sys, 'stdout', legacy_stdout)+ install._print_skill_text('Browser Use 🌐\n')++ assert legacy_stdout.buffer.getvalue().decode('cp1252') == 'Browser Use ?\n'+++def test_browser_use_alias_sources_metadata_from_canonical_skill():+ from browser_use.skills import browser_use++ canonical = browser_use.skill_text()+ _, canonical_frontmatter, _ = canonical.split('---\n', 2)+ metadata = canonical_frontmatter[canonical_frontmatter.index('metadata:') :]++ converted = browser_use.as_browser_use_skill('---\nname: browser-harness\n---\n\n# Browser Harness\n')+ _, converted_frontmatter, _ = converted.split('---\n', 2)++ assert metadata in converted_frontmatter