error "The variable var is not defined." number -2753 from "var" in a method
figured it out, a misplaced ) and concatenating the javascript to make it a variable, silly question.

on waitForId(idText)
set wait to false
set idText to "\"" &amp; idText &amp; "\""
repeat until wait is true
    tell application "Safari"
        set wait to (do JavaScript "document.contains(document.getElementById(" &amp; idText &amp; "));" in current tab of first window)
    end tell
    delay 0.2
end repeat
return true
end waitForId


tell application "Safari"
set var to false
if not (exists document 1) then reopen
tell current tab of window 1 to set URL to "https://www.google.com/?client=safari#channel=mac_bm"
tell current tab to activate
log "starting wait"
my waitForId("hplogo")

log "done waiting"
end tell