Make sure the front page has loaded a valid URL first.
If you get back an URL then something else is amiss.
-Chris
--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/02/12 11:42
# dMod: 2021/02/12 11:42
# Appl: Safari
# Task: Test JavaScript Running in Safari.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Safari, @Test, @JavaScript
--------------------------------------------------------
set jsCmdStr to "
document.URL
"
doJavaScriptInSafari(jsCmdStr)
--------------------------------------------------------
--» HANDLERS
--------------------------------------------------------
on doJavaScriptInSafari(jsCmdStr)
try
tell application "Safari" to do JavaScript jsCmdStr in front document
on error e
error "Error in handler doJavaScriptInSafari() of library NLb!" & return & return & e
end try
end doJavaScriptInSafari
--------------------------------------------------------