Search code examples
safari-extensionpkgbuild

Installing Safari Extension from Desktop Software Package


We have a desktop software for OSX distributed outside the Mac App Store, in a form of a pkg installer package. What we would like to do, is to install a Safari extension along with the desktop application during install.

Steps we have done:

  • We have the toolchain ready for successfully generating the pkg package for our desktop app.
  • Also the signed safariextz package creation is ready.
  • Both can be installed separately, but it would be nicer to package the Safari extension together with the desktop pkg installer to it in one step.

Is it possible with pkgbuild or productbuild do achieve this?


Solution

  • If your extension is a Safari App Extension, Safari should automatically detect the extension (and display it in Safari > Preferences > Extensions) as long as:

    1. The extension is located in the appropriate path in your app bundle (the PlugIns folder).
    2. Your app bundle is installed in /Applications.
    3. Your app bundle is properly signed with your Developer ID.

    However, the extension will default to disabled, and only the user can enable it through Safari Preferences. (There is no API to enable a Safari App Extension, although there are APIs to query its state, and to open the Safari preferences for the extension.)


    If your extension was created using the older method using Safari Extension Builder (which I presume it is, since you mentioned .safariextz), then unfortunately the only two permitted methods of installing it are:

    1. By clicking an Install button in the Extensions Gallery.
    2. By opening the (.safariextz) file in Safari. (Safari will prompt the user to confirm the installation.)

    Apple warns:

    Important: These are the only permitted ways to install a Safari extension. You should not attempt to install your extension any other way.

    And, in fact, they have taken steps to make it difficult to use creative methods to install the extension in any other way. (Likely to prevent malicious apps / installers from foisting extensions on users without their knowledge.)

    That said, you may be able to convert your existing extension to a Safari App Extension without too much work, and you are strongly encouraged by Apple to do so:

    Important: As of Safari 10.0 on macOS 10.11.5, Safari extensions are created as app extensions in Xcode. New extensions are wrapped in a containing macOS app and are distributed and sold on the App Store. If you have created an extension with the methods described in this document, consider transitioning to the new extensions model.

    (Note: You do not have to distribute your App via the Mac App Store to provide a Safari App Extension - Developer ID-signed apps should work too.)

    This would net you the benefits of the much easier install flow for Safari App Extensions.