Module: Browserctl::Detectors

Defined in:
lib/browserctl/detectors.rb,
lib/browserctl/detectors/auth_required.rb

Defined Under Namespace

Modules: AuthRequired

Constant Summary collapse

CLOUDFLARE_SIGNALS =
[
  "cf-challenge-running",
  "cf_chl_opt",
  "__cf_chl_f_tk",
  "Just a moment..."
].freeze

Class Method Summary collapse

Class Method Details

.auth_required(page) ⇒ Object



124
125
126
# File 'lib/browserctl/detectors/auth_required.rb', line 124

def self.auth_required(page, **)
  AuthRequired.detect(page, **)
end

.auth_required?(page) ⇒ Boolean

Module-level shorthand so callers match the existing ‘Detectors.cloudflare?` style.

Returns:

  • (Boolean)


120
121
122
# File 'lib/browserctl/detectors/auth_required.rb', line 120

def self.auth_required?(page, **)
  AuthRequired.triggered?(page, **)
end

.cloudflare?(page) ⇒ Boolean

Returns true if the page appears to be showing a Cloudflare challenge. Checks both the current URL and the page body for known Cloudflare signals.

Parameters:

  • page (#current_url, #body)

    the browser page to inspect

Returns:

  • (Boolean)


18
19
20
21
22
23
# File 'lib/browserctl/detectors.rb', line 18

def self.cloudflare?(page)
  url  = page.current_url.to_s
  body = page.body.to_s
  url.include?("challenge-platform") ||
    CLOUDFLARE_SIGNALS.any? { |sig| body.include?(sig) }
end