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
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 -->133.0.6943.16<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| WebKit <!-- GEN:webkit-version -->18.2<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->134.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Chromium <!-- GEN:chromium-version -->134.0.6998.35<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| WebKit <!-- GEN:webkit-version -->18.4<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->135.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |

## Documentation

Expand Down
5 changes: 5 additions & 0 deletions playwright/_impl/_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from playwright._impl._errors import is_target_closed_error
from playwright._impl._helper import (
ColorScheme,
Contrast,
ForcedColors,
HarContentPolicy,
HarMode,
Expand Down Expand Up @@ -107,6 +108,7 @@ async def new_context(
colorScheme: ColorScheme = None,
reducedMotion: ReducedMotion = None,
forcedColors: ForcedColors = None,
contrast: Contrast = None,
acceptDownloads: bool = None,
defaultBrowserType: str = None,
proxy: ProxySettings = None,
Expand Down Expand Up @@ -152,6 +154,7 @@ async def new_page(
hasTouch: bool = None,
colorScheme: ColorScheme = None,
forcedColors: ForcedColors = None,
contrast: Contrast = None,
reducedMotion: ReducedMotion = None,
acceptDownloads: bool = None,
defaultBrowserType: str = None,
Expand Down Expand Up @@ -254,6 +257,8 @@ async def prepare_browser_context_params(params: Dict) -> None:
params["reducedMotion"] = "no-override"
if params.get("forcedColors", None) == "null":
params["forcedColors"] = "no-override"
if params.get("contrast", None) == "null":
params["contrast"] = "no-override"
if "acceptDownloads" in params:
params["acceptDownloads"] = "accept" if params["acceptDownloads"] else "deny"

Expand Down
8 changes: 6 additions & 2 deletions playwright/_impl/_browser_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,12 @@ async def _inner_close() -> None:
await self._channel.send("close", {"reason": reason})
await self._closed_future

async def storage_state(self, path: Union[str, Path] = None) -> StorageState:
result = await self._channel.send_return_as_dict("storageState")
async def storage_state(
self, path: Union[str, Path] = None, indexedDB: bool = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not indexed_db?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our generator layer has some magical logic which maps indexed_db (user consuming API) to indexedDB (driver). The reason for this is that we like to use the protocol.yaml compatible property names in the implementation so we can simply pass locals() to the driver.

) -> StorageState:
result = await self._channel.send_return_as_dict(
"storageState", {"indexedDB": indexedDB}
)
if path:
await async_writefile(path, json.dumps(result))
return result
Expand Down
11 changes: 10 additions & 1 deletion playwright/_impl/_browser_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from playwright._impl._errors import Error
from playwright._impl._helper import (
ColorScheme,
Contrast,
Env,
ForcedColors,
HarContentPolicy,
Expand Down Expand Up @@ -134,6 +135,7 @@ async def launch_persistent_context(
colorScheme: ColorScheme = None,
reducedMotion: ReducedMotion = None,
forcedColors: ForcedColors = None,
contrast: Contrast = None,
acceptDownloads: bool = None,
tracesDir: Union[pathlib.Path, str] = None,
chromiumSandbox: bool = None,
Expand All @@ -150,7 +152,7 @@ async def launch_persistent_context(
recordHarContent: HarContentPolicy = None,
clientCertificates: List[ClientCertificate] = None,
) -> BrowserContext:
userDataDir = str(Path(userDataDir)) if userDataDir else ""
userDataDir = self._user_data_dir(userDataDir)
params = locals_to_params(locals())
await prepare_browser_context_params(params)
normalize_launch_params(params)
Expand All @@ -161,6 +163,13 @@ async def launch_persistent_context(
self._did_create_context(context, params, params)
return context

def _user_data_dir(self, userDataDir: Optional[Union[str, Path]]) -> str:
if not userDataDir:
return ""
if not Path(userDataDir).is_absolute():
return str(Path(userDataDir).resolve())
return str(Path(userDataDir))

async def connect_over_cdp(
self,
endpointURL: str,
Expand Down
22 changes: 15 additions & 7 deletions playwright/_impl/_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ async def new_context(
timeout: float = None,
storageState: Union[StorageState, str, Path] = None,
clientCertificates: List[ClientCertificate] = None,
failOnStatusCode: bool = None,
) -> "APIRequestContext":
params = locals_to_params(locals())
if "storageState" in params:
Expand Down Expand Up @@ -422,9 +423,13 @@ async def _inner_fetch(
return APIResponse(self, response)

async def storage_state(
self, path: Union[pathlib.Path, str] = None
self,
path: Union[pathlib.Path, str] = None,
indexedDB: bool = None,
) -> StorageState:
result = await self._channel.send_return_as_dict("storageState")
result = await self._channel.send_return_as_dict(
"storageState", {"indexedDB": indexedDB}
)
if path:
await async_writefile(path, json.dumps(result))
return result
Expand Down Expand Up @@ -475,11 +480,14 @@ def headers_array(self) -> network.HeadersArray:

async def body(self) -> bytes:
try:
result = await self._request._channel.send_return_as_dict(
"fetchResponseBody",
{
"fetchUid": self._fetch_uid,
},
result = await self._request._connection.wrap_api_call(
lambda: self._request._channel.send_return_as_dict(
"fetchResponseBody",
{
"fetchUid": self._fetch_uid,
},
),
True,
)
if result is None:
raise Error("Response has been disposed")
Expand Down
1 change: 1 addition & 0 deletions playwright/_impl/_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

ColorScheme = Literal["dark", "light", "no-preference", "null"]
ForcedColors = Literal["active", "none", "null"]
Contrast = Literal["more", "no-preference", "null"]
ReducedMotion = Literal["no-preference", "null", "reduce"]
DocumentLoadState = Literal["commit", "domcontentloaded", "load", "networkidle"]
KeyboardModifier = Literal["Alt", "Control", "ControlOrMeta", "Meta", "Shift"]
Expand Down
6 changes: 6 additions & 0 deletions playwright/_impl/_locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def __init__(
has_not_text: Union[str, Pattern[str]] = None,
has: "Locator" = None,
has_not: "Locator" = None,
visible: bool = None,
) -> None:
self._frame = frame
self._selector = selector
Expand All @@ -95,6 +96,9 @@ def __init__(
raise Error('Inner "has_not" locator must belong to the same frame.')
self._selector += " >> internal:has-not=" + json.dumps(locator._selector)

if visible is not None:
self._selector += f" >> visible={bool_to_js_bool(visible)}"

def __repr__(self) -> str:
return f"<Locator frame={self._frame!r} selector={self._selector!r}>"

Expand Down Expand Up @@ -338,6 +342,7 @@ def filter(
hasNotText: Union[str, Pattern[str]] = None,
has: "Locator" = None,
hasNot: "Locator" = None,
visible: bool = None,
) -> "Locator":
return Locator(
self._frame,
Expand All @@ -346,6 +351,7 @@ def filter(
has_not_text=hasNotText,
has=has,
has_not=hasNot,
visible=visible,
)

def or_(self, locator: "Locator") -> "Locator":
Expand Down
6 changes: 6 additions & 0 deletions playwright/_impl/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
from playwright._impl._har_router import HarRouter
from playwright._impl._helper import (
ColorScheme,
Contrast,
DocumentLoadState,
ForcedColors,
HarMode,
Expand Down Expand Up @@ -608,6 +609,7 @@ async def emulate_media(
colorScheme: ColorScheme = None,
reducedMotion: ReducedMotion = None,
forcedColors: ForcedColors = None,
contrast: Contrast = None,
) -> None:
params = locals_to_params(locals())
if "media" in params:
Expand All @@ -624,6 +626,10 @@ async def emulate_media(
params["forcedColors"] = (
"no-override" if params["forcedColors"] == "null" else forcedColors
)
if "contrast" in params:
params["contrast"] = (
"no-override" if params["contrast"] == "null" else contrast
)
await self._channel.send("emulateMedia", params)

async def set_viewport_size(self, viewportSize: ViewportSize) -> None:
Expand Down
Loading
Loading