Looking for a way to properly reload a Safari tab and check if a page has finished loading using AppleScript + Javascript.
Seems like the build in action "for waiting for safari to finish loading" doesn't work.
This script should work but it doesn't, it shows the page has completed loading while it keeps loading.
tell application "Safari"
set sameURL to URL of tab 2 of front window
set URL of tab 2 of front window to sameURL
end tell
set t to ""
tell application "Safari" to tell tab 2 of window 1
repeat until t is "complete"
set t to do JavaScript "document.readyState"
end repeat
end tell
The only solution that I could manage and which actually works is to refresh the page and run JS periodically to check if the page contains some text or an element - That means the page has finished loading.
after 12 month and 10 different ways - the easiest (of course) came to my mind and it works perfectly
just put in a "PAUSE UNTIL" and then select "MENU CONDITON" the menu item "Stopp" (*) is NOT ENABLED
for a clean run I always add an addiontional PAUSE of 0.2 to 0.5 after it
Sorry that was someone elses macro
stop is what is appropriate for you
see other options under pause until
and you can also try
wait until safari is finished loading..
Sadly, this no longer works. With an update to Safari about a year ago the Stop menu now is always enabled. For the Wait For Front Browser to Finish Loading action, Keyboard Maestro checks the Stop menu (but no longer in Safari since it is no longer useful), and then document.readyState is “complete”. It continuously checks this until it remains “complete” for the specified time in the action.
I have found the most reliable way is to pause until a specific HTML element is found on the page.
This works for Safari, Google Chrome, and all of the Chrome-based browsers.
See: