You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

修复获取Brave浏览器中YouTube视频信息的AppleScript语法错误

修复Brave浏览器YouTube视频标题获取的AppleScript语法错误

你的代码出现Expected “,” but found identifier.错误,核心原因是Brave的AppleScript接口不支持do JavaScript ... in t的调用格式,需要通过tell块针对目标标签页执行JavaScript命令。

修复后的完整代码

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
                tell t
                    set videoTitle to do JavaScript "document.title"
                end tell
                exit repeat
            end if
        end repeat
        if videoTitle is not "" then exit repeat
    end repeat
end tell
return videoTitle

额外说明

  • 权限配置:必须先在Brave中启用AppleScript控制:打开「设置」→ 搜索「AppleScript」→ 勾选「允许AppleScript控制浏览器」。
  • 纯视频标题优化:如果不需要标题里的“YouTube”后缀,可以把JavaScript代码替换为:
    document.querySelector('h1.title yt-formatted-string').textContent
    

内容的提问来源于stack exchange,提问作者Gokul Kannan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 11:27:34