Below applescript is to fetch currently running youtube video detial info. But im getting error.
Syntax Error : Expected “,” but found identifier.
tell application "Brave Browser"
if (count of windows) = 0 then
return "No windows open in Brave Browser"
end if
set videoTitle to ""
repeat with w in (every window)
repeat with t in (every tab of w)
if URL of t contains "youtube.com/watch" then
set videoTitle to (do JavaScript "document.title" in t)
exit repeat
end if
end repeat
if videoTitle is not "" then exit repeat
end repeat
end tell
return videoTitle
Help me to fix or give a solution
Most applications that allow for scripting via AppleScript will provide their “dictionary” for viewing. You can view dictionaries in Script Editor from the “File” menu by choosing “Open Dictionary…”.
In the case of Brave, the terminology for executing javascript is given in the dictionary as “execute specifier javascript text”. In your script, that would be:
set videoTitle to execute t javascript "document.title"
If you plan on getting more details than just the title, you may find it useful to enclose the lines in a tell
block that specifies which tab you’re scripting:
tell t
set videoTitle to execute javascript "document.title"
set videoURL to execute javascript "document.URL"
--etc.
end tell
As mockman mentioned, depending on the data you wish to get from the tab, you might not have to use javascript. Title is available simply as title
, for example:
tell t
set videoTitle to title
end tell
That may or may not be useful; according to the dictionary, Brave tabs have only the properties of id
, title
, URL
, and (whether or not the tab is still) loading
.