Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加其他Chromium内核浏览器和windows下的非默认安装路径错误提示 #255

Merged
merged 2 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ BROWSER_USER_AGENT=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36

# 无头模式 默认开启
# BROWSER_HEADLESS='True'

# 使用其他浏览器(如Edge)
# BROWSER_PATH='C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe'
12 changes: 8 additions & 4 deletions browser_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ def _get_browser_options(self, user_agent=None):
"""获取浏览器配置"""
co = ChromiumOptions()
try:
extension_path = self._get_extension_path()
extension_path = self._get_extension_path("turnstilePatch")
co.add_extension(extension_path)
except FileNotFoundError as e:
logging.warning(f"警告: {e}")

browser_path = os.getenv("BROWSER_PATH")
if browser_path:
co.set_paths(browser_path=browser_path)

co.set_pref("credentials_enable_service", False)
co.set_argument("--hide-crash-restore-bubble")
proxy = os.getenv("BROWSER_PROXY")
Expand All @@ -47,13 +51,13 @@ def _get_browser_options(self, user_agent=None):

return co

def _get_extension_path(self):
def _get_extension_path(self,exname='turnstilePatch'):
"""获取插件路径"""
root_dir = os.getcwd()
extension_path = os.path.join(root_dir, "turnstilePatch")
extension_path = os.path.join(root_dir, exname)

if hasattr(sys, "_MEIPASS"):
extension_path = os.path.join(sys._MEIPASS, "turnstilePatch")
extension_path = os.path.join(sys._MEIPASS, exname)

if not os.path.exists(extension_path):
raise FileNotFoundError(f"插件不存在: {extension_path}")
Expand Down
8 changes: 8 additions & 0 deletions patch_cursor_get_machine_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ def get_cursor_paths() -> Tuple[str, str]:
raise OSError("在 Linux 系统上未找到 Cursor 安装路径")

base_path = paths_map[system]["base"]
# 判断Windows是否存在这个文件夹,如果不存在,提示需要创建软连接后重试
if system == "Windows":
if not os.path.exists(base_path):
logging.info('可能您的Cursor不是默认安装路径,请创建软连接,命令如下:')
logging.info('cmd /c mklink /d "C:\\Users\\<username>\\AppData\\Local\\Programs\\Cursor" "默认安装路径"')
logging.info('例如:')
logging.info('cmd /c mklink /d "C:\\Users\\<username>\\AppData\\Local\\Programs\\Cursor" "D:\\SoftWare\\cursor"')
input("\n程序执行完毕,按回车键退出...")
return (
os.path.join(base_path, paths_map[system]["package"]),
os.path.join(base_path, paths_map[system]["main"]),
Expand Down