Unable to block youtube with chrome's declarativeNetRequest API but I can redirect from it

148 Views Asked by At

I am trying to block youtube using chromes declarative Net Request API. While I can redirect from the youtube homepage I can still watch embedded videos in google.com or other websites. Trying to use the declarative Net Request to block youtube revealed that it doesn't block youtube at all, unlike other websites. I am looking for a way to block embedded youtube videos as well as an answer to why the declarative Net Request API does not block youtube.

To study the core of the problem I made two simple extensions. One blocks both google and youtube matching how the API does it. The other one redirects from the pages to example.com, again matching how the api does it.

The blocking one blocks google but youtube is still accessible.

The redirecting one successful redirects from both google and youtube to example.com

here are my examples on GitHub

Manifest of blocking extension 
{
  "manifest_version": 3,
  "name": "blockYoutube",
  "version": "1.0",
  "icons": {
},
"declarative_net_request": {
  "rule_resources": [{
    "id": "ruleset_1",
    "enabled": true,
    "path": "rules_1.json"
  }]
},
  "permissions": [
     "declarativeNetRequest"
    ],
  "host_permissions": ["<all_urls>"]
}
Rules of blocking extension
[
    {
        "id" : 1,
        "priority": 1,
        "action" : { "type" : "block" },
        "condition" : {
          "urlFilter" : "google.com",
          "resourceTypes" : ["main_frame"]
        }
    },
      {
        "id": 4,
        "priority": 1,
        "action": { "type": "block" },
        "condition": {
            "urlFilter": "youtube.com",
            "resourceTypes": ["main_frame"] }
      }
]
Manifest of Redirecting extension
{
  "manifest_version": 3,
  "name": "redirectYoutube",
  "version": "1.0",
  "icons": {
},
"declarative_net_request": {
  "rule_resources": [{
    "id": "ruleset_1",
    "enabled": true,
    "path": "rules_1.json"
  }]
},
  "permissions": [
     "declarativeNetRequest"
    ],
  "host_permissions": ["<all_urls>"]
}
Rules of Redirecting extension
[
    {
        "id" : 1,
        "priority": 1,
        "action" : { "type": "redirect", "redirect": { "url": "https://example.com" } },
        "condition" : {
          "urlFilter" : "google.com",
          "resourceTypes" : ["main_frame"]
        }
    },
      {
        "id": 4,
        "priority": 1,
        "action": { "type": "redirect", "redirect": { "url": "https://example.com" } },
        "condition": {
            "urlFilter": "youtube.com",
            "resourceTypes": ["main_frame"] }
      }
]
0

There are 0 best solutions below