【问题标题】:Chrome Extension Block a certain pattern of urlChrome 扩展程序阻止特定模式的 url
【发布时间】:2019-07-10 10:00:43
【问题描述】:

我正在构建一个 chrome 扩展程序来阻止来自某个主机地址的图像。但是,由于 google 代理图像,我无法弄清楚要在 chrome webrequest api 中使用的 url 模式。

网址应该是这样的。

https://ci6.googleusercontent.con/proxy/hashds93932932-0-3123_#https://targethost.com/track?=trackparams

【问题讨论】:

  • 由于 API 会忽略 URL 模式中的 #hash 部分,因此您必须使用像 https://*.googleusercontent.con/proxy/hashds* 这样的通用模式,然后在您的 webRequest 侦听器中检查 details.url 字符串以获取 targethost 子字符串。
  • @wOxxOm 所以我需要做的是使用正则表达式来检查 details.url。如果返回 true 那么我返回 {cancel : true} 否则返回 {cancel : false}

标签: javascript google-chrome google-chrome-extension chrome-webrequest


【解决方案1】:

好的,正如@wOxxOm 指出的那样,我需要检查 details.url 的值。 { details 是 webrequest API 在回调中返回的内容}。我需要在链接上应用正则表达式,这对我有用。如果正则表达式失败则返回 {cancel:false} 否则返回 {cancel:true}。 cancel:true 阻止网络请求。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-15
    • 1970-01-01
    • 2018-01-28
    • 2020-04-14
    • 2014-06-04
    • 1970-01-01
    • 1970-01-01
    • 2013-05-11
    相关资源
    最近更新 更多