1

I can't get values from inner functions of current webpage in Chrome. Why it's happened?

for examples in JXA:

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

Chrome returns reference error:

 Uncaught ReferenceError: jwplayer is not defined

in AppleScript the same:

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

Settings in Chrome is checked: "Allow Javascript from Apple Events"

bikeNik
  • 43
  • 1
  • 5

1 Answers1

2

Founded a workaround with 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
bikeNik
  • 43
  • 1
  • 5