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

| | Linux | macOS | Windows |
| :--- | :---: | :---: | :---: |
| Chromium <!-- GEN:chromium-version -->127.0.6533.17<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| WebKit <!-- GEN:webkit-version -->17.4<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->127.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Chromium <!-- GEN:chromium-version -->128.0.6613.18<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| WebKit <!-- GEN:webkit-version -->18.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->128.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |

## Documentation

Expand Down
18 changes: 9 additions & 9 deletions local-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
auditwheel==6.0.0
auditwheel==6.1.0
autobahn==23.1.2
black==24.4.2
flake8==7.1.0
black==24.8.0
flake8==7.1.1
flaky==3.8.1
mypy==1.10.1
mypy==1.11.1
objgraph==3.6.1
Pillow==10.4.0
pixelmatch==0.3.0
pre-commit==3.4.0
pyOpenSSL==24.1.0
pytest==8.2.2
pyOpenSSL==24.2.1
pytest==8.3.2
pytest-asyncio==0.21.2
pytest-cov==5.0.0
pytest-repeat==0.9.3
pytest-timeout==2.3.1
pytest-xdist==3.6.1
requests==2.32.3
service_identity==24.1.0
setuptools==70.3.0
twisted==24.3.0
types-pyOpenSSL==24.1.0.20240425
setuptools==72.1.0
twisted==24.7.0
types-pyOpenSSL==24.1.0.20240722
types-requests==2.32.0.20240712
wheel==0.42.0
9 changes: 9 additions & 0 deletions playwright/_impl/_api_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from pathlib import Path
from typing import Any, Dict, List, Literal, Optional, Sequence, TypedDict, Union

# These are the structures that we like keeping in a JSON form for their potential
Expand Down Expand Up @@ -100,6 +101,14 @@ class StorageState(TypedDict, total=False):
origins: List[OriginState]


class ClientCertificate(TypedDict, total=False):
origin: str
certPath: Optional[Union[str, Path]]
keyPath: Optional[Union[str, Path]]
pfxPath: Optional[Union[str, Path]]
passphrase: Optional[str]


class ResourceTiming(TypedDict):
startTime: float
domainLookupStart: float
Expand Down
10 changes: 9 additions & 1 deletion playwright/_impl/_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from typing import TYPE_CHECKING, Dict, List, Optional, Pattern, Sequence, Union, cast

from playwright._impl._api_structures import (
ClientCertificate,
Geolocation,
HttpCredentials,
ProxySettings,
Expand All @@ -41,7 +42,7 @@
make_dirs_for_file,
prepare_record_har_options,
)
from playwright._impl._network import serialize_headers
from playwright._impl._network import serialize_headers, to_client_certificates_protocol
from playwright._impl._page import Page

if TYPE_CHECKING: # pragma: no cover
Expand Down Expand Up @@ -120,6 +121,7 @@ async def new_context(
recordHarUrlFilter: Union[Pattern[str], str] = None,
recordHarMode: HarMode = None,
recordHarContent: HarContentPolicy = None,
clientCertificates: List[ClientCertificate] = None,
) -> BrowserContext:
params = locals_to_params(locals())
await prepare_browser_context_params(params)
Expand Down Expand Up @@ -165,6 +167,7 @@ async def new_page(
recordHarUrlFilter: Union[Pattern[str], str] = None,
recordHarMode: HarMode = None,
recordHarContent: HarContentPolicy = None,
clientCertificates: List[ClientCertificate] = None,
) -> Page:
params = locals_to_params(locals())

Expand Down Expand Up @@ -253,3 +256,8 @@ async def prepare_browser_context_params(params: Dict) -> None:
params["forcedColors"] = "no-override"
if "acceptDownloads" in params:
params["acceptDownloads"] = "accept" if params["acceptDownloads"] else "deny"

if "clientCertificates" in params:
params["clientCertificates"] = await to_client_certificates_protocol(
params["clientCertificates"]
)
11 changes: 10 additions & 1 deletion playwright/_impl/_browser_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
import asyncio
import pathlib
from pathlib import Path
from typing import TYPE_CHECKING, Dict, Optional, Pattern, Sequence, Union, cast
from typing import TYPE_CHECKING, Dict, List, Optional, Pattern, Sequence, Union, cast

from playwright._impl._api_structures import (
ClientCertificate,
Geolocation,
HttpCredentials,
ProxySettings,
Expand Down Expand Up @@ -147,6 +148,7 @@ async def launch_persistent_context(
recordHarUrlFilter: Union[Pattern[str], str] = None,
recordHarMode: HarMode = None,
recordHarContent: HarContentPolicy = None,
clientCertificates: List[ClientCertificate] = None,
) -> BrowserContext:
userDataDir = str(Path(userDataDir)) if userDataDir else ""
params = locals_to_params(locals())
Expand Down Expand Up @@ -229,6 +231,13 @@ def handle_transport_close(reason: Optional[str]) -> None:
context._on_close()
browser._on_close()
connection.cleanup(reason)
# TODO: Backport https://github.com/microsoft/playwright/commit/d8d5289e8692c9b1265d23ee66988d1ac5122f33
# Give a chance to any API call promises to reject upon page/context closure.
# This happens naturally when we receive page.onClose and browser.onClose from the server
# in separate tasks. However, upon pipe closure we used to dispatch them all synchronously
# here and promises did not have a chance to reject.
# The order of rejects vs closure is a part of the API contract and our test runner
# relies on it to attribute rejections to the right test.

transport.once("close", handle_transport_close)

Expand Down
3 changes: 0 additions & 3 deletions playwright/_impl/_element_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ async def set_input_files(
"setInputFiles",
{
"timeout": timeout,
"noWaitAfter": noWaitAfter,
**converted,
},
)
Expand Down Expand Up @@ -246,15 +245,13 @@ async def set_checked(
position=position,
timeout=timeout,
force=force,
noWaitAfter=noWaitAfter,
trial=trial,
)
else:
await self.uncheck(
position=position,
timeout=timeout,
force=force,
noWaitAfter=noWaitAfter,
trial=trial,
)

Expand Down
26 changes: 25 additions & 1 deletion playwright/_impl/_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import playwright._impl._network as network
from playwright._impl._api_structures import (
ClientCertificate,
FilePayload,
FormField,
Headers,
Expand All @@ -42,7 +43,7 @@
object_to_array,
to_impl,
)
from playwright._impl._network import serialize_headers
from playwright._impl._network import serialize_headers, to_client_certificates_protocol
from playwright._impl._tracing import Tracing

if typing.TYPE_CHECKING:
Expand Down Expand Up @@ -71,6 +72,7 @@ async def new_context(
userAgent: str = None,
timeout: float = None,
storageState: Union[StorageState, str, Path] = None,
clientCertificates: List[ClientCertificate] = None,
) -> "APIRequestContext":
params = locals_to_params(locals())
if "storageState" in params:
Expand All @@ -81,6 +83,9 @@ async def new_context(
)
if "extraHTTPHeaders" in params:
params["extraHTTPHeaders"] = serialize_headers(params["extraHTTPHeaders"])
params["clientCertificates"] = await to_client_certificates_protocol(
params.get("clientCertificates")
)
context = cast(
APIRequestContext,
from_channel(await self.playwright._channel.send("newRequest", params)),
Expand Down Expand Up @@ -118,6 +123,7 @@ async def delete(
failOnStatusCode: bool = None,
ignoreHTTPSErrors: bool = None,
maxRedirects: int = None,
maxRetries: int = None,
) -> "APIResponse":
return await self.fetch(
url,
Expand All @@ -131,6 +137,7 @@ async def delete(
failOnStatusCode=failOnStatusCode,
ignoreHTTPSErrors=ignoreHTTPSErrors,
maxRedirects=maxRedirects,
maxRetries=maxRetries,
)

async def head(
Expand All @@ -145,6 +152,7 @@ async def head(
failOnStatusCode: bool = None,
ignoreHTTPSErrors: bool = None,
maxRedirects: int = None,
maxRetries: int = None,
) -> "APIResponse":
return await self.fetch(
url,
Expand All @@ -158,6 +166,7 @@ async def head(
failOnStatusCode=failOnStatusCode,
ignoreHTTPSErrors=ignoreHTTPSErrors,
maxRedirects=maxRedirects,
maxRetries=maxRetries,
)

async def get(
Expand All @@ -172,6 +181,7 @@ async def get(
failOnStatusCode: bool = None,
ignoreHTTPSErrors: bool = None,
maxRedirects: int = None,
maxRetries: int = None,
) -> "APIResponse":
return await self.fetch(
url,
Expand All @@ -185,6 +195,7 @@ async def get(
failOnStatusCode=failOnStatusCode,
ignoreHTTPSErrors=ignoreHTTPSErrors,
maxRedirects=maxRedirects,
maxRetries=maxRetries,
)

async def patch(
Expand All @@ -199,6 +210,7 @@ async def patch(
failOnStatusCode: bool = None,
ignoreHTTPSErrors: bool = None,
maxRedirects: int = None,
maxRetries: int = None,
) -> "APIResponse":
return await self.fetch(
url,
Expand All @@ -212,6 +224,7 @@ async def patch(
failOnStatusCode=failOnStatusCode,
ignoreHTTPSErrors=ignoreHTTPSErrors,
maxRedirects=maxRedirects,
maxRetries=maxRetries,
)

async def put(
Expand All @@ -226,6 +239,7 @@ async def put(
failOnStatusCode: bool = None,
ignoreHTTPSErrors: bool = None,
maxRedirects: int = None,
maxRetries: int = None,
) -> "APIResponse":
return await self.fetch(
url,
Expand All @@ -239,6 +253,7 @@ async def put(
failOnStatusCode=failOnStatusCode,
ignoreHTTPSErrors=ignoreHTTPSErrors,
maxRedirects=maxRedirects,
maxRetries=maxRetries,
)

async def post(
Expand All @@ -253,6 +268,7 @@ async def post(
failOnStatusCode: bool = None,
ignoreHTTPSErrors: bool = None,
maxRedirects: int = None,
maxRetries: int = None,
) -> "APIResponse":
return await self.fetch(
url,
Expand All @@ -266,6 +282,7 @@ async def post(
failOnStatusCode=failOnStatusCode,
ignoreHTTPSErrors=ignoreHTTPSErrors,
maxRedirects=maxRedirects,
maxRetries=maxRetries,
)

async def fetch(
Expand All @@ -281,6 +298,7 @@ async def fetch(
failOnStatusCode: bool = None,
ignoreHTTPSErrors: bool = None,
maxRedirects: int = None,
maxRetries: int = None,
) -> "APIResponse":
url = urlOrRequest if isinstance(urlOrRequest, str) else None
request = (
Expand All @@ -304,6 +322,7 @@ async def fetch(
failOnStatusCode,
ignoreHTTPSErrors,
maxRedirects,
maxRetries,
)

async def _inner_fetch(
Expand All @@ -320,6 +339,7 @@ async def _inner_fetch(
failOnStatusCode: bool = None,
ignoreHTTPSErrors: bool = None,
maxRedirects: int = None,
maxRetries: int = None,
) -> "APIResponse":
if self._close_reason:
raise TargetClosedError(self._close_reason)
Expand All @@ -329,6 +349,9 @@ async def _inner_fetch(
assert (
maxRedirects is None or maxRedirects >= 0
), "'max_redirects' must be greater than or equal to '0'"
assert (
maxRetries is None or maxRetries >= 0
), "'max_retries' must be greater than or equal to '0'"
url = url or (request.url if request else url)
method = method or (request.method if request else "GET")
# Cannot call allHeaders() here as the request may be paused inside route handler.
Expand Down Expand Up @@ -392,6 +415,7 @@ async def _inner_fetch(
"failOnStatusCode": failOnStatusCode,
"ignoreHTTPSErrors": ignoreHTTPSErrors,
"maxRedirects": maxRedirects,
"maxRetries": maxRetries,
},
)
return APIResponse(self, response)
Expand Down
3 changes: 0 additions & 3 deletions playwright/_impl/_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,6 @@ async def set_input_files(
"selector": selector,
"strict": strict,
"timeout": timeout,
"noWaitAfter": noWaitAfter,
**converted,
},
)
Expand Down Expand Up @@ -792,7 +791,6 @@ async def set_checked(
position=position,
timeout=timeout,
force=force,
noWaitAfter=noWaitAfter,
strict=strict,
trial=trial,
)
Expand All @@ -802,7 +800,6 @@ async def set_checked(
position=position,
timeout=timeout,
force=force,
noWaitAfter=noWaitAfter,
strict=strict,
trial=trial,
)
Expand Down
Loading