Skip to content

Commit 275f285

Browse files
committed
Rename take_screenshot -> screenshot_b64, small cleanup
1 parent bc2adb8 commit 275f285

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Added
1313

14-
- Added `tab.take_screenshot` and `element.take_screenshot` methods to return screenshot as base64 string @falmar
14+
- Added `tab.screenshot_b64` and `element.screenshot_b64` methods to return screenshot as base64 string @falmar
1515

1616
### Changed
1717

18-
- Changed `take.save_screenshot` and `element.save_screenshot` to use `self.take_screenshot` to fetch screenshot data and only perform the file saving @falmar
19-
2018
### Removed
2119

2220
## [0.6.1] - 2025-04-25

zendriver/core/element.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -810,14 +810,14 @@ async def query_selector(self, selector):
810810
await self.update()
811811
return await self.tab.query_selector(selector, self)
812812

813-
async def take_screenshot(
813+
async def screenshot_b64(
814814
self,
815815
format: str = "jpeg",
816816
scale: typing.Optional[typing.Union[int, float]] = 1,
817-
):
817+
) -> str:
818818
"""
819-
Takes a screenshot of this element (only)
820-
This is not the same as :py:obj:`Tab.take_screenshot`, which takes a "regular" screenshot
819+
Takes a screenshot of this element (only) and return the result as a base64 encoded string.
820+
This is not the same as :py:obj:`Tab.screenshot_b64`, which takes a "regular" screenshot
821821
822822
When the element is hidden, or has no size, or is otherwise not capturable, a RuntimeError is raised
823823
@@ -848,7 +848,7 @@ async def take_screenshot(
848848
"could not take screenshot. most possible cause is the page has not finished loading yet."
849849
)
850850

851-
return str(data)
851+
return data
852852

853853
async def save_screenshot(
854854
self,
@@ -890,7 +890,7 @@ async def save_screenshot(
890890

891891
path.parent.mkdir(parents=True, exist_ok=True)
892892

893-
data = await self.take_screenshot(format, scale)
893+
data = await self.screenshot_b64(format, scale)
894894

895895
data_bytes = base64.b64decode(data)
896896
if not path:

zendriver/core/tab.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@ async def download_file(self, url: str, filename: Optional[PathLike] = None):
12851285
arguments=[cdp.runtime.CallArgument(object_id=body.object_id)],
12861286
)
12871287
)
1288-
1288+
12891289
async def save_snapshot(self, filename: str = "snapshot.mhtml") -> None:
12901290
"""
12911291
Saves a snapshot of the page.
@@ -1302,15 +1302,15 @@ async def save_snapshot(self, filename: str = "snapshot.mhtml") -> None:
13021302

13031303
with open(filename, "w") as file:
13041304
file.write(data)
1305-
1306-
async def take_screenshot(
1305+
1306+
async def screenshot_b64(
13071307
self,
13081308
format: str = "jpeg",
13091309
full_page: bool = False,
13101310
) -> str:
13111311
"""
1312-
Takes a screenshot of the page.
1313-
This is not the same as :py:obj:`Element.take_screenshot`, which takes a screenshot of a single element only
1312+
Takes a screenshot of the page and return the result as a base64 encoded string.
1313+
This is not the same as :py:obj:`Element.screenshot_b64`, which takes a screenshot of a single element only
13141314
13151315
:param format: jpeg or png (defaults to jpeg)
13161316
:type format: str
@@ -1339,7 +1339,7 @@ async def take_screenshot(
13391339
"could not take screenshot. most possible cause is the page has not finished loading yet."
13401340
)
13411341

1342-
return str(data)
1342+
return data
13431343

13441344
async def save_screenshot(
13451345
self,
@@ -1367,6 +1367,7 @@ async def save_screenshot(
13671367
ext = ".png"
13681368

13691369
if not filename or filename == "auto":
1370+
assert self.target is not None
13701371
parsed = urllib.parse.urlparse(self.target.url)
13711372
parts = parsed.path.split("/")
13721373
last_part = parts[-1]
@@ -1378,7 +1379,7 @@ async def save_screenshot(
13781379
path = pathlib.Path(filename)
13791380
path.parent.mkdir(parents=True, exist_ok=True)
13801381

1381-
data = await self.take_screenshot(format=format, full_page=full_page)
1382+
data = await self.screenshot_b64(format=format, full_page=full_page)
13821383

13831384
import base64
13841385

0 commit comments

Comments
 (0)