Skip to content

Commit fedfaed

Browse files
committed
make tests pass
1 parent 3ed5b5c commit fedfaed

12 files changed

+368
-195
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Playwright is a Python library to automate [Chromium](https://www.chromium.org/H
44

55
| | Linux | macOS | Windows |
66
| :--- | :---: | :---: | :---: |
7-
| Chromium <!-- GEN:chromium-version -->130.0.6723.19<!-- GEN:stop --> ||||
7+
| Chromium <!-- GEN:chromium-version -->130.0.6723.31<!-- GEN:stop --> ||||
88
| WebKit <!-- GEN:webkit-version -->18.0<!-- GEN:stop --> ||||
9-
| Firefox <!-- GEN:firefox-version -->130.0<!-- GEN:stop --> ||||
9+
| Firefox <!-- GEN:firefox-version -->131.0<!-- GEN:stop --> ||||
1010

1111
## Documentation
1212

playwright/_impl/_browser_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ async def _on_route(self, route: Route) -> None:
260260
try:
261261
# If the page is closed or unrouteAll() was called without waiting and interception disabled,
262262
# the method will throw an error - silence it.
263-
await route._internal_continue(is_internal=True)
263+
await route._inner_continue(True)
264264
except Exception:
265265
pass
266266

playwright/_impl/_connection.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def __init__(
132132
self._channel: Channel = Channel(self._connection, self)
133133
self._initializer = initializer
134134
self._was_collected = False
135+
self._is_internal_type = False
135136

136137
self._connection._objects[guid] = self
137138
if self._parent:
@@ -156,6 +157,9 @@ def _adopt(self, child: "ChannelOwner") -> None:
156157
self._objects[child._guid] = child
157158
child._parent = self
158159

160+
def mark_as_internal_type(self) -> None:
161+
self._is_internal_type = True
162+
159163
def _set_event_to_subscription_mapping(self, mapping: Dict[str, str]) -> None:
160164
self._event_to_subscription_mapping = mapping
161165

@@ -353,7 +357,7 @@ def _send_message_to_server(
353357
"params": self._replace_channels_with_guids(params),
354358
"metadata": metadata,
355359
}
356-
if self._tracing_count > 0 and frames and object._guid != "localUtils":
360+
if self._tracing_count > 0 and frames and not object._is_internal_type:
357361
self.local_utils.add_stack_to_tracing_no_reply(id, frames)
358362

359363
self._transport.send(message)

playwright/_impl/_fetch.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import typing
1919
from pathlib import Path
2020
from typing import Any, Dict, List, Optional, Union, cast
21-
from urllib.parse import parse_qs
2221

2322
import playwright._impl._network as network
2423
from playwright._impl._api_structures import (
@@ -405,7 +404,8 @@ async def _inner_fetch(
405404
"fetch",
406405
{
407406
"url": url,
408-
"params": params_to_protocol(params),
407+
"params": object_to_array(params) if isinstance(params, dict) else None,
408+
"encodedParams": params if isinstance(params, str) else None,
409409
"method": method,
410410
"headers": serialized_headers,
411411
"postData": post_data,
@@ -430,23 +430,6 @@ async def storage_state(
430430
return result
431431

432432

433-
def params_to_protocol(params: Optional[ParamsType]) -> Optional[List[NameValue]]:
434-
if not params:
435-
return None
436-
if isinstance(params, dict):
437-
return object_to_array(params)
438-
if params.startswith("?"):
439-
params = params[1:]
440-
parsed = parse_qs(params)
441-
if not parsed:
442-
return None
443-
out = []
444-
for name, values in parsed.items():
445-
for value in values:
446-
out.append(NameValue(name=name, value=value))
447-
return out
448-
449-
450433
def file_payload_to_json(payload: FilePayload) -> ServerFilePayload:
451434
return ServerFilePayload(
452435
name=payload["name"],

playwright/_impl/_local_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def __init__(
2525
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
2626
) -> None:
2727
super().__init__(parent, type, guid, initializer)
28+
self.mark_as_internal_type()
2829
self.devices = {
2930
device["name"]: parse_device_descriptor(device["descriptor"])
3031
for device in initializer["deviceDescriptors"]

playwright/_impl/_network.py

Lines changed: 31 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
)
4848
from playwright._impl._connection import (
4949
ChannelOwner,
50-
Connection,
5150
from_channel,
5251
from_nullable_channel,
5352
)
@@ -318,6 +317,7 @@ def __init__(
318317
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
319318
) -> None:
320319
super().__init__(parent, type, guid, initializer)
320+
self.mark_as_internal_type()
321321
self._handling_future: Optional[asyncio.Future["bool"]] = None
322322
self._context: "BrowserContext" = cast("BrowserContext", None)
323323
self._did_throw = False
@@ -350,7 +350,6 @@ async def abort(self, errorCode: str = None) -> None:
350350
"abort",
351351
{
352352
"errorCode": errorCode,
353-
"requestUrl": self.request._initializer["url"],
354353
},
355354
)
356355
)
@@ -433,7 +432,6 @@ async def _inner_fulfill(
433432
if length and "content-length" not in headers:
434433
headers["content-length"] = str(length)
435434
params["headers"] = serialize_headers(headers)
436-
params["requestUrl"] = self.request._initializer["url"]
437435

438436
await self._race_with_page_close(self._channel.send("fulfill", params))
439437

@@ -492,43 +490,28 @@ async def continue_(
492490

493491
async def _inner() -> None:
494492
self.request._apply_fallback_overrides(overrides)
495-
await self._internal_continue()
493+
await self._inner_continue(False)
496494

497495
return await self._handle_route(_inner)
498496

499-
def _internal_continue(
500-
self, is_internal: bool = False
501-
) -> Coroutine[Any, Any, None]:
502-
async def continue_route() -> None:
503-
try:
504-
params: Dict[str, Any] = {}
505-
params["url"] = self.request._fallback_overrides.url
506-
params["method"] = self.request._fallback_overrides.method
507-
params["headers"] = self.request._fallback_overrides.headers
508-
if self.request._fallback_overrides.post_data_buffer is not None:
509-
params["postData"] = base64.b64encode(
510-
self.request._fallback_overrides.post_data_buffer
511-
).decode()
512-
params = locals_to_params(params)
513-
514-
if "headers" in params:
515-
params["headers"] = serialize_headers(params["headers"])
516-
params["requestUrl"] = self.request._initializer["url"]
517-
params["isFallback"] = is_internal
518-
await self._connection.wrap_api_call(
519-
lambda: self._race_with_page_close(
520-
self._channel.send(
521-
"continue",
522-
params,
523-
)
524-
),
525-
is_internal,
526-
)
527-
except Exception as e:
528-
if not is_internal:
529-
raise e
530-
531-
return continue_route()
497+
async def _inner_continue(self, is_fallback: bool = False) -> None:
498+
options = self.request._fallback_overrides
499+
await self._race_with_page_close(
500+
self._channel.send(
501+
"continue",
502+
{
503+
"url": options.url,
504+
"method": options.method,
505+
"headers": serialize_headers(options.headers)
506+
if options.headers
507+
else None,
508+
"postData": base64.b64encode(options.post_data_buffer).decode()
509+
if options.post_data_buffer is not None
510+
else None,
511+
"isFallback": is_fallback,
512+
},
513+
)
514+
)
532515

533516
async def _redirected_navigation_request(self, url: str) -> None:
534517
await self._handle_route(
@@ -586,7 +569,7 @@ def close(self, code: int = None, reason: str = None) -> None:
586569
},
587570
)
588571
)
589-
except:
572+
except Exception:
590573
pass
591574

592575
def send(self, message: Union[str, bytes]) -> None:
@@ -636,7 +619,7 @@ def _channel_message_from_page(self, event: Dict) -> None:
636619
elif self._connected:
637620
try:
638621
asyncio.create_task(self._channel.send("sendToServer", event))
639-
except:
622+
except Exception:
640623
pass
641624

642625
def _channel_message_from_server(self, event: Dict) -> None:
@@ -649,7 +632,7 @@ def _channel_message_from_server(self, event: Dict) -> None:
649632
else:
650633
try:
651634
asyncio.create_task(self._channel.send("sendToPage", event))
652-
except:
635+
except Exception:
653636
pass
654637

655638
def _channel_close_page(self, event: Dict) -> None:
@@ -658,7 +641,7 @@ def _channel_close_page(self, event: Dict) -> None:
658641
else:
659642
try:
660643
asyncio.create_task(self._channel.send("closeServer", event))
661-
except:
644+
except Exception:
662645
pass
663646

664647
def _channel_close_server(self, event: Dict) -> None:
@@ -667,7 +650,7 @@ def _channel_close_server(self, event: Dict) -> None:
667650
else:
668651
try:
669652
asyncio.create_task(self._channel.send("closePage", event))
670-
except:
653+
except Exception:
671654
pass
672655

673656
@property
@@ -679,7 +662,7 @@ async def close(self, code: int = None, reason: str = None) -> None:
679662
await self._channel.send(
680663
"closePage", {"code": code, "reason": reason, "wasClean": True}
681664
)
682-
except:
665+
except Exception:
683666
pass
684667

685668
def connect_to_server(self) -> "WebSocketRoute":
@@ -697,7 +680,7 @@ def send(self, message: Union[str, bytes]) -> None:
697680
"sendToPage", {"message": message, "isBase64": False}
698681
)
699682
)
700-
except:
683+
except Exception:
701684
pass
702685
else:
703686
try:
@@ -710,7 +693,7 @@ def send(self, message: Union[str, bytes]) -> None:
710693
},
711694
)
712695
)
713-
except:
696+
except Exception:
714697
pass
715698

716699
def on_message(self, handler: Callable[[Union[str, bytes]], Any]) -> None:
@@ -758,9 +741,9 @@ def matches(self, ws_url: str) -> bool:
758741
return self.matcher.matches(ws_url)
759742

760743
async def handle(self, websocket_route: "WebSocketRoute") -> None:
761-
maybe_future = self.handler(websocket_route)
762-
if maybe_future:
763-
breakpoint()
744+
coro_or_future = self.handler(websocket_route)
745+
if asyncio.iscoroutine(coro_or_future):
746+
await coro_or_future
764747
await websocket_route._after_handle()
765748

766749

playwright/_impl/_page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ async def _on_web_socket_route(self, web_socket_route: WebSocketRoute) -> None:
325325
if route_handler:
326326
await route_handler.handle(web_socket_route)
327327
else:
328-
web_socket_route.connect_to_server()
328+
await self._browser_context._on_web_socket_route(web_socket_route)
329329

330330
def _on_binding(self, binding_call: "BindingCall") -> None:
331331
func = self._bindings.get(binding_call._initializer["name"])

playwright/_impl/_tracing.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,10 @@ async def start(
4141
params = locals_to_params(locals())
4242
self._include_sources = bool(sources)
4343

44-
async def _inner_start() -> str:
45-
await self._channel.send("tracingStart", params)
46-
return await self._channel.send(
47-
"tracingStartChunk", {"title": title, "name": name}
48-
)
49-
50-
trace_name = await self._connection.wrap_api_call(_inner_start, True)
44+
await self._channel.send("tracingStart", params)
45+
trace_name = await self._channel.send(
46+
"tracingStartChunk", {"title": title, "name": name}
47+
)
5148
await self._start_collecting_stacks(trace_name)
5249

5350
async def start_chunk(self, title: str = None, name: str = None) -> None:
@@ -64,14 +61,11 @@ async def _start_collecting_stacks(self, trace_name: str) -> None:
6461
)
6562

6663
async def stop_chunk(self, path: Union[pathlib.Path, str] = None) -> None:
67-
await self._connection.wrap_api_call(lambda: self._do_stop_chunk(path), True)
64+
await self._do_stop_chunk(path)
6865

6966
async def stop(self, path: Union[pathlib.Path, str] = None) -> None:
70-
async def _inner() -> None:
71-
await self._do_stop_chunk(path)
72-
await self._channel.send("tracingStop")
73-
74-
await self._connection.wrap_api_call(_inner, True)
67+
await self._do_stop_chunk(path)
68+
await self._channel.send("tracingStop")
7569

7670
async def _do_stop_chunk(self, file_path: Union[pathlib.Path, str] = None) -> None:
7771
self._reset_stack_counter()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
InWheel = None
3131
from wheel.bdist_wheel import bdist_wheel as BDistWheelCommand
3232

33-
driver_version = "1.48.0-alpha-1727434891000"
33+
driver_version = "1.48.0-beta-1728034490000"
3434

3535

3636
def extractall(zip: zipfile.ZipFile, path: str) -> None:

tests/async/test_page_request_gc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ async def test_should_work(page: Page, server: Server) -> None:
2525
)
2626
await page.request_gc()
2727
assert await page.evaluate("() => globalThis.weakRef.deref()") == {"hello": "world"}
28+
2829
await page.request_gc()
2930
assert await page.evaluate("() => globalThis.weakRef.deref()") == {"hello": "world"}
31+
3032
await page.evaluate("() => globalThis.objectToDestroy = null")
3133
await page.request_gc()
3234
assert await page.evaluate("() => globalThis.weakRef.deref()") is None

0 commit comments

Comments
 (0)