我刚刚开始构建chrome扩展,并且因为我需要仅为特定网址显示其图标,所以我使用了page_action。 我也是使用的事件监听如果该URL的变化和这种方式来显示图标符合我的模式:如何在chrome.declarativeContent.PageStateMatcher中使用UrlFilter过滤网址(#)(哈希标签)
chrome.declarativeContent.onPageChanged.addRules([
{
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { urlContains: 'https://mysite.com/mypage.html' }
})
],
actions: [ new chrome.declarativeContent.ShowPageAction() ]
}
]);
它工作正常,但是当我要添加查询的第一个字符的过滤器,它失败。 URL模式我想过滤的样子: https://mysite.com/mypage.html#e123456789
我尝试以下,但它并没有帮助:
pageUrl: { urlContains: 'https://mysite.com/mypage.html#e' }
pageUrl: { urlContains: 'https://mysite.com/mypage.html', queryPrefix: '#e' }
pageUrl: { urlContains: 'https://mysite.com/mypage.html', queryPrefix: 'e' }
我认为,这个问题来自于哈希标签。
任何想法的解决方法?
尝试'pathContains'代替。如果它有效,我会将其作为答案。 – Xan 2014-09-19 08:16:04
嗨Xan,感谢您的快速回答,但由于某些原因,它既不工作也不工作。它看起来不能检查哈希标记后面的内容。 – Surreal 2014-09-19 08:27:40
这有点奇怪。我会在https://crbug.com上提交功能请求,看看他们有什么要说的。 – Xan 2014-09-19 08:29:42