Skip to content

Commit 6878829

Browse files
authored
Update CopilotSession.py
1 parent 4961f09 commit 6878829

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

‎g4f/Provider/CopilotSession.py‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from ..requests import get_nodriver_session
2020
from ..image import is_accepted_format
2121
from .helper import get_last_user_message
22-
from .Copilot import click_trunstile
2322
from .. import debug
2423

2524
class Conversation(JsonConversation):
@@ -205,4 +204,20 @@ async def create_authed(
205204
if not done:
206205
raise MissingAuthError(f"Invalid response: {last_msg}")
207206
if sources:
208-
yield Sources(sources.values())
207+
yield Sources(sources.values())
208+
209+
if has_nodriver:
210+
async def click_trunstile(page: nodriver.Tab, element='document.getElementById("cf-turnstile")'):
211+
for _ in range(3):
212+
size = None
213+
for idx in range(15):
214+
size = await page.js_dumps(f'{element}?.getBoundingClientRect()||{{}}')
215+
debug.log(f"Found size: {size.get('x'), size.get('y')}")
216+
if "x" not in size:
217+
break
218+
await page.flash_point(size.get("x") + idx * 3, size.get("y") + idx * 3)
219+
await page.mouse_click(size.get("x") + idx * 3, size.get("y") + idx * 3)
220+
await asyncio.sleep(2)
221+
if "x" not in size:
222+
break
223+
debug.log("Finished clicking trunstile.")

0 commit comments

Comments
 (0)