seleniumbase / SeleniumBase

📊 Python's all-in-one framework for web crawling, scraping, testing, and reporting. Supports pytest. UC Mode provides stealth. Includes many tools.
https://seleniumbase.io
MIT License
4.46k stars 910 forks source link

uc_cdp_events not functioning within Flask + SeleniumBase #2657

Closed ranggaggngntt closed 3 months ago

ranggaggngntt commented 3 months ago

Python version = 3.11.1 SeleniumBase version = 4.24.2 Flask version = 3.0.2 Os = Windows

I'm trying to integrate flask and seleniumbase, When i enabling the uc_cdp_events option in the Driver constructor, it just stuck. It work properly when im running it outside of flask.

This my code for initialize driver

def initialize_driver(url, user_id, user_agent):
    user = dbRead('users', {'user_id': user_id})
    if user:
        # Create instance on mongo
        dbCreate('driver_instances', {'user_id': user_id, 'url': url})

        #it works if i use this
        # webdriver_instances[user_id] = Driver(uc=True)
        webdriver_instances[user_id] = Driver(uc=True, uc_cdp_events=True)
        webdriver_instances[user_id].maximize_window()
        webdriver_instances[user_id].get(url)
        # User exists, do something
        return 'Initialize Driver Success'
    else:
        # User doesn't exist, do something else
        return 'Initialize Driver Failed'

any how to fix this? i need to capture some events that's why i need use uc_cdp_events

mdmintz commented 3 months ago

On the latest version of SeleniumBase, these scripts are both working:

Since the version you're using is currently more than 10 versions old, you should upgrade to the latest version of SeleniumBase, and try the examples provided. (And if still not working for your scripts, it might be an issue with your Flask setup.)