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

如何用JavaScript筛选Chrome中匹配指定URL列表的标签页?

筛选Chrome中匹配指定URL列表的标签页

我正尝试编写JavaScript代码,筛选出Chrome浏览器中匹配指定URL列表的标签页。例如,当打开10个标签页时,应返回符合输入URL列表的标签页。我尝试了以下代码组合,但无法正常运行:

let urlLists = ['youtube.com', 'cnn.com']
chrome.tabs.query({ "url": urlLists.includes(p => `*://${p}/*`) }, (tabs) => {
    tabs.forEach((tab) => {
          console.log('tab.id: ',tab.id, 'tab.url:', tab.url);
}

我确认不存在权限问题,因为以下代码可以输出所有标签页:

chrome.tabs.query({}, (tabs) => {
        tabs.forEach((tab) => {
          console.log('tab.id: ',tab.id, 'tab.url:', tab.url);
        })
    })

编辑

根据@wOxxOm的回复,以下是可行的代码:

let blockUrlList = ["youtube.com", "dict.cc"]
chrome.tabs.query({ "url": blockUrlList.map(p => `*://*.${p}/*`)}, (tabs) => {
    tabs.forEach((tab) => {
        console.log('tab.id: ',tab.id, 'tab.url:', tab.url)
    })
})

感谢@wOxxOm的帮助。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 21:02:12