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
add example for using cookies from file and sample file with cookie structure
Ran Locar7404eab590a7
diff --git a/examples/twitter_cookies.txt b/examples/twitter_cookies.txtnew file mode 100644index 000000000..804318b75--- /dev/null+++ b/examples/twitter_cookies.txt@@ -0,0 +1,12 @@+[{+ "name": "auth_token",+ "value": "auth_token_cookie_value",+ "domain": ".x.com",+ "path": "/"+ },+{+ "name": "ct0",+ "value": "ct0_cookie_value",+ "domain": ".x.com",+ "path": "/"+}]diff --git a/examples/twitter_post_using_cookies.py b/examples/twitter_post_using_cookies.pynew file mode 100644index 000000000..f19890c9c--- /dev/null+++ b/examples/twitter_post_using_cookies.py@@ -0,0 +1,50 @@+import asyncio+import os++from dotenv import load_dotenv+from langchain_google_genai import ChatGoogleGenerativeAI+from pydantic import SecretStr++from browser_use import Agent+from browser_use import Agent+from browser_use.browser.browser import Browser, BrowserConfig+from browser_use.browser.context import BrowserContext, BrowserContextConfig+from browser_use.controller.service import Controller++load_dotenv()+api_key = os.getenv('GEMINI_API_KEY')+if not api_key:+ raise ValueError('GEMINI_API_KEY is not set')++llm = ChatGoogleGenerativeAI(model='gemini-2.0-flash-exp', api_key=SecretStr(api_key))+++browser = Browser(+ config=BrowserConfig(+ # chrome_instance_path='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',+ )+)++context = BrowserContext(+ browser = browser,+ config = BrowserContextConfig(cookies_file= "twitter_cookies.txt")+)+++++async def run_search():+ agent = Agent(+ browser_context=context,+ task=(+ 'go to https://x.com. write a new post with the text "browser-use ftw", and submit it'+ ),+ llm=llm,+ max_actions_per_step=4,+ tool_call_in_content=False+ )+ await agent.run(max_steps=25)+ input('Press Enter to close the browser...')++if __name__ == '__main__':+ asyncio.run(run_search())