Получение значений из внутренних функций текущей веб-страницы в Chrome через (JXA/AppleScript)

Я не могу получить значения из внутренних функций текущей веб-страницы в Chrome. Почему это произошло?

для примеров в JXA:

function getTime() {
    const chrome = Application('Google Chrome')
    const currentTab = chrome.windows[0].activeTab()
    return currentTab.execute({javascript: 'jwplayer().getPosition()'})
}
getTime()

Chrome возвращает справочную ошибку:

 Uncaught ReferenceError: jwplayer is not defined

в AppleScript то же самое:

tell application "Google Chrome"
    return execute front window's active tab javascript "jwplayer().getPosition()"
end tell

Настройки в Chrome проверены: «Разрешить Javascript из событий Apple».


person bikeNik    schedule 02.05.2019    source источник


Ответы (1)


Нашел обходной путь с AppleScript:

tell front window of application "Google Chrome"
    set URL of active tab to "javascript:
    sessionStorage.setItem('scrapy', JSON.stringify({
      currentTime: jwplayer().getPosition()
    }, 2, '  ')
  "
    return {execute active tab javascript "sessionStorage.getItem('scrapy')"}
end tell
person bikeNik    schedule 04.05.2019