Building a Safari App Extension

I followed the walkthrough here: https://developer.apple.com/documentation/safariservices/safari_app_extensions/building_a_safari_app_extension?language=objc

and created new target for a Safari App Extension, but it doesn't show up in Safari. The extension should be code-signed, but I've tried allowing unsigned extensions, and it doesn't help.

The "Troubleshooting Your Safari App Extension" article suggests that you can verify your extension is visible to Safari by runnin ghtis terminal command:

pluginkit -mAvvv -p com.apple.Safari.extension

Since the output is "(no matches)" I'd say mine isn't. Unfortunately the author of the article couldn't be bothered to suggest any reasons why this might be, or what you might be able to do about it. I've tried various combinations of relaunching applications and rebooting my Mac, which is often the fix when Xcode refuses to do something for no good reason, but it's no help in this case.

I also tried changing the "SFSafariWebsiteAccess" level to "All", but I don't think that's relevant since the extension isn't showing up at all.

So what's the magic step that's missing from the walkthrough (and the Xcode template) to produce an extension that actually appears in Safari?

Replies

Update:

So launching the app doesn't make the extension appear in Safari like the walkthrough says it should. You can get the extension to appear if you specifically launch its scheme in Xcode. I'm not sure if this is any real help, since I still can't find a way to make it appear that a user could actually do.

I might be totally wrong (some insight from the Apple side would definitely help!), but far as I understand


- the extension still must be signed, but you can use any certificate for testing;

- not only it must be signed; it must be sandboxed so as Safri launches it (if you need to do something which can't be done in a sandbox, use an XPC Service);

- the Safari “Allow Unsigned Extensions” switch actually means something like “Allow Extensions Signed By Any Certificate From Any Application”, or so.


At least, this works for me: a signed/sandboxed extension does appear in Safari soon as I run the container application from Xcode.


Note: for me, in High Sierra and Xcode 9 this works without a glitch. In Mojave and Xcode 10 though, the extension sometimes inexplicably disappears from Safari (regardless that “unsigned extensions” are still allowed and I've just re-built); I found to get it back I need to clean, re-build, and run again the container application. Looks like Apple “improved” something in there 🙂

Well, I was just coming back to report that mine has started working, and my experience is similar to yours. I've moved up to Xcode 10 and Mojave, since I'm primarily working on fixes the issues that causes.

I had made a new minimal project that has a do-nothing application containing a hello-world extension, which also hadn't been working.

Today I noticed that my test extension had started appearing in the Extensions pane of the preferences, although its toolbar button still wouldn't appear. On a whim, I replaced the ToolbarItem.pdf file from the template with a new PNG image, and suddenly the hello-world extension started working properly. It even updated when I added an extra label to its XIB file. After a bit more messing about, comparing the build settings and PLISt files for the working and non-working extension and their containing apps, I just did a clean and rebuild of the containing app again, since I hadn't done that today, and the other extension suddenly appeared. I've no idea why this suddenly started working, but at least it is.

I also agree that Apple's documentation on this stuff could do with being a lot better. I can't even find anything that explains why they used a PDF for their icon, or what its specs are supposed to be. Fortunately it seems to be irrelevant.

I am also experiencing a lot of problems in getting just the basic hello world example to get to work. I am on xcode 10.2 and mojave. The extension example code that I get when creating a new extension target simply does not work. Or better said it works only 20, 30 seconds or so and then safari crashes and I have to rerun the extension. Totally impossible to work with this. On the one hand Apple pushes extension developers to move to App extensions, on the other hand the documentation and development platform is totally insufficient in accomplishing this task.