|
8 | 8 | from functools import partial |
9 | 9 | from random import randint |
10 | 10 | from tempfile import TemporaryDirectory |
11 | | -from typing import Any, Callable, Optional |
| 11 | +from typing import Any, Awaitable, Callable, Optional, overload |
12 | 12 |
|
13 | 13 | from pydoll.browser.interfaces import BrowserOptionsManager |
14 | 14 | from pydoll.browser.managers import ( |
@@ -118,9 +118,9 @@ async def start(self, headless: bool = False) -> Tab: |
118 | 118 | if headless: |
119 | 119 | warnings.warn( |
120 | 120 | "The 'headless' parameter is deprecated and will be removed in a future version. " |
121 | | - "Use `options.headless = True` instead.", |
| 121 | + 'Use `options.headless = True` instead.', |
122 | 122 | DeprecationWarning, |
123 | | - stacklevel=2 |
| 123 | + stacklevel=2, |
124 | 124 | ) |
125 | 125 | self.options.headless = headless |
126 | 126 |
|
@@ -378,9 +378,15 @@ async def reset_permissions(self, browser_context_id: Optional[str] = None): |
378 | 378 | """Reset all permissions to defaults and restore prompting behavior.""" |
379 | 379 | return await self._execute_command(BrowserCommands.reset_permissions(browser_context_id)) |
380 | 380 |
|
| 381 | + @overload |
381 | 382 | async def on( |
382 | 383 | self, event_name: str, callback: Callable[[Any], Any], temporary: bool = False |
383 | | - ) -> int: |
| 384 | + ) -> int: ... |
| 385 | + @overload |
| 386 | + async def on( |
| 387 | + self, event_name: str, callback: Callable[[Any], Awaitable[Any]], temporary: bool = False |
| 388 | + ) -> int: ... |
| 389 | + async def on(self, event_name, callback, temporary: bool = False) -> int: |
384 | 390 | """ |
385 | 391 | Register CDP event listener at browser level. |
386 | 392 |
|
@@ -409,6 +415,10 @@ async def callback_wrapper(event): |
409 | 415 | event_name, function_to_register, temporary |
410 | 416 | ) |
411 | 417 |
|
| 418 | + async def remove_callback(self, callback_id: int): |
| 419 | + """Remove callback from browser.""" |
| 420 | + return await self._connection_handler.remove_callback(callback_id) |
| 421 | + |
412 | 422 | async def enable_fetch_events( |
413 | 423 | self, |
414 | 424 | handle_auth_requests: bool = False, |
|
0 commit comments