Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/crawlee/crawlers/_playwright/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING, Literal, Protocol, TypedDict

from playwright.async_api import APIResponse

from crawlee import HttpHeaders
from crawlee._utils.docs import docs_group

if TYPE_CHECKING:
from collections.abc import AsyncGenerator

from playwright.async_api import APIResponse, Response
from playwright.async_api import Response
from typing_extensions import NotRequired, Self


Expand Down Expand Up @@ -56,6 +58,9 @@ async def from_playwright_response(cls, response: Response | APIResponse, protoc
# Used http protocol version cannot be obtained from `Response` and has to be passed as additional argument.
http_version = protocol
_content = await response.body()
# If not called then the body will stay in memory until the context closes.
if isinstance(response, APIResponse):
await response.dispose()

return cls(http_version=http_version, status_code=status_code, headers=headers, _content=_content)

Expand Down
Loading