Download api/browser_backend.py from fsanyoto/loopable: direct link, hf CLI and curl.
- Browser
- Download file 1.43 kB
-
https://huggingface.co/spaces/fsanyoto/loopable/resolve/main/api/browser_backend.py
- Command line
-
hf download hf://spaces/fsanyoto/loopable/api/browser_backend.py
-
curl -L -o browser_backend.py https://huggingface.co/spaces/fsanyoto/loopable/resolve/main/api/browser_backend.py
1.43 kB
| """Select a browser executor without importing optional browser packages.""" | |
| import os | |
| from typing import Protocol | |
| class BrowserRefusal(RuntimeError): | |
| """Expose a fixed refusal code without provider text or arguments.""" | |
| def __init__(self, code="backend_unavailable"): | |
| self.code = code if code in {"backend_unavailable", "blocked_origin", "sign_in_failed", | |
| "read_only", "needs_code", "needs_human"} else "backend_unavailable" | |
| super().__init__(self.code) | |
| class BrowserBackend(Protocol): | |
| """Keep browser and credential operations behind the executor seam.""" | |
| def open(self, origin, *, origin_guard): ... | |
| def goto(self, url): ... | |
| def snapshot_text(self): ... | |
| def click(self, handle, *, executor=False): ... | |
| def type_handle(self, handle, text): ... | |
| def fill_secret(self, handle, value, *, origin): ... | |
| def close(self): ... | |
| def get_backend(): | |
| """Refuse an unconfigured executor before any model or browser call.""" | |
| selected = os.environ.get("AIOS_BROWSER_BACKEND", "").strip().lower() | |
| if selected == "local": | |
| from browser_local import LocalBrowser | |
| return LocalBrowser() | |
| if selected == "agentcore": | |
| try: | |
| from browser_agentcore import AgentCoreBackend | |
| return AgentCoreBackend() | |
| except Exception: | |
| raise BrowserRefusal() from None | |
| raise BrowserRefusal() | |