Merge pull request #420 from vbanos/screenshot-limits
Some checks failed
Python Formatting Check / formatting (push) Has been cancelled
Tests / Run tests (push) Has been cancelled

Limit screenshot width and height
This commit is contained in:
Alex Dempsey 2025-11-19 10:44:26 -08:00 committed by GitHub
commit d12ed3af6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -388,6 +388,8 @@ class Browser:
self.is_browsing = False
self._command_id = Counter()
self._wait_interval = 0.5
self._max_screenshot_width = kwargs.get("max_screenshot_width", 2000)
self._max_screenshot_height = kwargs.get("max_screenshot_height", 20000)
def __enter__(self):
self.start()
@ -808,8 +810,12 @@ class Browser:
lambda: self.websock_thread.received_result(msg_id), timeout=timeout
)
message = self.websock_thread.pop_result(msg_id)
width = message["result"]["contentSize"]["width"]
height = message["result"]["contentSize"]["height"]
width = min(
message["result"]["contentSize"]["width"], self._max_screenshot_width
)
height = min(
message["result"]["contentSize"]["height"], self._max_screenshot_height
)
clip = dict(x=0, y=0, width=width, height=height, scale=1)
deviceScaleFactor = 1
screenOrientation = {"angle": 0, "type": "portraitPrimary"}