_debugger.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright (c) Microsoft Corporation.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from types import SimpleNamespace
  15. from typing import Any, Dict, Optional
  16. from playwright._impl._api_structures import DebuggerLocation, DebuggerPausedDetails
  17. from playwright._impl._connection import ChannelOwner
  18. class Debugger(ChannelOwner):
  19. Events = SimpleNamespace(
  20. PausedStateChanged="pausedstatechanged",
  21. )
  22. def __init__(
  23. self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
  24. ) -> None:
  25. super().__init__(parent, type, guid, initializer)
  26. self._paused_details: Optional[DebuggerPausedDetails] = None
  27. self._channel.on(
  28. "pausedStateChanged", lambda params: self._on_paused_state_changed(params)
  29. )
  30. def _on_paused_state_changed(self, params: Dict[str, Any]) -> None:
  31. self._paused_details = params.get("pausedDetails")
  32. self.emit(Debugger.Events.PausedStateChanged)
  33. async def request_pause(self) -> None:
  34. await self._channel.send("requestPause", None)
  35. async def resume(self) -> None:
  36. await self._channel.send("resume", None)
  37. async def next(self) -> None:
  38. await self._channel.send("next", None)
  39. async def run_to(self, location: DebuggerLocation) -> None:
  40. await self._channel.send("runTo", None, {"location": location})
  41. @property
  42. def paused_details(self) -> Optional[DebuggerPausedDetails]:
  43. return self._paused_details