| 675 | self.emit(BrowserContext.Events.Console, message) |
| 676 | |
| 677 | def _on_dialog(self, dialog: Dialog) -> None: |
| 678 | has_listeners = self.emit(BrowserContext.Events.Dialog, dialog) |
| 679 | page = dialog.page |
| 680 | if page: |
| 681 | has_listeners = page.emit(Page.Events.Dialog, dialog) or has_listeners |
| 682 | if not has_listeners: |
| 683 | # Although we do similar handling on the server side, we still need this logic |
| 684 | # on the client side due to a possible race condition between two async calls: |
| 685 | # a) removing "dialog" listener subscription (client->server) |
| 686 | # b) actual "dialog" event (server->client) |
| 687 | if dialog.type == "beforeunload": |
| 688 | asyncio.create_task(dialog.accept()) |
| 689 | else: |
| 690 | asyncio.create_task(dialog.dismiss()) |
| 691 | |
| 692 | def _on_page_error( |
| 693 | self, error: Error, page: Optional[Page], location: WebErrorLocation |