diff --git a/crawl4ai/async_configs.py b/crawl4ai/async_configs.py index a43b50a4a..da163f90d 100644 --- a/crawl4ai/async_configs.py +++ b/crawl4ai/async_configs.py @@ -365,6 +365,13 @@ class BrowserConfig: viewport_height (int): Default viewport height for pages. Default: 600. viewport (dict): Default viewport dimensions for pages. If set, overrides viewport_width and viewport_height. Default: None. + device_scale_factor (float): The device pixel ratio used for rendering pages. Controls how many + physical pixels map to one CSS pixel, allowing simulation of HiDPI + or Retina displays. For example, a viewport of 1920x1080 with a + device_scale_factor of 2.0 produces screenshots at 3840x2160 resolution. + Increasing this value improves screenshot quality but may increase + memory usage and rendering time. + Default: 1.0. verbose (bool): Enable verbose logging. Default: True. accept_downloads (bool): Whether to allow file downloads. If True, requires a downloads_path. @@ -411,6 +418,7 @@ def __init__( viewport_width: int = 1080, viewport_height: int = 600, viewport: dict = None, + device_scale_factor: float = 1.0, accept_downloads: bool = False, downloads_path: str = None, storage_state: Union[str, dict, None] = None, @@ -461,6 +469,7 @@ def __init__( if self.viewport is not None: self.viewport_width = self.viewport.get("width", 1080) self.viewport_height = self.viewport.get("height", 600) + self.device_scale_factor = device_scale_factor self.accept_downloads = accept_downloads self.downloads_path = downloads_path self.storage_state = storage_state @@ -534,6 +543,7 @@ def from_kwargs(kwargs: dict) -> "BrowserConfig": proxy_config=kwargs.get("proxy_config", None), viewport_width=kwargs.get("viewport_width", 1080), viewport_height=kwargs.get("viewport_height", 600), + device_scale_factor=kwargs.get("device_scale_factor", 1.0), accept_downloads=kwargs.get("accept_downloads", False), downloads_path=kwargs.get("downloads_path"), storage_state=kwargs.get("storage_state"), @@ -571,6 +581,7 @@ def to_dict(self): "proxy_config": self.proxy_config, "viewport_width": self.viewport_width, "viewport_height": self.viewport_height, + "device_scale_factor": self.device_scale_factor, "accept_downloads": self.accept_downloads, "downloads_path": self.downloads_path, "storage_state": self.storage_state, diff --git a/crawl4ai/browser_manager.py b/crawl4ai/browser_manager.py index 8fed970cc..93f67fc5b 100644 --- a/crawl4ai/browser_manager.py +++ b/crawl4ai/browser_manager.py @@ -919,7 +919,7 @@ async def create_browser_context(self, crawlerRunConfig: CrawlerRunConfig = None "accept_downloads": self.config.accept_downloads, "storage_state": self.config.storage_state, "ignore_https_errors": self.config.ignore_https_errors, - "device_scale_factor": 1.0, + "device_scale_factor": self.config.device_scale_factor, "java_script_enabled": self.config.java_script_enabled, } diff --git a/deploy/docker/c4ai-code-context.md b/deploy/docker/c4ai-code-context.md index eb29b94ce..f5a65af28 100644 --- a/deploy/docker/c4ai-code-context.md +++ b/deploy/docker/c4ai-code-context.md @@ -7698,7 +7698,7 @@ class BrowserManager: "accept_downloads": self.config.accept_downloads, "storage_state": self.config.storage_state, "ignore_https_errors": self.config.ignore_https_errors, - "device_scale_factor": 1.0, + "device_scale_factor": self.config.device_scale_factor, "java_script_enabled": self.config.java_script_enabled, }