Safari Extensions: block content in 30 lines of code

CocoaHeads on 3 Apr 2017
iOS security Safari Extensions content blockers Swift

Safari Extensions in all their beautifulness: from js-injections and html-changes on users' phones to content blockers. Also there is a pitfalls overview including support of extensions in SFSafariViewController and WKWebView, remote blocking lists and many else.

About this talk

What does this talk cover?

What Safari extensions on iOS can do: JavaScript injection, changing pages as users browse, and building a working content blocker in about 30 lines of code - plus the pitfalls around SFSafariViewController, WKWebView, and remote blocking lists.

How do content blockers actually work?

They strip content by CSS selector, domain pattern, or HTML, with regex support, all driven by a JSON rule file - url-filter, resource-type, if-domain, and the rest. The talk walks through the format field by field.

What's the history of Safari extensions on iOS?

From Safari 5 extensions in 2010, to content blockers at WWDC 2015 on iOS 9, to Safari App Extensions in 2016 - and where Share Extensions and JavaScript injection fit in that arc.

Where can I watch it?

The full recording is embedded at the top of this page, with the slides linked in the resources section.

Related consulting

Content blocking grew into its own category - today I build Screen Time and parental-control apps for clients, and get the Family Controls entitlement approved.

Screen Time & Family Controls