| 851 | ) |
| 852 | |
| 853 | async def close(self, runBeforeUnload: bool = None, reason: str = None) -> None: |
| 854 | self._close_reason = reason |
| 855 | if not runBeforeUnload: |
| 856 | self._close_was_called = True |
| 857 | try: |
| 858 | if self._owned_context: |
| 859 | await self._owned_context.close() |
| 860 | elif runBeforeUnload: |
| 861 | await self._channel.send("runBeforeUnload", None) |
| 862 | else: |
| 863 | await self._channel.send("close", None, {"reason": reason}) |
| 864 | except Exception as e: |
| 865 | if is_target_closed_error(e) and not runBeforeUnload: |
| 866 | return |
| 867 | raise e |
| 868 | |
| 869 | def is_closed(self) -> bool: |
| 870 | return self._is_closed |