From 14f6dfc29dab1f684a400e2287455a1b21aeb0d6 Mon Sep 17 00:00:00 2001 From: yeongpin Date: Thu, 6 Mar 2025 11:01:34 +0800 Subject: [PATCH] fix: Improve Browser Startup and Error Handling - Add `--no-sandbox` flag to resolve browser startup issues - Enhance error handling in temp email creation - Update localization files with new email-related messages - Improve translation support for email creation process --- .env | 4 ++-- CHANGELOG.md | 6 ++++++ locales/en.json | 3 ++- locales/zh_cn.json | 3 ++- locales/zh_tw.json | 3 ++- new_signup.py | 3 +++ new_tempemail.py | 40 +++++++++++++++++++++++++++++----------- 7 files changed, 46 insertions(+), 16 deletions(-) diff --git a/.env b/.env index f18a0b4..2de03d8 100644 --- a/.env +++ b/.env @@ -1,2 +1,2 @@ -version=1.5.02 -VERSION=1.5.02 +version=1.5.03 +VERSION=1.5.03 diff --git a/CHANGELOG.md b/CHANGELOG.md index f877c8a..d802030 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## v1.5.03 +1. HOTFIX: Stuck on starting browser | 修復啟動瀏覽器卡住問題 +2. Small Fix: Error Handling | 小修錯誤處理 +3. Small Fix: Translation | 小修翻譯 +4. Small Fix: Performance | 小修性能 + ## v1.5.02 1. Add: Generate Random Name Alias | 增加生成隨機真實姓名 2. Add: Realistic Name Input | 增加真實姓名輸入 diff --git a/locales/en.json b/locales/en.json index 67b83fd..6356d39 100644 --- a/locales/en.json +++ b/locales/en.json @@ -224,7 +224,8 @@ "blocked_domains_loaded_timeout": "Blocked Domains Loaded Timeout: {timeout}s", "blocked_domains_loaded_timeout_error": "Blocked Domains Loaded Timeout Error: {error}", "available_domains_loaded": "Available Domains Loaded: {count}", - "domains_filtered": "Domains Filtered: {count}" + "domains_filtered": "Domains Filtered: {count}", + "trying_to_create_email": "Trying to create email: {email}" }, "update": { "title": "Disable Cursor Auto Update", diff --git a/locales/zh_cn.json b/locales/zh_cn.json index 4ded99e..108abeb 100644 --- a/locales/zh_cn.json +++ b/locales/zh_cn.json @@ -221,7 +221,8 @@ "blocked_domains_loaded_timeout": "加载被屏蔽的域名超时: {timeout}秒", "blocked_domains_loaded_timeout_error": "加载被屏蔽的域名超时错误: {error}", "available_domains_loaded": "获取到 {count} 个可用域名", - "domains_filtered": "过滤后剩餘 {count} 個可用域名" + "domains_filtered": "过滤后剩餘 {count} 個可用域名", + "trying_to_create_email": "尝试创建邮箱: {email}" }, "update": { "title": "禁用 Cursor 自动更新", diff --git a/locales/zh_tw.json b/locales/zh_tw.json index e63f4b3..9ceafb9 100644 --- a/locales/zh_tw.json +++ b/locales/zh_tw.json @@ -202,7 +202,8 @@ "blocked_domains_loaded_timeout": "加載被屏蔽的域名超時: {timeout}秒", "blocked_domains_loaded_timeout_error": "加載被屏蔽的域名超時錯誤: {error}", "available_domains_loaded": "獲取到 {count} 個可用域名", - "domains_filtered": "過濾後剩餘 {count} 個可用域名" + "domains_filtered": "過濾後剩餘 {count} 個可用域名", + "trying_to_create_email": "嘗試創建郵箱: {email}" }, "update": { "title": "禁用 Cursor 自动更新", diff --git a/new_signup.py b/new_signup.py index 27b2561..fe34bbf 100644 --- a/new_signup.py +++ b/new_signup.py @@ -100,6 +100,9 @@ def setup_driver(translator=None): # 使用无痕模式 co.set_argument("--incognito") + + # 设置随机端口 + co.set_argument("--no-sandbox") # 设置随机端口 co.auto_port() diff --git a/new_tempemail.py b/new_tempemail.py index 4b5a7b2..4f1ef33 100644 --- a/new_tempemail.py +++ b/new_tempemail.py @@ -66,13 +66,13 @@ class NewTempEmail: return filtered_domains def _generate_credentials(self): - """生成随机用户名和密码""" + """generate random username and password""" username = ''.join(random.choices(string.ascii_lowercase + string.digits, k=10)) password = ''.join(random.choices(string.ascii_letters + string.digits + string.punctuation, k=12)) return username, password def create_email(self): - """创建临时邮箱""" + """create temporary email""" try: if self.translator: print(f"{Fore.CYAN}ℹ️ {self.translator.get('email.visiting_site').replace('mail.tm', self.selected_service['name'])}{Style.RESET_ALL}") @@ -135,7 +135,10 @@ class NewTempEmail: selected_domain = filtered_domains[0]['domain'] email = f"{username}@{selected_domain}" - print(f"{Fore.CYAN}ℹ️ 尝试创建邮箱: {email}{Style.RESET_ALL}") + if self.translator: + print(f"{Fore.CYAN}ℹ️ {self.translator.get('email.trying_to_create_email', email=email)}{Style.RESET_ALL}") + else: + print(f"{Fore.CYAN}ℹ️ 尝试创建邮箱: {email}{Style.RESET_ALL}") account_data = { "address": email, @@ -150,8 +153,14 @@ class NewTempEmail: create_response = requests.post(f"{self.api_url}/accounts", json=account_data, timeout=15) if create_response.status_code != 201: - print(f"{Fore.RED}❌ 创建账户失败: 状态码 {create_response.status_code}{Style.RESET_ALL}") - print(f"{Fore.RED}❌ 响应内容: {create_response.text}{Style.RESET_ALL}") + if self.translator: + print(f"{Fore.RED}❌ {self.translator.get('email.failed_to_create_account', error=create_response.status_code)}{Style.RESET_ALL}") + else: + print(f"{Fore.RED}❌ 创建账户失败: 状态码 {create_response.status_code}{Style.RESET_ALL}") + if self.translator: + print(f"{Fore.RED}❌ {self.translator.get('email.failed_to_create_account', error=create_response.text)}{Style.RESET_ALL}") + else: + print(f"{Fore.RED}❌ 响应内容: {create_response.text}{Style.RESET_ALL}") # 如果是域名问题,尝试下一个域名 if len(filtered_domains) > 1 and ("domain" in create_response.text.lower() or "address" in create_response.text.lower()): @@ -164,7 +173,10 @@ class NewTempEmail: raise Exception(f"{self.translator.get('email.failed_to_create_account') if self.translator else '创建账户失败'}") except Exception as e: - print(f"{Fore.RED}❌ 创建账户时出错: {str(e)}{Style.RESET_ALL}") + if self.translator: + print(f"{Fore.RED}❌ {self.translator.get('email.failed_to_create_account', error=str(e))}{Style.RESET_ALL}") + else: + print(f"{Fore.RED}❌ 创建账户时出错: {str(e)}{Style.RESET_ALL}") raise # 获取访问令牌 @@ -176,8 +188,14 @@ class NewTempEmail: token_response = requests.post(f"{self.api_url}/token", json=token_data, timeout=10) if token_response.status_code != 200: - print(f"{Fore.RED}❌ 获取令牌失败: 状态码 {token_response.status_code}{Style.RESET_ALL}") - print(f"{Fore.RED}❌ 响应内容: {token_response.text}{Style.RESET_ALL}") + if self.translator: + print(f"{Fore.RED}❌ {self.translator.get('email.failed_to_get_access_token', error=token_response.status_code)}{Style.RESET_ALL}") + else: + print(f"{Fore.RED}❌ 获取令牌失败: 状态码 {token_response.status_code}{Style.RESET_ALL}") + if self.translator: + print(f"{Fore.RED}❌ {self.translator.get('email.failed_to_get_access_token', error=token_response.text)}{Style.RESET_ALL}") + else: + print(f"{Fore.RED}❌ 响应内容: {token_response.text}{Style.RESET_ALL}") raise Exception(f"{self.translator.get('email.failed_to_get_access_token') if self.translator else '获取访问令牌失败'}") self.token = token_response.json()["token"] @@ -200,12 +218,12 @@ class NewTempEmail: return None def close(self): - """关闭浏览器""" + """close browser""" if self.page: self.page.quit() def refresh_inbox(self): - """刷新邮箱""" + """refresh inbox""" try: if self.translator: print(f"{Fore.CYAN}🔄 {self.translator.get('email.refreshing')}{Style.RESET_ALL}") @@ -271,7 +289,7 @@ class NewTempEmail: return False def get_verification_code(self): - """获取验证码""" + """get verification code""" try: # 使用 API 获取邮件列表 headers = {"Authorization": f"Bearer {self.token}"}