Merge PR #1463: Add configurable device_scale_factor for screenshot quality

This commit is contained in:
unclecode
2026-02-06 09:19:42 +00:00
3 changed files with 13 additions and 2 deletions

View File

@@ -534,6 +534,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.
@@ -594,6 +601,7 @@ class BrowserConfig:
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,
@@ -663,6 +671,7 @@ class BrowserConfig:
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
@@ -743,6 +752,7 @@ class BrowserConfig:
proxy_config=ProxyConfig.from_dict(kwargs.get("proxy_config")) if isinstance(kwargs.get("proxy_config"), dict) else 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"),
@@ -787,6 +797,7 @@ class BrowserConfig:
"proxy_config": self.proxy_config.to_dict() if hasattr(self.proxy_config, 'to_dict') else 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,

View File

@@ -1229,7 +1229,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,
}

View File

@@ -7699,7 +7699,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,
}