Skip to content

Passing Tab / driver between asyncio tasks #3722

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

Closed
mrwillis opened this issue May 1, 2025 · 1 comment
Closed

Passing Tab / driver between asyncio tasks #3722

mrwillis opened this issue May 1, 2025 · 1 comment
Labels
question Someone is looking for answers UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode

Comments

@mrwillis
Copy link

mrwillis commented May 1, 2025

Hi Mike,

Searched around but couldn't find an example of this. I have a bunch of asyncio tasks and I'm trying to use the Tab and Browser objects in different ones, but all my await function invocations of the Tab or Browser objects hang in the child tasks. So here's an example

driver: cdp_driver.cdp_util.Browser

async def watch_participant_count():
    """Watch the participant count and trigger shutdown when everyone leaves"""
    last_count = None
    
    logging.info("Starting participant count watcher...")
    
    page = driver.main_tab
    
    logging.info("Switching to Google")
    
    
    await driver.get("https://google.com") # HANGS HERE IF INVOKED AS A TASK
    
    logging.info("Switched to Google")

   # Try to find the participant count element
   logging.info("Looking for participant count element...")
   count_element = await page.select('div.uGOf1d', 1) # ALSO HANGS HERE IF INVOKED AS A TASK
# other function
async def join_google_meet():
    global driver, ffmpeg_process
    logging.info("Starting Google Meet session")
    driver = await cdp_driver.cdp_util.start_async(xvfb=True, lang="en")
  # ...
  # other stuff...
  # ...
  # Start participant count watcher
      participant_watcher_two = await watch_participant_count() # This works fine
  # causes problems in the function: participant_watcher = asyncio.create_task(watch_participant_count()) 

I've also tried for example directly passing in the driver and or page vs global objects, but it also seems to hang. Is there any way to do this?

@mdmintz mdmintz added question Someone is looking for answers UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode labels May 1, 2025
@mdmintz
Copy link
Member

mdmintz commented May 1, 2025

See the existing async examples for correct use:

Those use "Syntax Format 24", from the 25 Syntax Formats.

For general asyncio questions, the internet may be of better help.

@mdmintz mdmintz closed this as completed May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Someone is looking for answers UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode
Projects
None yet
Development

No branches or pull requests

2 participants