"css-display-none" type content blocker actions do not work in iOS 10.3.1

Originator:kane.cheshire
Number:rdar://31779540 Date Originated:24 April 2017
Status:Open Resolved:
Product:iOS + SDK Product Version:Safari Services
Classification:Serious bug Reproducible:Always
 
Running a simple "css-display-none" content blocker in iOS 10.3.1 does not work. The `SFContentBlockerManager` method `reloadContentBlocker` fails to reload the content blocker with an error stating that the content blocker is empty, and the rules are ignored when running Safari.

This is the error: 

Error Domain=_WKUserContentExtensionsDomain Code=3 "(null)" UserInfo={NSHelpAnchor=Extension compilation failed: Empty extension.

Running exactly the same simple content blocker in iOS 9 works fine and `reloadContentBlocker` reloads without an error.

This is the content blocker json:
[
    {
        "action": {
            "type": "css-display-none",
            "selector": "a"
        },
        "trigger": {
            "url-filter": ".*",
            "if-domain": ["macrumors.com"]
        }
    }
]

Ensure you call ``SFContentBlockerManager.reloadContentBlocker` AFTER enabling the content blocker in Safari settings or you will not get an error.

Steps to Reproduce:
1: create a content blocker with the following content blocker json:
[
    {
        "action": {
            "type": "css-display-none",
            "selector": "a"
        },
        "trigger": {
            "url-filter": ".*",
            "if-domain": ["macrumors.com"]
        }
    }
]
2: Run on a compatible device running iOS 9, enable the content blocker and call `SFContentBlockerManager.reloadContentBlocker`
3: Observe that the rules are working for iOS 9 when visiting MacRumors (all the links are missing)
4: Run the content blocker on a compatible device running iOS 10.3.1, enable the content blocker and call `SFContentBlockerManager.reloadContentBlocker`
5: Observe that the call to reload fails and the rules are no longer observed when visiting MacRumors.

Expected Results:
The content blocker should reload and the rules should be observed by Safari.

Actual Results:
The content blocker fails to reload and the rules are not observed by Safari.

Version:
iOS 10.3.1 14E304

Notes:


Configuration:
iPhone 7 Plus Black 128GB

Comments

This wasted 2 hours of my life. Xcode 8.3.3 ships with the 10.3.1 simulator, which still has this bug. The result was that none of my css-display-none blocker extension rules were applying in the simulator and I had no idea why.

Tested now on my actual 10.3.2 phone and they worked just fine. Glad I found this.

I've been fighting with this for a month.

Edit: tried it with iOS 10.2 and works perfectly.

Edit 2: It has been fixed in iOS 10.3.2

By alex.bartis at April 26, 2017, 6:42 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!