【问题标题】:Chrome URL match patterns (specific depth, varying subdomain and top level domain)Chrome URL 匹配模式(特定深度、不同的子域和顶级域)
【发布时间】:2021-01-31 15:21:05
【问题描述】:

我想在特定深度(文件夹内)匹配 url
<>://somewhere.else/folder/<>

我试过了
*://somewhere.else/*/*
但它也可以匹配
<>://somewhere.else/folder/


我还想将 url 与不同的子域和顶级域匹配
<>://<>.somewhere.<>/<>
我试过
*://*.somewhere.*/* 但它只是没有用。

【问题讨论】:

    标签: javascript google-chrome-extension


    【解决方案1】:

    在特定深度匹配 url

    匹配模式无法做到这一点,因此您必须使用更广泛的模式并在您的内容脚本中检查location.href(如果这是一个 webRequest 事件侦听器,则在后台脚本中)。

    将 url 与不同的子域和顶级域匹配

    如果这是用于 manifest.json 中的 content_scripts,您可以使用 include_globsexample

    附:有一些 chrome API 接受 RE2 正则表达式以匹配模式(例如 webNavigationdeclarativeNetRequest),您可以在后台脚本中使用它们。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-18
      • 2013-04-18
      • 1970-01-01
      • 2020-11-04
      • 1970-01-01
      • 1970-01-01
      • 2017-12-30
      • 1970-01-01
      相关资源
      最近更新 更多