Dialog box detection

Looking for any suggestions as to how I can detect whether a dialog box prompting the user for username and password in a web browser is present or not.

I’m trying to write a script that will input username and password if prompted by the dialog box otherwise just ignore.

Any tips or suggestions are appreciated! Thanks in advance!

in Safari check sheet 1 of window 1 of process “Safari” of application “System Events” with GUi scripting

Thanks Stefan! Is it possible to do without GUI scripting?

Either with JavaScript, which I have no idea about, or no