From 8ad30460ce80465aafac60bd4d61bed3db5b90f6 Mon Sep 17 00:00:00 2001 From: imnyang Date: Sat, 21 Jun 2025 15:32:17 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B0=9C=EC=84=A0=EB=90=9C=20=EC=BF=A0?= =?UTF-8?q?=ED=82=A4=20=EC=82=AD=EC=A0=9C=20=EB=B0=8F=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=EC=83=88=EB=A1=9C=20=EA=B3=A0=EC=B9=A8=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80=20-=20'clear=5Fcookies'=20?= =?UTF-8?q?=EC=95=A1=EC=85=98=EC=9D=84=20'Clear=20all=20cookies=20and=20re?= =?UTF-8?q?load=20page'=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20-=20=ED=98=84?= =?UTF-8?q?=EC=9E=AC=20=ED=8E=98=EC=9D=B4=EC=A7=80=EA=B0=80=20=EC=97=86?= =?UTF-8?q?=EA=B1=B0=EB=82=98=20=EC=9E=98=EB=AA=BB=EB=90=9C=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=EC=9D=BC=20=EA=B2=BD=EC=9A=B0=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EC=B6=94=EA=B0=80=20-=20=EC=BF=A0?= =?UTF-8?q?=ED=82=A4=20=EC=82=AD=EC=A0=9C=20=ED=9B=84=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=EC=83=88=EB=A1=9C=20=EA=B3=A0=EC=B9=A8=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EB=B0=8F=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?-=20extend=5Fplanner=5Fsystem=5Fmessage=EC=97=90=20OAuth=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EC=A1=B0=EA=B1=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/llm/prompt/__init__.py | 4 +++- main.py | 46 +++++++++++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/lib/llm/prompt/__init__.py b/lib/llm/prompt/__init__.py index e7e5752..0b09c9e 100644 --- a/lib/llm/prompt/__init__.py +++ b/lib/llm/prompt/__init__.py @@ -12,6 +12,8 @@ extend_planner_system_message = f""" - ✅ **초기 제공된 URL 내에서만 탐색** - ❌ 직접 이동하거나 추측한 링크 클릭 금지 - ⛔ 추측한 URL은 대답하거나 클릭하지 마세요 +- OAuth가 아닌 일반 로그인은 무시 +- OAuth가 없다면 **즉시 중단**하고 빈 배열 반환 --- @@ -77,7 +79,7 @@ extend_planner_system_message = f""" - **로그인 완료 후 authorize 등 버튼이 있으면 클릭** - GitHub같은 경우 Authorize 버튼이 뜨는데 오래걸릴 수 있음, 기다려야 할 수도 있음 - 만약 버튼을 눌러도 반응이 없을 경우 새로고침을 한번 해주세요. -4. 로그인 성공 후 clear_cookies를 사용해 모두 쿠키를 삭제하고 다음 SSO 버튼을 클릭합니다. +4. 로그인 성공 후 clear all cookies, then reload the page 모두 쿠키를 삭제하고 다음 SSO 버튼을 클릭합니다. 5. 다음 SSO 버튼으로 반복 진행 🛑 절대 아래와 같이 해석하지 말 것: diff --git a/main.py b/main.py index 89c4037..7f4d0dc 100644 --- a/main.py +++ b/main.py @@ -14,8 +14,7 @@ from browser_use import ( Controller, ActionResult, ) -from patchright.async_api import async_playwright as async_patchright -from playwright.async_api import Page +from patchright.async_api import async_playwright as async_patchright, Page from lib.utils import env_cheker from lib.utils.backend_client import notify_backend @@ -113,17 +112,44 @@ async def scan_one_url(url: str, skip_html_check: bool = False): initial_actions = [{"open_tab": {"url": target_url}}] 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: - # Clear all cookies for the current context + print("🔧 Executing clear_cookies action...") + + # Get the current page page = await browser_session.get_current_page() - await page.context.clear_cookies() - await page.context.clear_permissions() - await page.reload() + 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}") - print("🗑️ All cookies have been cleared.") - return ActionResult(extracted_content="All cookies have been cleared") - + try: + # Clear all cookies for the current context + await page.context.clear_cookies() + await page.context.clear_permissions() + await page.reload() + + print("🗑️ All cookies have been cleared and page reloaded.") + 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("Available actions:", list(controller.registry.registry.actions.keys())) try: