Scroll Height
Learn how to control page scrolling before taking screenshots
Scroll Height Control
The Screenshots API allows you to control the vertical scroll position of a webpage before capturing the screenshot. This is particularly useful for:
- Capturing specific sections of a long page
- Ensuring important content is in view
- Testing responsive layouts at different scroll positions
- Validating infinite scroll implementations
How Scroll Height Works
- You specify the desired scroll height using the
scroll
parameter - The API scrolls the page to that position before taking the screenshot
- The screenshot is captured after any animations or content loading completes
Basic Usage
Here's how to use the scroll height feature:
Scroll Height Options
The scroll
parameter supports several formats:
-
Pixel Value:
scroll=800
- Scrolls to 800 pixels from the topscroll=0
- Stays at the top of the pagescroll=2000
- Scrolls to 2000 pixels from the top
-
Special Values:
scroll=auto
- Uses the default scroll position (usually top)scroll=bottom
- Scrolls to the bottom of the page
-
Percentage:
scroll=50%
- Scrolls to 50% of the page heightscroll=75%
- Scrolls to 75% of the page height
Best Practices
-
Wait Time:
- Always use the
wait
parameter with scroll to allow time for:- Content to load after scrolling
- Animations to complete
- Lazy-loaded images to appear
- Recommended minimum wait: 500ms
- Always use the
-
Viewport Height:
- Consider the viewport height (
height
parameter) when using scroll - Ensure important content will be visible in the viewport
- Test with different viewport sizes
- Consider the viewport height (
-
Full Page Screenshots:
- When
full=true
, scroll position affects initial render - Useful for ensuring specific content is loaded before capture
- Can be combined with
wait
for better results
- When
-
Error Handling:
- Validate scroll values before sending
- Handle cases where page is shorter than scroll value
- Consider fallback options for different page lengths
Common Use Cases
-
Content Verification:
- Capture specific sections of long pages
- Verify content at different scroll positions
- Test dynamic content loading
-
Performance Testing:
- Check lazy loading behavior
- Verify scroll-based animations
- Test infinite scroll implementations
-
Layout Testing:
- Verify fixed/sticky elements
- Test floating navigation
- Check responsive behavior at different scroll positions
-
User Experience:
- Document user journey steps
- Capture specific user interactions
- Test scroll-triggered features
Example: Capturing Multiple Sections
Here's an example of capturing the same page at different scroll positions:
Next Steps
- Learn about advanced features
- Explore bulk screenshot capabilities
- Check out the API reference for detailed documentation