【问题标题】:Applescript : wait that the page is load on chromeApplescript:等待页面在 chrome 上加载
【发布时间】:2017-02-17 07:44:03
【问题描述】:
tell application "Safari"
        repeat until (do JavaScript "document.readyState" in tab 2 of window 1) is "complete"
        end repeat
    end tell
end if

我怎样才能让它与 Chrome 一起使用?

【问题讨论】:

    标签: javascript google-chrome applescript document-ready


    【解决方案1】:

    你应该可以的

    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
    

    但您的页面可能会永远返回“交互式”,或者在很长一段时间内返回。

    只使用 AppleScript 应该是:

    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
    

    但是,说实话,我觉得这很可疑。我在正文中有一个非常裸露的 html 页面(http://www.crgreen.com/boethos/boethos.html),它适用于该页面,但对于大多数页面(我尝试过 yahoo、macupdate、bbc news、jedit.org 等)我不是得到一个“加载=真”,永远。可能有问题。

    【讨论】:

    • 谢谢!我会在几分钟内尝试所有这些,太好了。
    【解决方案2】:

    对于 Chromium 浏览器(Google Chrome、Brave Browser、Microsoft Edge、Opera、Vivaldi 等),您不需要 JavaScript 变通方法,因为它们可以适当地支持检查选项卡是否仍在加载。

    在 AppleScript 中:

    tell application "Google Chrome" to return loading of tab 2 of window 1
    

    在自动化 JavaScript (JXA) 中:

    Application('Google Chrome').windows[1].tabs[2].loading()
    

    【讨论】:

      猜你喜欢
      • 2021-10-14
      • 1970-01-01
      • 2017-12-11
      • 2017-09-13
      • 2016-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多