captchaforge 0.2.4

Automatic CAPTCHA detection and multi-strategy solving for chromiumoxide-driven headless browsers (Cloudflare Turnstile, reCAPTCHA v2/v3, hCaptcha, image grids, audio, sliders).
Documentation
//! Generic audio CAPTCHA detector.
use anyhow::Result;
use async_trait::async_trait;
use chromiumoxide::Page;

use super::{parse_detection_result, CaptchaInfo, Detector};

/// Detector for generic audio CAPTCHAs.
pub struct AudioCaptchaDetector;

impl AudioCaptchaDetector {
    /// JS payload evaluated against the live page.
    pub const JS: &'static str = r#"(function() {
    const audioCaptcha = document.querySelector(
        'audio[src*="captcha"], .audio-captcha, #audio-captcha'
    );
    if (audioCaptcha) {
        return { kind: 'audio', site_key: null, container: '.audio-captcha, #audio-captcha' };
    }
    return { kind: 'none', site_key: null, container: null };
})()"#;
}

#[async_trait]
impl Detector for AudioCaptchaDetector {
    fn name(&self) -> &'static str {
        "audio_captcha"
    }
    fn priority(&self) -> i32 {
        50
    }
    async fn detect(&self, page: &Page) -> Result<Option<CaptchaInfo>> {
        let raw = page.evaluate(Self::JS).await?;
        let val = raw.into_value::<serde_json::Value>()?;
        Ok(parse_detection_result(val))
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn audio_captcha_detector_js_has_selectors() {
        assert!(AudioCaptchaDetector::JS.contains("audio[src*=\"captcha\"]"));
        assert!(AudioCaptchaDetector::JS.contains(".audio-captcha"));
    }
}