Catching a Safari Time Out

Hi all,

My script runs through websites and when it loads one with a pop up, I want it to time out and return a message I can pass back to the calling routine. I can’t seem to get it to work. Here is a sample script where it should display a message instead of returning to calling routine.

If you load the homedepot.com site it will pop up a location window. If this sits long enough it times out and crashes the script. I just want to catch the timeout and basically skip over it by returning something else.

The above script returns the error “missing value” since it can’t find URL and never gets a chance to fully load due to the popup. Shouldn’t the error trap catch that or am I missing something? In reality, I check the URL in a loop for a few seconds for slow loads, but once that’s done, I need to catch the pop up before it crashes the script.

This is the result in the console:

Any advice would be appreciated.

RP

Now that I’ve done some further testing, the URL is returned even though the pop up message box is shown. It’s one of those boxes requesting an answer like USA or Canada site?
The script seems to hang there and not move on to the next one. Maybe the answer is to test if it’s hanging and then move on.

Any ideas?

RP

Takes some time creating new tab in the Safari.app. Adding little delay should help:


set oldURL to "https://www.homedepot.com"

tell application "Safari"
	activate
	if not (exists window 1) then make new document
	try
		with timeout of 20 seconds
			tell window 1 to set current tab to (make new tab at end of tabs with properties {URL:oldURL})
			delay 0.5 -- THIS
			set newURL to URL of (get window 1's document)
		end timeout
	on error errMsg
		set newURL to "Timed Out, Don't Use"
		display dialog "ERROR: " & errMsg & newURL
	end try
end tell

Thank you for your reply. Yes, it needs some time. In the actual code I send it in a loop with a delay checking for URL is not “”.

It seems to hang though when one of these popup’s come up requiring a response.