SafariConverterLib icon indicating copy to clipboard operation
SafariConverterLib copied to clipboard

Consider using `if-top-url/unless-top-url` in newer Safari versions

Open ameshkov opened this issue 4 years ago • 3 comments

Example: if-domain: [ "example.org", "*example.org" ] --> if-top-url: [ "^[htpsw]+:\\/\\/://([a-z0-9-]+\\.)?example.org/" ]

Ideally, we'll simply need a JSON built with this new approach. Once we have it, we'll be able to see how long it takes Safari to compile such a content blocker and whether it's faster or not.

ameshkov avatar May 21 '21 11:05 ameshkov

Regex from the subject is not correct, I've used the next one.

{
    "trigger": {
        "url-filter": ".*",
        "if-top-url": ["^[htpsw]+:\\/\\/([a-z0-9-]+\\.)?example.org"]
    },
    "action": {
        "type": "css-display-none",
        "selector": ".banner"
    }
}

I've generated random 50000 rules like example.org##.banner and reloaded content blocker. Rules with if-domain trigger were loaded faster

  • if-domain - 2.2 seconds
  • if-top-url - 4.2 seconds

After that, I've tried the filter with real rules https://raw.githubusercontent.com/AdguardTeam/FiltersRegistry/master/filters/filter_2_English/filter.txt And again rules with if-domain trigger were loaded faster

  • if-domain - 6-8 seconds
  • if-top-url - 9-12 seconds

With both kinds of triggers I didn't notice that the browser become slowly

maximtop avatar Jun 21 '21 11:06 maximtop

We should do that experiment one more time after iOS 15 is out and we can create content blockers with 150k rules. I am not yet sure how important this slowdown will be.

ameshkov avatar Aug 26 '21 08:08 ameshkov