screenshot image height #1235
              
                Unanswered
              
          
                  
                    
                      imad07mos
                    
                  
                
                  asked this question in
                Forums - Q&A
              
            Replies: 2 comments 1 reply
-
| @imad07mos hi, you can set the  async def main():
    browser_config = BrowserConfig(
        accept_downloads=True,
        downloads_path=os.path.expanduser("~/.crawl4ai/screenshots"),
    )
    async with AsyncWebCrawler(config=browser_config) as crawler:
        run_config = CrawlerRunConfig(
            screenshot=True,
            adjust_viewport_to_content=True,
            wait_for_images=True,
            screenshot_height_threshold=500,
        )
        result = await crawler.arun(url="https://www.amazon.com", config=run_config)
        if result.success and result.screenshot:
            screenshot_size = len(result.screenshot) * 3 / 4 / 1024  # Size in KB
            print(f"Successfully captured a viewport-only screenshot using the threshold trick.")
            print(f"Screenshot size: {screenshot_size:.2f} KB")
            from base64 import b64decode
            with open("screenshot.png", "wb") as f:
                f.write(b64decode(result.screenshot))
        else:
            print("Failed to get screenshot.") | 
Beta Was this translation helpful? Give feedback.
                  
                    1 reply
                  
                
            -
| Thanks for replying, but this setting is not for limiting height. It's to
change screenshot taking strategy for long pages because default strategy
is limited at certain height .… On Wed, 2 Jul 2025 at 12:02 Nasrin ***@***.***> wrote:
 @imad07mos <https://github.com/imad07mos> hi, you can set the
 screenshot_height_threshold parameter in CrawlerRunConfig:
 async def main():
     browser_config = BrowserConfig(
         accept_downloads=True,
         downloads_path=os.path.expanduser("~/.crawl4ai/screenshots"),
     )
     async with AsyncWebCrawler(config=browser_config) as crawler:
         run_config = CrawlerRunConfig(
             screenshot=True,
             adjust_viewport_to_content=True,
             wait_for_images=True,
             screenshot_height_threshold=500,
         )
         result = await crawler.arun(url="https://www.amazon.com", config=run_config)
         if result.success and result.screenshot:
             screenshot_size = len(result.screenshot) * 3 / 4 / 1024  # Size in KB
             print(f"Successfully captured a viewport-only screenshot using the threshold trick.")
             print(f"Screenshot size: {screenshot_size:.2f} KB")
             from base64 import b64decode
             with open("screenshot.png", "wb") as f:
                 f.write(b64decode(result.screenshot))
         else:
             print("Failed to get screenshot.")
 —
 Reply to this email directly, view it on GitHub
 <#1235 (comment)>,
 or unsubscribe
 <https://github.com/notifications/unsubscribe-auth/AEAP2Y2IFXDZK5R2U3VZ6C33GO32VAVCNFSM6AAAAAB7XASHFKVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTGNRTHE3DINY>
 .
 You are receiving this because you were mentioned.Message ID:
 ***@***.***>
 | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
how to limit screenshot height to x viewport ? bas64 for tall pages is too large for bulk crawling
Beta Was this translation helpful? Give feedback.
All reactions