Skip to content

Commit 203d960

Browse files
committed
feat: refactor network response handling for base64 encoding support
1 parent bd548b5 commit 203d960

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

pydoll/browser/page.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,13 @@ async def get_network_response_bodies(self, matches: list[str] = []):
239239
responses = []
240240
for log in logs_matched:
241241
try:
242-
response = await self.get_network_response_body(
242+
body, base64encoded = await self.get_network_response_body(
243243
log['params']['requestId']
244244
)
245245
except KeyError:
246246
continue
247-
responses.append(json.loads(response))
247+
response = json.loads(body) if not base64encoded else body
248+
responses.append(response)
248249
return responses
249250

250251
async def get_network_response_body(self, request_id: str):
@@ -260,7 +261,10 @@ async def get_network_response_body(self, request_id: str):
260261
response = await self._execute_command(
261262
NetworkCommands.get_response_body(request_id)
262263
)
263-
return response['result']['body']
264+
return (
265+
response['result']['body'],
266+
response['result']['base64Encoded'],
267+
)
264268

265269
async def enable_page_events(self):
266270
"""

pydoll/element.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,7 @@ async def get_screenshot(self, path: str):
189189
'scale': 1,
190190
}
191191
screenshot = await self._connection_handler.execute_command(
192-
PageCommands.screenshot(
193-
format='jpeg', clip=clip
194-
)
192+
PageCommands.screenshot(format='jpeg', clip=clip)
195193
)
196194
async with aiofiles.open(path, 'wb') as file:
197195
image_bytes = decode_image_to_bytes(screenshot['result']['data'])

0 commit comments

Comments
 (0)