javascriptgoogle-chromeapplescriptdocument-readyuntil-loop

Applescript : wait that the page is load on chrome


tell application "Safari"
        repeat until (do JavaScript "document.readyState" in tab 2 of window 1) is "complete"
        end repeat
    end tell
end if

how can I have this working with Chrome ?


Solution

  • You should be able to do

    tell application "Google Chrome"
    repeat until (execute tab 1 of window 1 javascript "document.readyState" is "complete")
    end repeat
        execute tab 1 of window 1 javascript "document.readyState"
    end tell
    

    but you may have pages that return "interactive" forever, or for a very long time.

    Doing it with just AppleScript is supposed to be:

    tell application "Google Chrome"
        repeat until (loading of tab 1 of window 1 is false)
            1 + 1 --just an arbitary line
        end repeat
        loading of tab 1 of window 1 --this just returns final status
    end tell
    

    but, to tell you the truth, I find it suspicious. I have a page that's pretty bare html in the body (http://www.crgreen.com/boethos/boethos.html), and it works with that, but for most pages (I've tried yahoo, macupdate, bbc news, jedit.org, etc.) I'm not getting a "loading = true", ever. It may be buggy.