I'm currently developing a tool that aims to streamline the automation of browser-based products. One specific scenario I need to address is how to manage popups that appear either within an application or in Safari. Ideally, I'd like to create an API that allows users to programmatically click "OK" when a popup appears. Is this achievable using JavaScript, or are there Apple-specific APIs that would be more suitable? Additionally, I'm looking for guidance on how to accurately detect when a popup has been displayed. Any insights or tips would be greatly appreciated. Thank you!