XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Update Copilot Url

e5d68e15
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

5 个文件 +37 -5
Modified g4f/Provider/CopilotApp.py +1 -1
@@ -12,7 +12,7 @@ from ..providers.response import SourceLink, Sources
12 12
13 13 class CopilotApp(AsyncGeneratorProvider, ProviderModelMixin):
14 14 label = "Copilot App"
15 url = "https://play.google.com/store/apps/details?id=com.microsoft.copilot"
15 url = "https://play.google.com/store/apps/details?id=com.microsoft.office.officehubrow"
16 16 working = True
17 17 active_by_default = True
18 18
Modified g4f/api/__init__.py +2 -1
@@ -1426,9 +1426,10 @@ class Api:
1426 1426 ):
1427 1427 try:
1428 1428 from g4f.requests.cdp import CDPSession
1429 session = CDPSession(headless="headless=false" not in url)
1429 session = CDPSession()
1430 1430 await session.start()
1431 1431 try:
1432 debug.log(f"Capturing screenshot for URL: {url}")
1432 1433 screenshot_path = await session.capture_screenshot(url, 1 if "q=" in url and "q=Hello" not in url else 3)
1433 1434 return FileResponse(
1434 1435 screenshot_path,
Modified g4f/cli/__init__.py +15 -0
@@ -173,6 +173,13 @@ def get_api_parser(exit_on_error: bool = True) -> ArgumentParser:
173 173 help="Host for browser automation tool.",
174 174 )
175 175
176 api_parser.add_argument(
177 "--no-headless",
178 action="store_true",
179 default=False,
180 help="Run the browser in visible (non-headless) mode.",
181 )
182
176 183 api_parser.add_argument(
177 184 "--disable-pa-auto-download",
178 185 action="store_true",
@@ -228,6 +235,14 @@ def run_api_args(args):
228 235 BrowserConfig.port = args.browser_port
229 236 BrowserConfig.host = args.browser_host
230 237
238 # Run browser in visible mode when requested.
239 # Set the env var too, because BrowserConfig.load_from_env() is called
240 # later during cookie loading (with dotenv override=True) and would
241 # otherwise clobber the CLI value.
242 if getattr(args, "no_headless", False):
243 BrowserConfig.headless = False
244 os.environ["G4F_BROWSER_HEADLESS"] = "false"
245
231 246 # Custom cookie browsers
232 247 if args.cookie_browsers:
233 248 cookies.BROWSERS = [
Modified g4f/cookies.py +1 -1
@@ -77,7 +77,7 @@ class BrowserConfig:
77 77 impersonate: str = "chrome"
78 78 executable_path: str = None
79 79 connection_timeout: float = 0.25
80 headless: bool = False
80 headless: bool = True
81 81
82 82 @staticmethod
83 83 async def stop_browser():
Modified g4f/requests/cdp.py +18 -2
@@ -811,6 +811,21 @@ class CDPSession:
811 811 logger.debug(f"Failed to auto-click Turnstile: {e}")
812 812 return False
813 813
814 async def include_debug(self) -> bool:
815 """Inject a debug script into the page to enable logging."""
816 js_code = """
817 // 1. Inject debug script to show logging
818 const debugEl = document.createElement('script');
819 debugEl.src = 'https://g4f.dev/dist/js/debug.js';
820 document.head.appendChild(debugEl);
821 """
822 try:
823 await self.evaluate_js(js_code)
824 return True
825 except Exception as e:
826 logger.debug(f"Failed to include debug script: {e}")
827 return False
828
814 829 async def click_accept_button(self) -> bool:
815 830 """Find and click an 'Accept' or 'Einwilligen' button, including inside iframes."""
816 831 js_code = """
@@ -1055,8 +1070,9 @@ if (deepseekSendButton) {
1055 1070 if await self.evaluate_js('!document.doctype'):
1056 1071 raise RuntimeError(f"Failed to load page {url} for screenshot, document.doctype={await self.evaluate_js('String(document.doctype)')}")
1057 1072
1058 await self.bypass_turnstile()
1073 #await self.bypass_turnstile()
1059 1074 await self.evaluate_js("window.scrollTo(0, 0);")
1075 await self.include_debug()
1060 1076
1061 1077 result = None
1062 1078 for i in range(n):
@@ -1114,7 +1130,7 @@ if (deepseekSendButton) {
1114 1130 # Wait for network activity to settle before capturing
1115 1131 await self.wait_for_network_idle(idle_time=5, timeout=15.0)
1116 1132 # Try to click any "Accept" or "Einwilligen" cookie consent buttons
1117 if n < 3:
1133 if n < 3 and not "id=" in url_without_suffix:
1118 1134 for _ in range(2):
1119 1135 debug.log("Attempting to click accept button...")
1120 1136 await asyncio.sleep(1)