|
18 | 18 | import pathlib |
19 | 19 | import typing |
20 | 20 | from pathlib import Path |
21 | | -from typing import Any, Dict, List, Optional, Sequence, Union, cast |
| 21 | +from typing import Any, Dict, List, Optional, Pattern, Sequence, Union, cast |
22 | 22 |
|
23 | 23 | import playwright._impl._network as network |
24 | 24 | from playwright._impl._api_structures import ( |
25 | 25 | ClientCertificate, |
| 26 | + Cookie, |
26 | 27 | FilePayload, |
27 | 28 | FormField, |
28 | 29 | Headers, |
|
32 | 33 | ResourceTiming, |
33 | 34 | SecurityDetails, |
34 | 35 | ServerFilePayload, |
| 36 | + SetCookieParam, |
35 | 37 | StorageState, |
36 | 38 | ) |
37 | 39 | from playwright._impl._connection import ChannelOwner, from_channel |
|
51 | 53 | ) |
52 | 54 | from playwright._impl._network import ( |
53 | 55 | serialize_headers, |
| 56 | + to_clear_cookies_params, |
54 | 57 | to_client_certificates_protocol, |
55 | 58 | to_http_credentials_protocol, |
56 | 59 | ) |
@@ -136,6 +139,26 @@ async def dispose(self, reason: str = None) -> None: |
136 | 139 | def tracing(self) -> Tracing: |
137 | 140 | return self._tracing |
138 | 141 |
|
| 142 | + async def cookies(self, urls: Union[str, Sequence[str]] = None) -> List[Cookie]: |
| 143 | + if urls is None: |
| 144 | + urls = [] |
| 145 | + if isinstance(urls, str): |
| 146 | + urls = [urls] |
| 147 | + return await self._channel.send("cookies", None, dict(urls=urls)) |
| 148 | + |
| 149 | + async def add_cookies(self, cookies: Sequence[SetCookieParam]) -> None: |
| 150 | + await self._channel.send("addCookies", None, dict(cookies=cookies)) |
| 151 | + |
| 152 | + async def clear_cookies( |
| 153 | + self, |
| 154 | + name: Union[str, Pattern[str]] = None, |
| 155 | + domain: Union[str, Pattern[str]] = None, |
| 156 | + path: Union[str, Pattern[str]] = None, |
| 157 | + ) -> None: |
| 158 | + await self._channel.send( |
| 159 | + "clearCookies", None, to_clear_cookies_params(name, domain, path) |
| 160 | + ) |
| 161 | + |
139 | 162 | async def delete( |
140 | 163 | self, |
141 | 164 | url: str, |
|
0 commit comments