whs-authz-authn/browser-use-oauth
Watch
1
0
Fork
You've already forked browser-use-oauth
0
mirror of https://github.com/j93es/browser-use-oauth.git synced 2026-10-12 07:21:21 +09:00

feat: 개선된 쿠키 삭제 및 페이지 새로 고침 기능 추가

- 'clear_cookies' 액션을 'Clear all cookies and reload page'로 변경
- 현재 페이지가 없거나 잘못된 타입일 경우 오류 처리 추가
- 쿠키 삭제 후 페이지 새로 고침 성공 메시지 및 오류 메시지 추가
- extend_planner_system_message에 OAuth 관련 조건 추가
This commit is contained in:
암냥 2025-06-21 15:32:17 +09:00
commit 8ad30460ce
2 changed files with 39 additions and 11 deletions

View file

@ -12,6 +12,8 @@ extend_planner_system_message = f"""
- ✅ **초기 제공된 URL 내에서만 탐색** - ✅ **초기 제공된 URL 내에서만 탐색**
- ❌ 직접 이동하거나 추측한 링크 클릭 금지 - ❌ 직접 이동하거나 추측한 링크 클릭 금지
- ⛔ 추측한 URL은 대답하거나 클릭하지 마세요 - ⛔ 추측한 URL은 대답하거나 클릭하지 마세요
- OAuth가 아닌 일반 로그인은 무시
- OAuth가 없다면 **즉시 중단**하고 빈 배열 반환
--- ---
@ -77,7 +79,7 @@ extend_planner_system_message = f"""
- **로그인 완료 후 authorize 등 버튼이 있으면 클릭** - **로그인 완료 후 authorize 등 버튼이 있으면 클릭**
- GitHub같은 경우 Authorize 버튼이 뜨는데 오래걸릴 수 있음, 기다려야 할 수도 있음 - GitHub같은 경우 Authorize 버튼이 뜨는데 오래걸릴 수 있음, 기다려야 할 수도 있음
- 만약 버튼을 눌러도 반응이 없을 경우 새로고침을 한번 해주세요. - 만약 버튼을 눌러도 반응이 없을 경우 새로고침을 한번 해주세요.
4. 로그인 성공 후 clear_cookies를 사용해 모두 쿠키를 삭제하고 다음 SSO 버튼을 클릭합니다. 4. 로그인 성공 후 clear all cookies, then reload the page 모두 쿠키를 삭제하고 다음 SSO 버튼을 클릭합니다.
5. 다음 SSO 버튼으로 반복 진행 5. 다음 SSO 버튼으로 반복 진행
🛑 절대 아래와 같이 해석하지 말 것: 🛑 절대 아래와 같이 해석하지 말 것:

38
main.py
View file

@ -14,8 +14,7 @@ from browser_use import (
Controller, Controller,
ActionResult, ActionResult,
) )
from patchright.async_api import async_playwright as async_patchright from patchright.async_api import async_playwright as async_patchright, Page
from playwright.async_api import Page
from lib.utils import env_cheker from lib.utils import env_cheker
from lib.utils.backend_client import notify_backend from lib.utils.backend_client import notify_backend
@ -113,16 +112,43 @@ async def scan_one_url(url: str, skip_html_check: bool = False):
initial_actions = [{"open_tab": {"url": target_url}}] initial_actions = [{"open_tab": {"url": target_url}}]
controller = Controller(output_model=model.BaseModel, exclude_actions=['search_google']) controller = Controller(output_model=model.BaseModel, exclude_actions=['search_google'])
@controller.action('clear_cookies') @controller.action('Clear all cookies and reload page')
async def clear_cookies(browser_session: BrowserSession) -> ActionResult: async def clear_cookies(browser_session: BrowserSession) -> ActionResult:
# Clear all cookies for the current context print("🔧 Executing clear_cookies action...")
# Get the current page
page = await browser_session.get_current_page() page = await browser_session.get_current_page()
if not page:
print("❌ 현재 페이지를 찾을 수 없습니다. 쿠키를 지울 수 없습니다.")
return ActionResult(
extracted_content="현재 페이지를 찾을 수 없습니다.",
include_in_memory=True
)
if not isinstance(page, Page):
print("❌ 현재 페이지가 올바른 타입이 아닙니다. 쿠키를 지울 수 없습니다.")
return ActionResult(
extracted_content="현재 페이지가 올바른 타입이 아닙니다.",
include_in_memory=True
)
print(f"🔍 현재 페이지 URL: {page.url}")
try:
# Clear all cookies for the current context
await page.context.clear_cookies() await page.context.clear_cookies()
await page.context.clear_permissions() await page.context.clear_permissions()
await page.reload() await page.reload()
print("🗑️ All cookies have been cleared.") print("🗑️ All cookies have been cleared and page reloaded.")
return ActionResult(extracted_content="All cookies have been cleared") return ActionResult(
extracted_content="Successfully cleared all cookies and reloaded the page",
include_in_memory=True
)
except Exception as e:
print(f"❌ Error clearing cookies: {e}")
return ActionResult(
extracted_content=f"Failed to clear cookies: {str(e)}",
include_in_memory=True
)
print("🤖 LLM 모델 초기화 및 스캔 시작...") print("🤖 LLM 모델 초기화 및 스캔 시작...")
print("Available actions:", list(controller.registry.registry.actions.keys())) print("Available actions:", list(controller.registry.registry.actions.keys()))