diff --git a/.env.example b/.env.example index ed8f925..8e60d58 100644 --- a/.env.example +++ b/.env.example @@ -24,6 +24,7 @@ ONKERNEL_API_KEY= REBROWSER_API_KEY= STEEL_API_KEY= DRIVER_API_KEY= +STRING_API_KEY= # Optional: save scores and text/tool traces in your private Laminar project # Install with: uv sync --frozen --extra laminar diff --git a/README.md b/README.md index ef93f91..972cb2a 100644 --- a/README.md +++ b/README.md @@ -286,7 +286,7 @@ cp .env.example .env uv run python run_eval.py --benchmark Stealth_Bench_V1 --browser ``` -Available providers: `browser-use-cloud`, `anchor`, `browserbase`, `browserless`, `hyperbrowser`, `onkernel`, `steel`, `local_headful`, `local_headless` +Available providers: `browser-use-cloud`, `anchor`, `browserbase`, `browserless`, `driver`, `hyperbrowser`, `onkernel`, `rebrowser`, `steel`, `string`, `local_headful`, `local_headless` **Results and official data:** [`stealth_bench/`](stealth_bench/) diff --git a/browsers/__init__.py b/browsers/__init__.py index 3784c1d..b70871d 100644 --- a/browsers/__init__.py +++ b/browsers/__init__.py @@ -15,6 +15,7 @@ onkernel, rebrowser, steel, + string, ) PROVIDERS = [ @@ -28,6 +29,7 @@ "onkernel", "rebrowser", "steel", + "string", ] BROWSERS = { @@ -42,6 +44,7 @@ "onkernel": onkernel, "rebrowser": rebrowser, "steel": steel, + "string": string, } diff --git a/browsers/string.py b/browsers/string.py new file mode 100644 index 0000000..0783c8d --- /dev/null +++ b/browsers/string.py @@ -0,0 +1,37 @@ +"""String -- https://usestring.ai + +Default (residential) proxy and captcha solving. +Requires: STRING_API_KEY env var. STRING_CDP_URL optionally overrides the endpoint. + +There is no session API: connecting to the CDP WebSocket starts a fresh browser, +and closing the connection (browser.stop()) ends it. The API key is sent as an +Authorization header on the WebSocket handshake rather than in the URL. +""" + +import os +from urllib.parse import parse_qsl, urlencode, urlsplit, urlunsplit + +DEFAULT_CDP_URL = "wss://request.usestring.ai/v1/wss" + +SETTINGS = {"solveCaptcha": "true"} + + +def headers() -> dict[str, str]: + return {"Authorization": f"Bearer {os.environ['STRING_API_KEY']}"} + + +async def connect() -> str: + parts = urlsplit(os.environ.get("STRING_CDP_URL") or DEFAULT_CDP_URL) + # Keep the override's own parameters as given, blank and repeated ones + # included, and replace only the keys this benchmark sets. + query = [ + (key, value) + for key, value in parse_qsl(parts.query, keep_blank_values=True) + if key not in SETTINGS + ] + query.extend(SETTINGS.items()) + return urlunsplit(parts._replace(query=urlencode(query))) + + +async def disconnect() -> None: + pass diff --git a/frameworks/browser_use/run_task.py b/frameworks/browser_use/run_task.py index 6f4847e..ccb1964 100644 --- a/frameworks/browser_use/run_task.py +++ b/frameworks/browser_use/run_task.py @@ -49,7 +49,8 @@ async def execute( try: cdp_url = await provider.connect() if cdp_url: - browser = Browser(cdp_url=cdp_url) + headers = getattr(provider, "headers", None) + browser = Browser(cdp_url=cdp_url, headers=headers() if headers else None) else: headless = getattr(provider, "HEADLESS", True) browser = Browser(headless=headless) diff --git a/run_eval.py b/run_eval.py index e584809..bf4565a 100644 --- a/run_eval.py +++ b/run_eval.py @@ -126,7 +126,9 @@ async def create_browser( cdp_url = await browser_provider.connect() if cdp_url is None: return Browser(headless=getattr(browser_provider, "HEADLESS", True)) - return Browser(cdp_url=cdp_url) + # Providers that authenticate the CDP handshake expose headers(). + headers = getattr(browser_provider, "headers", None) + return Browser(cdp_url=cdp_url, headers=headers() if headers else None) async def run_task(