document.readyState "Access not allowed" with Applescript +Javascript 等待页面加载

document.readyState "Access not allowed" with Applescript +Javascript that waits for page to load

我正在尝试编写一个 applescript 在我的浏览器中打开一个 html 页面,等待它加载,然后 运行s window.find 检查特定的关键字. 非常重要的是 .find 可以在页面加载后立即 运行 但之前不尝试。 如果关键字存在,脚本将单击 "next" 按钮。 这是我尝试创建的一个循环,用于检查 html 是否已加载

to checkInteractive()       

    repeat 60 times

        try     
            tell application "Safari"
                set a to do JavaScript 
                "document.readyState" in document 1
            end tell
        end try

        if a = "interactive" then
            exit repeat
        end if

        delay 0.01

    end repeat

end checkInteractive

但我收到此错误:

语法错误无法在文档 1 中获取 "document.readyState"。不允许访问。

有谁知道我应该做些什么? 或者是否有另一种方法来检查 html 是否已加载?

或者将语句放在一行中

tell application "Safari"
     set a to do JavaScript "document.readyState" in document 1
end tell

或使用 AppleScript 行分隔符

tell application "Safari"
    set a to do JavaScript ¬
        "document.readyState" in document 1
end tell