Skip to content

Instantly share code, notes, and snippets.

@tomialagbe
Forked from mackuba/content_blocker_tips.md
Created August 11, 2021 04:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomialagbe/72b009fdb5938f10c5f0bed4343f2d4a to your computer and use it in GitHub Desktop.
Save tomialagbe/72b009fdb5938f10c5f0bed4343f2d4a to your computer and use it in GitHub Desktop.
Tips for writing iOS content blockers - HelsinkiOS
  • read this first: https://www.webkit.org/blog/3476/content-blockers-first-look/
  • start by adding a new extension target to your iOS app of type “content blocker”
  • launch the app using the main target’s scheme + a call to SFContentBlockerManager.reloadContentBlockerWithIdentifier() with the extension’s id in application:didFinishLaunchingWithOptions: to auto-reload the blocker in development mode
  • if you don’t call reloadContentBlockerWithIdentifier() then you need to switch the blocker off and on again in the Safari settings (stop the app in Xcode if the switch is not moving)
  • use inspector from desktop Safari to inspect the Safari in the simulator in order to find specific things to block
  • things like periods in the url-filter regexp need to be escaped with double backslashes, e.g. facebook\\.net
  • if you use if-domain, it needs to be an array, even for one element
  • domain foo.com might not match www.foo.com even though I think it’s supposed to (UPDATE: They've changed it in one of the betas, now foo.com only matches foo.com and to match all subdomains you need to use *foo.com - thanks @CraftyDeano!)
  • remember that extensions are separate from the main app - use app groups and shared app group containers to share data between the app and the extension
  • json file can be updated silently or even generated on the fly, just return whatever you want to in the beginRequestWithExtensionContext: callback
  • look for critical errors in ~/Library/Logs/CoreSimulator/*/system.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment