I use playwright in python to cancel a text-submission on a webpage:
page.once("dialog", lambda dialog: asyncio.create_task(dialog.accept())) with p