From e2d0635f6b4b3e6f5285e5ac72be96cbe5fb9023 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 24 Oct 2024 13:01:19 +0200 Subject: [PATCH 1/2] fix: hide page.route calls from traces --- playwright/_impl/_connection.py | 23 +++++++++++++++-------- playwright/_impl/_local_utils.py | 2 +- playwright/_impl/_network.py | 4 ++-- playwright/_impl/_tracing.py | 2 +- tests/async/test_tracing.py | 1 - 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/playwright/_impl/_connection.py b/playwright/_impl/_connection.py index 95c87deb8..910693f9e 100644 --- a/playwright/_impl/_connection.py +++ b/playwright/_impl/_connection.py @@ -54,15 +54,18 @@ def __init__(self, connection: "Connection", object: "ChannelOwner") -> None: self._guid = object._guid self._object = object self.on("error", lambda exc: self._connection._on_event_listener_error(exc)) + self._is_internal_type = False async def send(self, method: str, params: Dict = None) -> Any: return await self._connection.wrap_api_call( - lambda: self.inner_send(method, params, False) + lambda: self._inner_send(method, params, False), + self._is_internal_type, ) async def send_return_as_dict(self, method: str, params: Dict = None) -> Any: return await self._connection.wrap_api_call( - lambda: self.inner_send(method, params, True) + lambda: self._inner_send(method, params, True), + self._is_internal_type, ) def send_no_reply(self, method: str, params: Dict = None) -> None: @@ -73,7 +76,7 @@ def send_no_reply(self, method: str, params: Dict = None) -> None: ) ) - async def inner_send( + async def _inner_send( self, method: str, params: Optional[Dict], return_as_dict: bool ) -> Any: if params is None: @@ -108,6 +111,9 @@ async def inner_send( key = next(iter(result)) return result[key] + def mark_as_internal_type(self) -> None: + self._is_internal_type = True + class ChannelOwner(AsyncIOEventEmitter): def __init__( @@ -132,7 +138,6 @@ def __init__( self._channel: Channel = Channel(self._connection, self) self._initializer = initializer self._was_collected = False - self._is_internal_type = False self._connection._objects[guid] = self if self._parent: @@ -157,9 +162,6 @@ def _adopt(self, child: "ChannelOwner") -> None: self._objects[child._guid] = child child._parent = self - def mark_as_internal_type(self) -> None: - self._is_internal_type = True - def _set_event_to_subscription_mapping(self, mapping: Dict[str, str]) -> None: self._event_to_subscription_mapping = mapping @@ -359,7 +361,12 @@ def _send_message_to_server( "params": self._replace_channels_with_guids(params), "metadata": metadata, } - if self._tracing_count > 0 and frames and not object._is_internal_type: + if ( + self._tracing_count > 0 + and frames + and frames + and object._guid != "localUtils" + ): self.local_utils.add_stack_to_tracing_no_reply(id, frames) self._transport.send(message) diff --git a/playwright/_impl/_local_utils.py b/playwright/_impl/_local_utils.py index 26a3417c4..5ea8b644d 100644 --- a/playwright/_impl/_local_utils.py +++ b/playwright/_impl/_local_utils.py @@ -25,7 +25,7 @@ def __init__( self, parent: ChannelOwner, type: str, guid: str, initializer: Dict ) -> None: super().__init__(parent, type, guid, initializer) - self.mark_as_internal_type() + self._channel.mark_as_internal_type() self.devices = { device["name"]: parse_device_descriptor(device["descriptor"]) for device in initializer["deviceDescriptors"] diff --git a/playwright/_impl/_network.py b/playwright/_impl/_network.py index 376b2b8cb..649b89198 100644 --- a/playwright/_impl/_network.py +++ b/playwright/_impl/_network.py @@ -317,7 +317,7 @@ def __init__( self, parent: ChannelOwner, type: str, guid: str, initializer: Dict ) -> None: super().__init__(parent, type, guid, initializer) - self.mark_as_internal_type() + self._channel.mark_as_internal_type() self._handling_future: Optional[asyncio.Future["bool"]] = None self._context: "BrowserContext" = cast("BrowserContext", None) self._did_throw = False @@ -603,7 +603,7 @@ def __init__( self, parent: ChannelOwner, type: str, guid: str, initializer: Dict ) -> None: super().__init__(parent, type, guid, initializer) - self.mark_as_internal_type() + self._channel.mark_as_internal_type() self._on_page_message: Optional[Callable[[Union[str, bytes]], Any]] = None self._on_page_close: Optional[Callable[[Optional[int], Optional[str]], Any]] = ( None diff --git a/playwright/_impl/_tracing.py b/playwright/_impl/_tracing.py index 5c59b749f..d645e41da 100644 --- a/playwright/_impl/_tracing.py +++ b/playwright/_impl/_tracing.py @@ -25,7 +25,7 @@ def __init__( self, parent: ChannelOwner, type: str, guid: str, initializer: Dict ) -> None: super().__init__(parent, type, guid, initializer) - self.mark_as_internal_type() + self._channel.mark_as_internal_type() self._include_sources: bool = False self._stacks_id: Optional[str] = None self._is_tracing: bool = False diff --git a/tests/async/test_tracing.py b/tests/async/test_tracing.py index a9cfdfbcb..027457586 100644 --- a/tests/async/test_tracing.py +++ b/tests/async/test_tracing.py @@ -119,7 +119,6 @@ async def test_should_collect_trace_with_resources_but_no_js( "Page.wait_for_timeout", "Page.route", "Page.goto", - "Route.continue_", "Page.goto", "Page.close", ] From 3c47a6ba9f81d2d3524c3b32bb1741a72750a733 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 24 Oct 2024 13:22:42 +0200 Subject: [PATCH 2/2] fix sync tests --- tests/sync/test_tracing.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/sync/test_tracing.py b/tests/sync/test_tracing.py index eaef24e00..cdf669f4f 100644 --- a/tests/sync/test_tracing.py +++ b/tests/sync/test_tracing.py @@ -112,7 +112,6 @@ def test_should_collect_trace_with_resources_but_no_js( "Page.wait_for_timeout", "Page.route", "Page.goto", - "Route.continue_", "Page.goto", "Page.close", ]