如何在ManifestV3中重定向精确的URL而不匹配嵌套页面?

问题描述 投票:0回答:1

当我在应重定向到

urlFilter
页面的规则中将网站的确切 URL 指定为
/questions
时,它会不断错误地重定向该网站的每个页面(例如个人资料、特定问题等)。

[
  {
    "id": 1,
    "priority": 1,
    "action": {
      "type": "redirect",
      "redirect": {
        "url": "https://stackoverflow.com/questions"
      }
    },
    "condition": {
      "urlFilter": "https://stackoverflow.com",
      "resourceTypes": ["main_frame"]
    }
  }
]

测试

https://stackoverflow.com         | redirected (OK)   |
https://stackoverflow.com/another | redirected (FAIL) | expected: not redirect

如何在ManifestV3中制定仅重定向

https://stackoverflow.com

google-chrome-extension chrome-extension-manifest-v3 chrome-declarativenetrequest
1个回答
1
投票

你应该能够使用

[
  {
    "id": 1,
    "priority": 1,
    "action": {
      "type": "redirect",
      "redirect": {
        "url": "https://stackoverflow.com/questions"
      }
    },
    "condition": {
      "urlFilter": "https://stackoverflow.com/|",
      "resourceTypes": ["main_frame"]
    }
  }
]

因为

|
指示其后不能有更多字符。

请参阅:

chrome.declarativeNetRequest
- URL 过滤器语法 - Chrome 扩展 API

© www.soinside.com 2019 - 2024. All rights reserved.