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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Playwright is a Python library to automate [Chromium](https://www.chromium.org/H

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

Expand Down
11 changes: 9 additions & 2 deletions playwright/_impl/_browser_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,20 @@ def _on_page(self, page: Page) -> None:
page._opener.emit(Page.Events.Popup, page)

def _on_route(self, route: Route, request: Request) -> None:
handled = False
for handler_entry in self._routes:
if handler_entry.matches(request.url):
result = handler_entry.handle(route, request)
if inspect.iscoroutine(result):
asyncio.create_task(result)
return
asyncio.create_task(route.continue_())
handled = True
break
if not handled:
asyncio.create_task(route.continue_())
else:
self._routes = list(
filter(lambda route: route.expired() is False, self._routes)
)

def _on_binding(self, binding_call: BindingCall) -> None:
func = self._bindings.get(binding_call._initializer["name"])
Expand Down
8 changes: 5 additions & 3 deletions playwright/_impl/_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,15 @@ def __init__(
self._times = times
self._handled_count = 0

def expired(self) -> bool:
return self._times is not None and self._handled_count >= self._times

def matches(self, request_url: str) -> bool:
if self._times and self._handled_count >= self._times:
return False
return self.matcher.matches(request_url)

def handle(self, route: "Route", request: "Request") -> Union[Coroutine, Any]:
self._handled_count += 1
if self._times:
self._handled_count += 1
return cast(
Callable[["Route", "Request"], Union[Coroutine, Any]], self.handler
)(route, request)
Expand Down
11 changes: 9 additions & 2 deletions playwright/_impl/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,20 @@ def _on_frame_detached(self, frame: Frame) -> None:
self.emit(Page.Events.FrameDetached, frame)

def _on_route(self, route: Route, request: Request) -> None:
handled = False
for handler_entry in self._routes:
if handler_entry.matches(request.url):
result = handler_entry.handle(route, request)
if inspect.iscoroutine(result):
asyncio.create_task(result)
return
self._browser_context._on_route(route, request)
handled = True
break
if not handled:
self._browser_context._on_route(route, request)
else:
self._routes = list(
filter(lambda route: route.expired() is False, self._routes)
)

def _on_binding(self, binding_call: "BindingCall") -> None:
func = self._bindings.get(binding_call._initializer["name"])
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-1632960932000"
driver_version = "1.16.0-next-1633339886000"


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