[Python] How can I programmatically install and configure the 2Captcha Chrome extension...

Discussão em 'Python' iniciado por Stack, Abril 7, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to fully automate the setup of the 2Captcha Chrome extension using Python and Playwright — including installing the extension and injecting my API key into its settings page.

    What I’ve done so far: Cloned the unpacked source of the extension from the official GitHub repo: https://github.com/rucaptcha/2captcha-solver

    Launched Chromium with the following Playwright options:

    context = await browser_type.launch_persistent_context(
    user_data_dir="profile",
    headless=False,
    args=[
    f"--disable-extensions-except={unpacked_path}",
    f"--load-extension={unpacked_path}",
    ]
    )


    Tried to programmatically open the options page at:

    chrome-extension://<EXT_ID>/options.html

    But since unpacked extensions have a dynamic ID, I can't hardcode it.

    Attempted to extract the extension ID from context.service_workers or context.background_pages, but the extension seems not to initialize fast enough — causing me to hit timeouts or ERR_ABORTED.

    What I need: ✅ A reliable way to detect the extension ID after launching Chromium with the unpacked extension

    ✅ A way to wait until the extension is fully registered (service worker or background page is ready)

    ✅ How to navigate to the options page and fill in the API key input using Playwright

    ⚠️ Ideally this should work in a headless environment (e.g. Docker with xvfb)

    Environment: Python 3.12

    Playwright v1.43+

    Ubuntu 22.04 (no desktop environment)

    Continue reading...

Compartilhe esta Página