Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Playwright is a Python library to automate [Chromium](https://www.chromium.org/H

| | Linux | macOS | Windows |
| :--- | :---: | :---: | :---: |
| Chromium <!-- GEN:chromium-version -->96.0.4659.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| WebKit <!-- GEN:webkit-version -->15.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Chromium <!-- GEN:chromium-version -->97.0.4666.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| WebKit <!-- GEN:webkit-version -->15.4<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->92.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |

## Documentation
Expand Down
15 changes: 13 additions & 2 deletions playwright/_impl/_api_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@


class Cookie(TypedDict, total=False):
name: str
value: str
domain: str
path: str
expires: float
httpOnly: bool
secure: bool
sameSite: Literal["Lax", "None", "Strict"]


class SetCookieParam(TypedDict, total=False):
name: str
value: str
url: Optional[str]
Expand Down Expand Up @@ -88,8 +99,8 @@ class ProxySettings(TypedDict, total=False):


class StorageState(TypedDict, total=False):
cookies: Optional[List[Cookie]]
origins: Optional[List[OriginState]]
cookies: List[Cookie]
origins: List[OriginState]


class ResourceTiming(TypedDict):
Expand Down
9 changes: 7 additions & 2 deletions playwright/_impl/_browser_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
from types import SimpleNamespace
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Set, Union, cast

from playwright._impl._api_structures import Cookie, Geolocation, StorageState
from playwright._impl._api_structures import (
Cookie,
Geolocation,
SetCookieParam,
StorageState,
)
from playwright._impl._api_types import Error
from playwright._impl._artifact import Artifact
from playwright._impl._cdp_session import CDPSession
Expand Down Expand Up @@ -200,7 +205,7 @@ async def cookies(self, urls: Union[str, List[str]] = None) -> List[Cookie]:
urls = [urls]
return await self._channel.send("cookies", dict(urls=urls))

async def add_cookies(self, cookies: List[Cookie]) -> None:
async def add_cookies(self, cookies: List[SetCookieParam]) -> None:
await self._channel.send("addCookies", dict(cookies=cookies))

async def clear_cookies(self) -> None:
Expand Down
5 changes: 1 addition & 4 deletions playwright/_impl/_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,7 @@ async def header_value(self, name: str) -> Optional[str]:
async def _actual_headers(self) -> "RawHeaders":
if not self._all_headers_future:
self._all_headers_future = asyncio.Future()
response = await self.response()
if not response:
return self._provisional_headers
headers = await response._channel.send("rawRequestHeaders")
headers = await self._channel.send("rawRequestHeaders")
self._all_headers_future.set_result(RawHeaders(headers))
return await self._all_headers_future

Expand Down
11 changes: 6 additions & 5 deletions playwright/async_api/_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
RequestSizes,
ResourceTiming,
SecurityDetails,
SetCookieParam,
SourceLocation,
StorageState,
ViewportSize,
Expand Down Expand Up @@ -10091,7 +10092,7 @@ async def cookies(

Returns
-------
List[{name: str, value: str, url: Union[str, NoneType], domain: Union[str, NoneType], path: Union[str, NoneType], expires: Union[float, NoneType], httpOnly: Union[bool, NoneType], secure: Union[bool, NoneType], sameSite: Union["Lax", "None", "Strict", NoneType]}]
List[{name: str, value: str, domain: str, path: str, expires: float, httpOnly: bool, secure: bool, sameSite: Union["Lax", "None", "Strict"]}]
"""

return mapping.from_impl_list(
Expand All @@ -10100,7 +10101,7 @@ async def cookies(
)
)

async def add_cookies(self, cookies: typing.List[Cookie]) -> NoneType:
async def add_cookies(self, cookies: typing.List[SetCookieParam]) -> NoneType:
"""BrowserContext.add_cookies

Adds cookies into this browser context. All pages within this context will have these cookies installed. Cookies can be
Expand Down Expand Up @@ -10611,7 +10612,7 @@ async def storage_state(

Returns
-------
{cookies: Union[List[{name: str, value: str, url: Union[str, NoneType], domain: Union[str, NoneType], path: Union[str, NoneType], expires: Union[float, NoneType], httpOnly: Union[bool, NoneType], secure: Union[bool, NoneType], sameSite: Union["Lax", "None", "Strict", NoneType]}], NoneType], origins: Union[List[{origin: str, localStorage: List[{name: str, value: str}]}], NoneType]}
{cookies: List[{name: str, value: str, domain: str, path: str, expires: float, httpOnly: bool, secure: bool, sameSite: Union["Lax", "None", "Strict"]}], origins: List[{origin: str, localStorage: List[{name: str, value: str}]}]}
"""

return mapping.from_impl(
Expand Down Expand Up @@ -10943,7 +10944,7 @@ async def new_context(
Dimensions of the recorded videos. If not specified the size will be equal to `viewport` scaled down to fit into
800x800. If `viewport` is not configured explicitly the video size defaults to 800x450. Actual picture of each page will
be scaled down if necessary to fit the specified size.
storage_state : Union[pathlib.Path, str, {cookies: Union[List[{name: str, value: str, url: Union[str, NoneType], domain: Union[str, NoneType], path: Union[str, NoneType], expires: Union[float, NoneType], httpOnly: Union[bool, NoneType], secure: Union[bool, NoneType], sameSite: Union["Lax", "None", "Strict", NoneType]}], NoneType], origins: Union[List[{origin: str, localStorage: List[{name: str, value: str}]}], NoneType]}, NoneType]
storage_state : Union[pathlib.Path, str, {cookies: List[{name: str, value: str, domain: str, path: str, expires: float, httpOnly: bool, secure: bool, sameSite: Union["Lax", "None", "Strict"]}], origins: List[{origin: str, localStorage: List[{name: str, value: str}]}]}, NoneType]
Populates context with given storage state. This option can be used to initialize context with logged-in information
obtained via `browser_context.storage_state()`. Either a path to the file with saved storage, or an object with
the following fields:
Expand Down Expand Up @@ -11117,7 +11118,7 @@ async def new_page(
Dimensions of the recorded videos. If not specified the size will be equal to `viewport` scaled down to fit into
800x800. If `viewport` is not configured explicitly the video size defaults to 800x450. Actual picture of each page will
be scaled down if necessary to fit the specified size.
storage_state : Union[pathlib.Path, str, {cookies: Union[List[{name: str, value: str, url: Union[str, NoneType], domain: Union[str, NoneType], path: Union[str, NoneType], expires: Union[float, NoneType], httpOnly: Union[bool, NoneType], secure: Union[bool, NoneType], sameSite: Union["Lax", "None", "Strict", NoneType]}], NoneType], origins: Union[List[{origin: str, localStorage: List[{name: str, value: str}]}], NoneType]}, NoneType]
storage_state : Union[pathlib.Path, str, {cookies: List[{name: str, value: str, domain: str, path: str, expires: float, httpOnly: bool, secure: bool, sameSite: Union["Lax", "None", "Strict"]}], origins: List[{origin: str, localStorage: List[{name: str, value: str}]}]}, NoneType]
Populates context with given storage state. This option can be used to initialize context with logged-in information
obtained via `browser_context.storage_state()`. Either a path to the file with saved storage, or an object with
the following fields:
Expand Down
11 changes: 6 additions & 5 deletions playwright/sync_api/_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
RequestSizes,
ResourceTiming,
SecurityDetails,
SetCookieParam,
SourceLocation,
StorageState,
ViewportSize,
Expand Down Expand Up @@ -9853,14 +9854,14 @@ def cookies(

Returns
-------
List[{name: str, value: str, url: Union[str, NoneType], domain: Union[str, NoneType], path: Union[str, NoneType], expires: Union[float, NoneType], httpOnly: Union[bool, NoneType], secure: Union[bool, NoneType], sameSite: Union["Lax", "None", "Strict", NoneType]}]
List[{name: str, value: str, domain: str, path: str, expires: float, httpOnly: bool, secure: bool, sameSite: Union["Lax", "None", "Strict"]}]
"""

return mapping.from_impl_list(
self._sync("browser_context.cookies", self._impl_obj.cookies(urls=urls))
)

def add_cookies(self, cookies: typing.List[Cookie]) -> NoneType:
def add_cookies(self, cookies: typing.List[SetCookieParam]) -> NoneType:
"""BrowserContext.add_cookies

Adds cookies into this browser context. All pages within this context will have these cookies installed. Cookies can be
Expand Down Expand Up @@ -10364,7 +10365,7 @@ def storage_state(

Returns
-------
{cookies: Union[List[{name: str, value: str, url: Union[str, NoneType], domain: Union[str, NoneType], path: Union[str, NoneType], expires: Union[float, NoneType], httpOnly: Union[bool, NoneType], secure: Union[bool, NoneType], sameSite: Union["Lax", "None", "Strict", NoneType]}], NoneType], origins: Union[List[{origin: str, localStorage: List[{name: str, value: str}]}], NoneType]}
{cookies: List[{name: str, value: str, domain: str, path: str, expires: float, httpOnly: bool, secure: bool, sameSite: Union["Lax", "None", "Strict"]}], origins: List[{origin: str, localStorage: List[{name: str, value: str}]}]}
"""

return mapping.from_impl(
Expand Down Expand Up @@ -10690,7 +10691,7 @@ def new_context(
Dimensions of the recorded videos. If not specified the size will be equal to `viewport` scaled down to fit into
800x800. If `viewport` is not configured explicitly the video size defaults to 800x450. Actual picture of each page will
be scaled down if necessary to fit the specified size.
storage_state : Union[pathlib.Path, str, {cookies: Union[List[{name: str, value: str, url: Union[str, NoneType], domain: Union[str, NoneType], path: Union[str, NoneType], expires: Union[float, NoneType], httpOnly: Union[bool, NoneType], secure: Union[bool, NoneType], sameSite: Union["Lax", "None", "Strict", NoneType]}], NoneType], origins: Union[List[{origin: str, localStorage: List[{name: str, value: str}]}], NoneType]}, NoneType]
storage_state : Union[pathlib.Path, str, {cookies: List[{name: str, value: str, domain: str, path: str, expires: float, httpOnly: bool, secure: bool, sameSite: Union["Lax", "None", "Strict"]}], origins: List[{origin: str, localStorage: List[{name: str, value: str}]}]}, NoneType]
Populates context with given storage state. This option can be used to initialize context with logged-in information
obtained via `browser_context.storage_state()`. Either a path to the file with saved storage, or an object with
the following fields:
Expand Down Expand Up @@ -10864,7 +10865,7 @@ def new_page(
Dimensions of the recorded videos. If not specified the size will be equal to `viewport` scaled down to fit into
800x800. If `viewport` is not configured explicitly the video size defaults to 800x450. Actual picture of each page will
be scaled down if necessary to fit the specified size.
storage_state : Union[pathlib.Path, str, {cookies: Union[List[{name: str, value: str, url: Union[str, NoneType], domain: Union[str, NoneType], path: Union[str, NoneType], expires: Union[float, NoneType], httpOnly: Union[bool, NoneType], secure: Union[bool, NoneType], sameSite: Union["Lax", "None", "Strict", NoneType]}], NoneType], origins: Union[List[{origin: str, localStorage: List[{name: str, value: str}]}], NoneType]}, NoneType]
storage_state : Union[pathlib.Path, str, {cookies: List[{name: str, value: str, domain: str, path: str, expires: float, httpOnly: bool, secure: bool, sameSite: Union["Lax", "None", "Strict"]}], origins: List[{origin: str, localStorage: List[{name: str, value: str}]}]}, NoneType]
Populates context with given storage state. This option can be used to initialize context with logged-in information
obtained via `browser_context.storage_state()`. Either a path to the file with saved storage, or an object with
the following fields:
Expand Down
3 changes: 0 additions & 3 deletions scripts/expected_api_mismatch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ Parameter type mismatch in BrowserContext.unroute(handler=): documented as Union
Parameter type mismatch in Page.route(handler=): documented as Callable[[Route, Request], Any], code has Union[Callable[[Route, Request], Any], Callable[[Route], Any]]
Parameter type mismatch in Page.unroute(handler=): documented as Union[Callable[[Route, Request], Any], NoneType], code has Union[Callable[[Route, Request], Any], Callable[[Route], Any], NoneType]

# Get vs set cookies
Parameter type mismatch in BrowserContext.storage_state(return=): documented as {cookies: List[{name: str, value: str, domain: str, path: str, expires: float, httpOnly: bool, secure: bool, sameSite: Union["Lax", "None", "Strict"]}], origins: List[{origin: str, localStorage: List[{name: str, value: str}]}]}, code has {cookies: Union[List[{name: str, value: str, url: Union[str, NoneType], domain: Union[str, NoneType], path: Union[str, NoneType], expires: Union[float, NoneType], httpOnly: Union[bool, NoneType], secure: Union[bool, NoneType], sameSite: Union["Lax", "None", "Strict", NoneType]}], NoneType], origins: Union[List[{origin: str, localStorage: List[{name: str, value: str}]}], NoneType]}
Parameter type mismatch in BrowserContext.cookies(return=): documented as List[{name: str, value: str, domain: str, path: str, expires: float, httpOnly: bool, secure: bool, sameSite: Union["Lax", "None", "Strict"]}], code has List[{name: str, value: str, url: Union[str, NoneType], domain: Union[str, NoneType], path: Union[str, NoneType], expires: Union[float, NoneType], httpOnly: Union[bool, NoneType], secure: Union[bool, NoneType], sameSite: Union["Lax", "None", "Strict", NoneType]}]
# Temporary Fix
Method not implemented: Error.name
Method not implemented: Error.stack
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def return_value(value: Any) -> List[str]:


from playwright._impl._accessibility import Accessibility as AccessibilityImpl
from playwright._impl._api_structures import Cookie, FloatRect, FilePayload, Geolocation, HttpCredentials, PdfMargins, Position, ProxySettings, ResourceTiming, SourceLocation, StorageState, ViewportSize, RemoteAddr, SecurityDetails, RequestSizes, NameValue
from playwright._impl._api_structures import Cookie, SetCookieParam, FloatRect, FilePayload, Geolocation, HttpCredentials, PdfMargins, Position, ProxySettings, ResourceTiming, SourceLocation, StorageState, ViewportSize, RemoteAddr, SecurityDetails, RequestSizes, NameValue
from playwright._impl._browser import Browser as BrowserImpl
from playwright._impl._browser_context import BrowserContext as BrowserContextImpl
from playwright._impl._browser_type import BrowserType as BrowserTypeImpl
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
InWheel = None
from wheel.bdist_wheel import bdist_wheel as BDistWheelCommand

driver_version = "1.16.0-next-1633339886000"
driver_version = "1.16.0-next-1634054506000"


def extractall(zip: zipfile.ZipFile, path: str) -> None:
Expand Down
2 changes: 2 additions & 0 deletions tests/async/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

async def test_request_fulfill(page, server):
async def handle_request(route: Route, request: Request):
headers = await route.request.all_headers()
assert headers["accept"]
assert route.request == request
assert repr(route) == f"<Route request={route.request}>"
assert "empty.html" in request.url
Expand Down