From 391d9e0d65ee5b8e462d2ae79443207a66b0f94f Mon Sep 17 00:00:00 2001 From: rcholic Date: Sat, 3 Jan 2026 19:21:00 -0800 Subject: [PATCH] add device_scale_factor support --- pyproject.toml | 2 +- sentience/__init__.py | 2 +- sentience/browser.py | 21 +++++++++++++++++++++ sentience/tracer_factory.py | 2 +- sentience/tracing.py | 2 +- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 54f3850..d253533 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "sentienceapi" -version = "0.92.0" +version = "0.92.1" description = "Python SDK for Sentience AI Agent Browser Automation" readme = "README.md" requires-python = ">=3.11" diff --git a/sentience/__init__.py b/sentience/__init__.py index 446ac52..8dd5314 100644 --- a/sentience/__init__.py +++ b/sentience/__init__.py @@ -72,7 +72,7 @@ from .utils.formatting import format_snapshot_for_llm from .wait import wait_for -__version__ = "0.92.0" +__version__ = "0.92.1" __all__ = [ # Core SDK diff --git a/sentience/browser.py b/sentience/browser.py index a07dbdb..58d0134 100644 --- a/sentience/browser.py +++ b/sentience/browser.py @@ -43,6 +43,7 @@ def __init__( record_video_dir: str | Path | None = None, record_video_size: dict[str, int] | None = None, viewport: Viewport | dict[str, int] | None = None, + device_scale_factor: float | None = None, ): """ Initialize Sentience browser @@ -115,6 +116,9 @@ def __init__( else: self.viewport = viewport + # Device scale factor for high-DPI emulation + self.device_scale_factor = device_scale_factor + self.playwright: Playwright | None = None self.context: BrowserContext | None = None self.page: Page | None = None @@ -217,6 +221,10 @@ def start(self) -> None: "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36", } + # Add device scale factor if configured + if self.device_scale_factor is not None: + launch_params["device_scale_factor"] = self.device_scale_factor + # Add proxy if configured if proxy_config: launch_params["proxy"] = proxy_config.to_playwright_dict() @@ -596,6 +604,7 @@ def __init__( record_video_dir: str | Path | None = None, record_video_size: dict[str, int] | None = None, viewport: Viewport | dict[str, int] | None = None, + device_scale_factor: float | None = None, ): """ Initialize Async Sentience browser @@ -615,6 +624,11 @@ def __init__( Viewport(width=1920, height=1080) (Full HD) {"width": 1280, "height": 800} (dict also supported) If None, defaults to Viewport(width=1280, height=800). + device_scale_factor: Optional device scale factor to emulate high-DPI (Retina) screens. + Examples: 1.0 (default, standard DPI) + 2.0 (Retina/high-DPI, like MacBook Pro) + 3.0 (very high DPI) + If None, defaults to 1.0 (standard DPI). """ self.api_key = api_key # Only set api_url if api_key is provided, otherwise None (free tier) @@ -649,6 +663,9 @@ def __init__( else: self.viewport = viewport + # Device scale factor for high-DPI emulation + self.device_scale_factor = device_scale_factor + self.playwright: AsyncPlaywright | None = None self.context: AsyncBrowserContext | None = None self.page: AsyncPage | None = None @@ -741,6 +758,10 @@ async def start(self) -> None: "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36", } + # Add device scale factor if configured + if self.device_scale_factor is not None: + launch_params["device_scale_factor"] = self.device_scale_factor + # Add proxy if configured if proxy_config: launch_params["proxy"] = proxy_config.to_playwright_dict() diff --git a/sentience/tracer_factory.py b/sentience/tracer_factory.py index 142e897..601f590 100644 --- a/sentience/tracer_factory.py +++ b/sentience/tracer_factory.py @@ -7,9 +7,9 @@ import gzip import os import uuid +from collections.abc import Callable from pathlib import Path from typing import Any, Optional -from collections.abc import Callable import requests diff --git a/sentience/tracing.py b/sentience/tracing.py index 03e2ccc..06e8639 100644 --- a/sentience/tracing.py +++ b/sentience/tracing.py @@ -6,11 +6,11 @@ import time from abc import ABC, abstractmethod +from collections.abc import Callable from dataclasses import dataclass, field from datetime import datetime from pathlib import Path from typing import Any, Optional -from collections.abc import Callable from .models import TraceStats from .trace_file_manager import TraceFileManager