I'm using this script for Google Chrome to pause the script until the page is fully loaded:
tell application "Google Chrome"
repeat until (loading of front window's tab 2 is false)
1 + 1 --just an arbitary line
end repeat
loading of front window's tab 2
end tell
This don't seems to work with Safari, any equivalent?
Best Answer
1. AppleScript
source
propertyYou could try using Safari's
source
property, which is""
until the HTML code gets loaded into it (which can only be done once the page is loaded). Note, however, that this doesn't necessarily imply that the page has been rendered:The
source
property is reset to""
even between page loads/reloads.2. Reload button UI element
If you want to know that a page is loaded and rendered on screen, then a reliable method is to determine whether the button in the URL bar is a "reload" button (page loaded and rendered), or a "cancel" button (page still loading/rendering):
3. JavaScript
readyState
propertyIf you have Allow JavaScript from Apple Events ticked in the Develop menu, then you can access the
readyState
property of thedocument
:The
document.readyState
JavaScript property returns one of five values:uninitialized
: Has not started loading yetloading
: Is loadingloaded
: Has been loadedinteractive
: Has loaded enough and the user can interact with itcomplete
: Fully loaded