Skip to content

Unable to run on AWS Lambda #2459

Closed
Closed
@andinua

Description

@andinua

Hello and thank you for building and maintaining this project.

I was previously using undetected-chromedriver but decided to give SeleniumBase a try seeing how it's actively maintained.

I am running a project using SeleniumBase on AWS lambda. It does not go undetected, but triggers the website's CloudFlare turnstile challenge. I have managed to solve the challenge by iframe switch and click, on my local Dockerized environment.

My setup

  • Chrome + Chromedriver for Linux version 120.0.6099.109
  • WSL: Ubuntu 20.04
  • Python 3.9

The code I use to solve the challenge, borrowed from examples seen on this repo/Issue board:

with SB(uc=True, headless=True) as sb: 
        data = load_data(url, sb)
    sb.driver.uc_open_with_reconnect(url, 10)
    sb.sleep(1)
    if not sb.is_element_visible('iframe[src*="challenge"]'):
        logger.info("Haven't found the challenge yet...")
        sb.get_new_driver(undetectable=True)
        sb.driver.get(url)
        sb.sleep(1)
    if sb.is_element_visible('iframe[src*="challenge"]'):
        with sb.frame_switch('iframe[src*="challenge"]'):
            logger.info("Found challenge, going in")
            sb.wait_for_element("span.mark")
            if not sb.is_element_visible("span.mark"):
                print('Could not find mark')
                sb.sleep(10)
            sb.click("span.mark")
            i = 1
            while i < 10: 
                i+=1
                sb.sleep(1)
                sb.save_screenshot(f'screen{i}.png')
    soup = BeautifulSoup(sb.driver.page_source, "html.parser")

This works nicely in a local Docker container. However, when deployed on AWS lambda, it seems to crash Chrome.

image
image
image

The only setup that seems to work on AWS lambda is adding

chrome_options.add_argument("--single-process")

However, this no longer seems to be able to solve the challenge, and the turnstile ends up in a loop after the click action.

I have tried both headless and headed modes (with Xvfb enabled), same outcome.

Do you have any idea of what I could be doing differently/ whether I'm approaching this correctly? Any hints are much appreciated. Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionSomeone is looking for answers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions