feat(bot_notifier, browser_automation): Add debug screenshot capability and improve browser automation
- Add `_send_photo_to_all()` async method to send photos to all admin chat IDs - Add `send_screenshot()` async method for sending debug screenshots via Telegram - Add `send_screenshot_sync()` synchronous wrapper for non-async code integration - Add `save_debug_screenshot()` function to capture and send screenshots when DEBUG_SCREENSHOT=true - Add debug screenshot directory creation and timestamp-based file naming - Improve browser initialization with automation detection bypass and realistic User-Agent - Add `--disable-blink-features=AutomationControlled` flag to hide automation characteristics - Set Mozilla/5.0 User-Agent string to mimic real Chrome browser - Enhance OpenAI account registration flow with better error handling and debugging - Add screenshot capture on page load failures and popup abnormalities - Improve popup detection with additional CSS and text selectors for better reliability - Increase timeout values for popup loading and form detection (1-3s to 2-5s) - Add multiple fallback selectors for login form detection (email input fields, welcome text) - Improve signup button retry logic with longer wait times and additional selector options - Add screenshot capture on critical failures (popup retry failed, signup button not found)
This commit is contained in:
@@ -200,6 +200,26 @@ class BotNotifier:
|
||||
except TelegramError:
|
||||
pass
|
||||
|
||||
async def _send_photo_to_all(self, photo_path: str, caption: str = ""):
|
||||
"""发送图片到所有管理员"""
|
||||
for chat_id in self.chat_ids:
|
||||
try:
|
||||
with open(photo_path, 'rb') as photo:
|
||||
await self.bot.send_photo(
|
||||
chat_id=chat_id,
|
||||
photo=photo,
|
||||
caption=caption,
|
||||
parse_mode="HTML"
|
||||
)
|
||||
except TelegramError:
|
||||
pass
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
async def send_screenshot(self, photo_path: str, caption: str = ""):
|
||||
"""发送调试截图"""
|
||||
await self._send_photo_to_all(photo_path, caption)
|
||||
|
||||
def queue_message(self, message: str, level: str = "info"):
|
||||
"""将消息加入发送队列 (非阻塞)"""
|
||||
if self._message_queue:
|
||||
@@ -292,6 +312,16 @@ def notify_sync(message: str, level: str = "info"):
|
||||
_notifier.queue_message(message, level)
|
||||
|
||||
|
||||
def send_screenshot_sync(photo_path: str, caption: str = ""):
|
||||
"""同步方式发送截图 (供非异步代码使用)"""
|
||||
if _notifier and _notifier._loop:
|
||||
import asyncio
|
||||
asyncio.run_coroutine_threadsafe(
|
||||
_notifier.send_screenshot(photo_path, caption),
|
||||
_notifier._loop
|
||||
)
|
||||
|
||||
|
||||
# ==================== 进度更新接口 (供 run.py 使用) ====================
|
||||
|
||||
def progress_start(team_name: str, total: int) -> Optional[ProgressTracker]:
|
||||
|
||||
Reference in New Issue
Block a user