WebExtensions on Safari 14

WebExtensions on Safari 14

Safari 14 now supports WebExtensions, in addition to Safari App Extensions and after killing off Legacy Safari Extensions (.safariextz)

The official guides provided by Apple (a bit buried): https://developer.apple.com/documentation/safariservices/safari_web_extensions

A couple of notes:

  • Safari's WebExtensions implementation isn't feature-parity (and they most likely don't intend to be), so it's important to check Apple's docs, plus reference the browser compatibility tables for manifest.json and the various JavaScript APIs
  • Not every type of extension is possible:
    • Overriding the new tab, but then, Safari already has a built-in setting to change the new tab anyway
    • Ad blockers because webRequestBlocking isn't supported, but Safari has their own content blocker solution
    • Devtools extensions such as React Developer Tools or Vue.js devtools
  • Safari extensions always run on Private Browsing windows, unlike Chrome and Firefox which disables all extensions on incognito by default
  • The user needs to explicitly grant each extension access to a specific website in order for the extension to function, this is something that Chrome is also trying to do but probably quite hard without breaking existing extensions
  • The distribution method is similar with Safari App Extensions, the user needs to download a wrapper app that provides the Safari extension inside
  • Because of the distribution method mentioned above, packaging a Safari WebExtension won't be as straightforward as zipping the extension unlike Chrome/Firefox as you (most likely) need to face the intricacies of Xcode signing
  • Apple's docs doesn't seem to have any mention of self-hosted extensions (unlike safariextz), so it's most likely only available through the Mac App Store
  • Apple really doesn't want people to use the development mode 'backdoor' to sideload extensions (or at the very least, make it annoying and painful to do so) by not allowing unsigned extensions by default and discarding the extension every time you relaunch Safari

I tried out the WebExtensions support by installing macOS Big Sur beta and Xcode 12 beta. I used CRX Viewer to grab and download a random Chrome extension, then open Terminal

xcrun safari-web-extension-converter /Users/user/Downloads/ghdnfbmfflgelndafnlgabneckbmfpla

Once the Terminal command is done, Xcode pops up and you can just click the top-left 'play' button to build and run the app.

Safari will launch, then you can open the Safari Extensions window and see that your extension should be inside. If it's not, then you need to enable the Develop menu at Preferences, then enable "Allow Unsigned Extensions".