Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Creating a Manifest v3 URL redirect from directly a URL

The new StackOverflow homepage is annoying. I thought I’d quickly set up the browser to redirect to the /questions subpage instead. I wrote the script for it. However, I’ve noticed that when I specify the StackOverflow homepage directly, it keeps redirecting every request to the /questions subpage (e.g., profile, specific question, etc.) incorrectly.

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

Tests

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

How can I formulate in Manifest v3 to redirect only https://stackoverflow.com?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should be able to use

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

since a | dictates that no more characters may come after it.

See: chrome.declarativeNetRequest – URL filter syntax – Chrome Extension API

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading