Skip to main content

Overview

Scroll the page to specific elements, by pixel offsets, or to page boundaries. Automatically waits for lazy-loaded content and DOM mutations to stabilize.

Syntax

bdg dom scroll [selector] [options]

Arguments

selector
string
CSS selector or numeric index from cached query results (0-based)

Options

--index
number
Element index if selector matches multiple (0-based)
--down
number
Scroll down by pixels
--up
number
Scroll up by pixels
--left
number
Scroll left by pixels
--right
number
Scroll right by pixels
--top
flag
Scroll to page top
--bottom
flag
Scroll to page bottom
--no-wait
flag
Skip waiting for lazy-loaded content after scroll
--json
flag
Output as JSON

Behavior

Element scrolling

When a selector is provided:
  • Scrolls element into view (centered vertically)
  • Uses instant scrolling (no smooth animation)
  • Returns original scroll position for restoration

Post-scroll stability

By default, waits for content to stabilize:
  • Network idle (no requests for 150ms)
  • DOM stable (no mutations for 200ms)
  • Maximum wait: 2 seconds
Detects lazy-loaded images, infinite scroll, and dynamic content.

Examples

Scroll to element

# By selector
bdg dom scroll "footer"
bdg dom scroll "#section-2"
bdg dom scroll ".product-card"

# By cached index
bdg dom query ".nav-link"
bdg dom scroll 2

Scroll by pixels

# Scroll down
bdg dom scroll --down 500

# Scroll up
bdg dom scroll --up 300

# Scroll horizontally
bdg dom scroll --right 200
bdg dom scroll --left 100

Scroll to boundaries

# Top of page
bdg dom scroll --top

# Bottom of page
bdg dom scroll --bottom

Skip waiting

# For pages without lazy loading
bdg dom scroll "footer" --no-wait

Common workflows

Load more content

# Scroll to bottom to trigger infinite scroll
bdg dom scroll --bottom
# Waits for new content to load

# Verify new content loaded
bdg dom query ".product-card"
# Query sections
bdg dom query "section"
# [0] <section#intro>
# [1] <section#features>
# [2] <section#pricing>

# Scroll to pricing section
bdg dom scroll 2

Screenshot visible area

# Scroll element into view before screenshot
bdg dom screenshot footer.png --scroll "footer"

# Or manually
bdg dom scroll "#chart"
bdg dom screenshot chart.png --no-full-page

Scroll modes

Element-based (with selector)

bdg dom scroll "#element"
  • Centers element vertically in viewport
  • Waits for lazy-loaded content by default
  • Returns original scroll position

Relative (with pixel offsets)

bdg dom scroll --down 500 --right 100
  • Scrolls relative to current position
  • Can combine vertical and horizontal
  • No element targeting

Absolute (with boundaries)

bdg dom scroll --bottom
  • Scrolls to fixed position
  • --top goes to (0, 0)
  • --bottom goes to maximum scroll height

Exit codes

0
number
Success - scrolled to target
81
number
INVALID_ARGUMENTS - invalid pixel value or conflicting options
83
number
RESOURCE_NOT_FOUND - element not found
87
number
STALE_CACHE - cached index invalid (page navigation)
102
number
CDP_TIMEOUT - CDP operation timed out

Lazy loading detection

The scroll command detects lazy-loaded content through:
  1. Network activity: Monitors resource requests via Performance Observer
  2. DOM mutations: Tracks element additions and changes via MutationObserver
  3. Stability thresholds: Waits until both network and DOM are idle
This ensures screenshots and subsequent operations capture fully loaded content.

Troubleshooting

Content not loading

If lazy content doesn’t load after scroll:
  1. Verify the page uses scroll-triggered loading
  2. Check scroll reached the trigger point: bdg dom eval 'window.scrollY'
  3. Increase wait time manually: bdg dom scroll --bottom && sleep 2

Scroll position wrong

For elements not centered correctly:
  1. Check element is visible: bdg dom get <selector>
  2. Verify element has dimensions: bdg dom get <selector> --raw
  3. Try scrolling by pixels instead: bdg dom scroll --down 500

Build docs developers (and LLMs) love