Skip to content

Latest commit

 

History

History
240 lines (184 loc) · 4.8 KB

File metadata and controls

240 lines (184 loc) · 4.8 KB

Screenshot Endpoint

The Screenshot endpoint captures screenshots of web pages with full JavaScript rendering support.

API Reference: https://spider.cloud/docs/api#screenshot

Basic Usage

response = SpiderCloud.screenshot( 'https://example.com' )

# Save to file
response.result.save_to( 'screenshot.png' )

# Or access raw image data
image_data = response.result.image_data

With Options

options = SpiderCloud::ScreenshotOptions.build do
  full_page true
  viewport do
    width 1920
    height 1080
  end
end

response = SpiderCloud.screenshot( 'https://example.com', options )

Options Reference

Screenshot Options

Option Type Default Description
full_page Boolean true Capture full scrollable page
binary Boolean false Return binary instead of base64
omit_background Boolean false Transparent background (PNG only)
block_images Boolean false Block images for faster capture

CDP Parameters

Chrome DevTools Protocol parameters for advanced control:

cdp_params do
  format :png       # :png or :jpeg
  quality 80        # JPEG quality (0-100)
  from_surface true
  capture_beyond_viewport true
  clip do
    x 0
    y 0
    width 800
    height 600
    scale 1
  end
end

Viewport & Device

Option Type Description
viewport Hash Browser viewport {width:, height:}
device Symbol Device: :mobile, :tablet, :desktop

Wait Conditions

wait_for do
  # Wait for CSS selector
  selector '#loaded'

  # Wait for network idle
  idle_network do
    timeout { seconds 5; nanoseconds 0 }
  end

  # Wait for delay
  delay do
    timeout { seconds 2; nanoseconds 0 }
  end
end

Browser Configuration

Option Type Description
stealth Boolean Stealth mode
fingerprint Boolean Use fingerprint detection
scroll Integer Scroll duration before capture (ms)
block_ads Boolean Block ads
virtual_display Boolean Use virtual display

Proxy Configuration

Option Type Description
proxy Symbol Proxy pool: :residential, :mobile, :isp
proxy_enabled Boolean Enable proxy
country_code String ISO country code

Authentication

Option Type Description
cookies String HTTP cookies
headers Hash Custom HTTP headers
automation_scripts Hash Path-based automation

Response

response = SpiderCloud.screenshot( 'https://example.com' )

response.result.success?    # => true
response.result.content     # => "iVBORw0KGgo..." (base64)
response.result.image_data  # => binary PNG/JPEG data
response.result.url         # => "https://example.com"
response.result.status      # => 200

# Save directly to file
response.result.save_to( 'screenshot.png' )

Examples

Full Page Screenshot

options = SpiderCloud::ScreenshotOptions.build do
  full_page true
end

response = SpiderCloud.screenshot( 'https://example.com', options )
response.result.save_to( 'full-page.png' )

Viewport Screenshot

options = SpiderCloud::ScreenshotOptions.build do
  full_page false
  viewport do
    width 1280
    height 720
  end
end

response = SpiderCloud.screenshot( 'https://example.com', options )

Mobile Screenshot

options = SpiderCloud::ScreenshotOptions.build do
  device :mobile
  viewport do
    width 375
    height 812
  end
end

response = SpiderCloud.screenshot( 'https://example.com', options )

JPEG with Quality

options = SpiderCloud::ScreenshotOptions.build do
  cdp_params do
    format :jpeg
    quality 85
  end
end

response = SpiderCloud.screenshot( 'https://example.com', options )
response.result.save_to( 'screenshot.jpg' )

Capture Specific Region

options = SpiderCloud::ScreenshotOptions.build do
  cdp_params do
    clip do
      x 100
      y 100
      width 400
      height 300
      scale 1
    end
  end
end

response = SpiderCloud.screenshot( 'https://example.com', options )

Wait for Content

options = SpiderCloud::ScreenshotOptions.build do
  wait_for do
    selector '.chart-loaded'
  end
end

response = SpiderCloud.screenshot( 'https://example.com/dashboard', options )

With Proxy

options = SpiderCloud::ScreenshotOptions.build do
  proxy :residential
  proxy_enabled true
  country_code 'UK'
end

response = SpiderCloud.screenshot( 'https://example.com', options )

Transparent Background

options = SpiderCloud::ScreenshotOptions.build do
  omit_background true
  cdp_params do
    format :png
  end
end

response = SpiderCloud.screenshot( 'https://example.com', options )