[Add] browser-use and main.py

This commit is contained in:
tv0924@icloud.com 2025-05-18 21:57:54 +09:00
commit 96914d44ac
221 changed files with 30952 additions and 1 deletions

View file

@ -0,0 +1,37 @@
import asyncio
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
from dotenv import load_dotenv
load_dotenv()
from langchain_openai import ChatOpenAI
from browser_use import Agent, Browser, BrowserConfig
browser = Browser(
config=BrowserConfig(
# NOTE: you need to close your chrome browser - so that this can open your browser in debug mode
browser_binary_path='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
)
)
async def main():
agent = Agent(
task='In docs.google.com write my Papa a quick letter',
llm=ChatOpenAI(model='gpt-4o'),
browser=browser,
)
await agent.run()
await browser.close()
input('Press Enter to close...')
if __name__ == '__main__':
asyncio.run(main())

View file

@ -0,0 +1,83 @@
import asyncio
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
from dotenv import load_dotenv
load_dotenv()
from langchain_openai import ChatOpenAI
from browser_use import Agent, Browser, BrowserConfig, BrowserContextConfig
llm = ChatOpenAI(model='gpt-4o')
browser = Browser(
config=BrowserConfig(
headless=False,
disable_security=False,
keep_alive=True,
new_context_config=BrowserContextConfig(
keep_alive=True,
disable_security=False,
),
)
)
async def main():
agent = Agent(
task="""
Go to https://bot-detector.rebrowser.net/ and verify that all the bot checks are passed.
""",
llm=llm,
browser=browser,
)
await agent.run()
input('Press Enter to continue to the next test...')
agent = Agent(
task="""
Go to https://www.webflow.com/ and verify that the page is not blocked by a bot check.
""",
llm=llm,
browser=browser,
)
await agent.run()
input('Press Enter to continue to the next test...')
agent = Agent(
task="""
Go to https://www.okta.com/ and verify that the page is not blocked by a bot check.
""",
llm=llm,
browser=browser,
)
await agent.run()
agent = Agent(
task="""
Go to https://abrahamjuliot.github.io/creepjs/ and verify that the detection score is >50%.
""",
llm=llm,
browser=browser,
)
await agent.run()
input('Press Enter to close the browser...')
agent = Agent(
task="""
Go to https://nowsecure.nl/ check the "I'm not a robot" checkbox.
""",
llm=llm,
browser=browser,
)
await agent.run()
input('Press Enter to close the browser...')
if __name__ == '__main__':
asyncio.run(main())

View file

@ -0,0 +1,61 @@
"""
Simple demonstration of the CDP feature.
To test this locally, follow these steps:
1. Create a shortcut for the executable Chrome file.
2. Add the following argument to the shortcut:
- On Windows: `--remote-debugging-port=9222`
3. Open a web browser and navigate to `http://localhost:9222/json/version` to verify that the Remote Debugging Protocol (CDP) is running.
4. Launch this example.
@dev You need to set the `GOOGLE_API_KEY` environment variable before proceeding.
"""
import asyncio
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
from dotenv import load_dotenv
load_dotenv()
from langchain_google_genai import ChatGoogleGenerativeAI
from pydantic import SecretStr
from browser_use import Agent, Controller
from browser_use.browser.browser import Browser, BrowserConfig
api_key = os.getenv('GOOGLE_API_KEY')
if not api_key:
raise ValueError('GOOGLE_API_KEY is not set')
browser = Browser(
config=BrowserConfig(
headless=False,
cdp_url='http://localhost:9222',
)
)
controller = Controller()
async def main():
task = 'In docs.google.com write my Papa a quick thank you for everything letter \n - Magnus'
task += ' and save the document as pdf'
model = ChatGoogleGenerativeAI(model='gemini-2.0-flash-exp', api_key=SecretStr(str(api_key)))
agent = Agent(
task=task,
llm=model,
controller=controller,
browser=browser,
)
await agent.run()
await browser.close()
input('Press Enter to close...')
if __name__ == '__main__':
asyncio.run(main())