Skip to content

Commit f388fb9

Browse files
authored
feat(inspector): plumb api names metainfo (microsoft#520)
1 parent fea6434 commit f388fb9

12 files changed

+1665
-765
lines changed

playwright/_impl/_async_base.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
# limitations under the License.
1414

1515
import asyncio
16-
from typing import Any, Callable, Generic, TypeVar
16+
import traceback
17+
from typing import Any, Awaitable, Callable, Generic, TypeVar
1718

1819
from playwright._impl._impl_to_api_mapping import ImplToApiMapping, ImplWrapper
1920

@@ -54,8 +55,11 @@ def __init__(self, impl_obj: Any) -> None:
5455
def __str__(self) -> str:
5556
return self._impl_obj.__str__()
5657

57-
def _sync(self, future: asyncio.Future) -> Any:
58-
return self._loop.run_until_complete(future)
58+
def _async(self, api_name: str, coro: Awaitable) -> Any:
59+
task = asyncio.current_task()
60+
setattr(task, "__pw_api_name__", api_name)
61+
setattr(task, "__pw_stack_trace__", traceback.extract_stack())
62+
return coro
5963

6064
def _wrap_handler(self, handler: Any) -> Callable[..., None]:
6165
if callable(handler):

playwright/_impl/_browser_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def expect_event(
207207
) -> EventContextManagerImpl:
208208
if timeout is None:
209209
timeout = self._timeout_settings.timeout()
210-
wait_helper = WaitHelper(self, f"expect_event({event})")
210+
wait_helper = WaitHelper(self, f"browser_context.expect_event({event})")
211211
wait_helper.reject_on_timeout(
212212
timeout, f'Timeout while waiting for event "{event}"'
213213
)

playwright/_impl/_connection.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ def __init__(
154154
self._callbacks: Dict[int, ProtocolCallback] = {}
155155
self._object_factory = object_factory
156156
self._is_sync = False
157+
self._api_name = ""
157158

158159
async def run_as_sync(self) -> None:
159160
self._is_sync = True
@@ -194,20 +195,22 @@ def _send_message_to_server(
194195
self._last_id += 1
195196
id = self._last_id
196197
callback = ProtocolCallback(self._loop)
197-
if self._is_sync:
198-
task = asyncio.current_task(self._loop)
199-
callback.stack_trace = (
200-
getattr(task, "__pw_stack_trace__", None) if task else None
201-
)
198+
task = asyncio.current_task(self._loop)
199+
callback.stack_trace = getattr(task, "__pw_stack_trace__", None)
202200
if not callback.stack_trace:
203201
callback.stack_trace = traceback.extract_stack()
204202

203+
metadata = {"stack": serialize_call_stack(callback.stack_trace)}
204+
api_name = getattr(task, "__pw_api_name__", None)
205+
if api_name:
206+
metadata["apiName"] = api_name
207+
205208
message = dict(
206209
id=id,
207210
guid=guid,
208211
method=method,
209212
params=self._replace_channels_with_guids(params, "params"),
210-
metadata={"stack": serialize_call_stack(callback.stack_trace)},
213+
metadata=metadata,
211214
)
212215
self._transport.send(message)
213216
self._callbacks[id] = callback

playwright/_impl/_frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ async def goto(
118118
def _setup_navigation_wait_helper(
119119
self, wait_name: str, timeout: float = None
120120
) -> WaitHelper:
121-
wait_helper = WaitHelper(self, wait_name)
121+
wait_helper = WaitHelper(self, f"frame.{wait_name}")
122122
wait_helper.reject_on_event(
123123
self._page, "close", Error("Navigation failed because page was closed!")
124124
)

playwright/_impl/_network.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def expect_event(
301301
) -> EventContextManagerImpl:
302302
if timeout is None:
303303
timeout = cast(Any, self._parent)._timeout_settings.timeout()
304-
wait_helper = WaitHelper(self, f"expect_event({event})")
304+
wait_helper = WaitHelper(self, f"web_socket.expect_event({event})")
305305
wait_helper.reject_on_timeout(
306306
timeout, f'Timeout while waiting for event "{event}"'
307307
)

playwright/_impl/_page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ def expect_event(
779779
) -> EventContextManagerImpl:
780780
if timeout is None:
781781
timeout = self._timeout_settings.timeout()
782-
wait_helper = WaitHelper(self, f"expect_event({event})")
782+
wait_helper = WaitHelper(self, f"page.expect_event({event})")
783783
wait_helper.reject_on_timeout(
784784
timeout, f'Timeout while waiting for event "{event}"'
785785
)

playwright/_impl/_sync_base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ def __init__(self, impl_obj: Any) -> None:
8787
def __str__(self) -> str:
8888
return self._impl_obj.__str__()
8989

90-
def _sync(self, coro: Awaitable) -> Any:
91-
stack_trace = traceback.extract_stack()
90+
def _sync(self, api_name: str, coro: Awaitable) -> Any:
9291
g_self = greenlet.getcurrent()
9392
task = self._loop.create_task(coro)
94-
setattr(task, "__pw_stack_trace__", stack_trace)
93+
setattr(task, "__pw_api_name__", api_name)
94+
setattr(task, "__pw_stack_trace__", traceback.extract_stack())
9595

9696
def callback(result: Any) -> None:
9797
g_self.switch()

0 commit comments

Comments
 (0)