Module: Browserctl::Detectors

Defined in:
lib/browserctl/detectors.rb

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

.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 (Ferrum::Page)

    the browser page to inspect

Returns:

  • (Boolean)


16
17
18
19
20
21
# File 'lib/browserctl/detectors.rb', line 16

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