MCPcopy Index your code
hub / github.com/microsoft/playwright-python / _on_route

Method _on_route

playwright/_impl/_browser_context.py:245–275  ·  view source on GitHub ↗
(self, route: Route)

Source from the content-addressed store, hash-verified

243 page._opener.emit(Page.Events.Popup, page)
244
245 async def _on_route(self, route: Route) -> None:
246 route._context = self
247 page = route.request._safe_page()
248 route_handlers = self._routes.copy()
249 for route_handler in route_handlers:
250 # If the page or the context was closed we stall all requests right away.
251 if (page and page._close_was_called) or self._closing_or_closed:
252 return
253 if not route_handler.matches(route.request.url):
254 continue
255 if route_handler not in self._routes:
256 continue
257 if route_handler.will_expire:
258 self._routes.remove(route_handler)
259 try:
260 handled = await route_handler.handle(route)
261 finally:
262 if len(self._routes) == 0:
263 asyncio.create_task(
264 self._connection.wrap_api_call(
265 lambda: self._update_interception_patterns(), True
266 )
267 )
268 if handled:
269 return
270 try:
271 # If the page is closed or unrouteAll() was called without waiting and interception disabled,
272 # the method will throw an error - silence it.
273 await route._inner_continue(True)
274 except Exception:
275 pass
276
277 async def _on_web_socket_route(self, web_socket_route: WebSocketRoute) -> None:
278 route_handler = next(

Callers 1

__init__Method · 0.95

Calls 7

_safe_pageMethod · 0.80
copyMethod · 0.80
wrap_api_callMethod · 0.80
_inner_continueMethod · 0.80
matchesMethod · 0.45
handleMethod · 0.45

Tested by

no test coverage detected