1

What's the proper way to create whitelists when using Safari content blocker API? https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/ContentBlocker.html

Imagine I have an adult content blocker like this one, but instead of 3 domains, 50000. (I already did it and it works)

[
    {
        "action": {
            "type": "block"
        },
        "trigger": {
            "url-filter": ".*",
            "if-domain": ["*xvideos.com", "*pornhub.com", "*xxx.com"]
        }
    }
]

How should I add a whitelist? Do I have to create a second blocker with other rules or do I have to modify my adult content blocker to remove the whitelisted domains programmatically in real time, generate another JSON and reloading it?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ricardo
  • 2,831
  • 4
  • 29
  • 42

1 Answers1

2

You start by blocking everything:

{
    "action": {
        "type": "block"
    },
        "trigger": {
        "url-filter": ".*"
    }
}

than you whitelist (for example) the website "Google.com":

{
    "action": {
        "type": "ignore-previous-rules"
    },
    "trigger": {
        "url-filter": "Google.com/.*"
    }
}

Here I approve "Google.com" and everything down his hierarchy, for example "Google.com/shop" or "Google.com/account".

Edit: it seems I was wrong, and not the first one to fall into it, to white list a website, This is how it's done:

{
    "trigger": {
        "url-filter": ".*",
        "if-domain": ["Google.com"]
    },
    "action": {
        "type": "ignore-previous-rules"
    } 
}

You can see full list of commands here: https://developer.apple.com/documentation/safariservices/creating_a_content_blocker

Also check this question: iOS Content Blocker Whitelist Website

Ori
  • 21
  • 4