3

I've been having a strange issue where the second time I run my Safari app extension, it won't show up in Safari.

  1. Open Xcode.
  2. New > Project.
  3. Under Other, select Safari Extension App, then click "Next".
  4. Enter whatever you want on this "product name" screen and then click "Next".
  5. Click "Create".
  6. Run the project by clicking the Play icon in the top-left of Xcode.
  7. It will open a small app with a single button at the bottom with the text: "Open in Safari Extensions Preferences".
  8. It probably won't show up. If it does, skip to 10.
  9. Go to Develop in the title menu of Safari, click "Allow Unsigned Extensions".
  10. Once shows up, check the box to enable it.
  11. Stop Xcode from running by clicking the stop icon in the top-left.
  12. Change a value in the Info.plist of the plugin such as changing the SFSafariWebsiteAccess.Level from "Some" to "All".
  13. Click the Play icon in Xcode.
  14. Safari will tell you the extension permissions have changed. Acknowledge those changes and the extension will no longer show up.

The same thing happens if I change other values. If I leave the extension code and settings completely unchanged, no problems occur. But as soon as I change some value, it completely breaks even if I change those settings back.

This happens for me on two different Macs, both 10.13 and 10.14 with the latest Xcode.

Kevin Ghadyani
  • 6,829
  • 6
  • 44
  • 62
  • Normally, the project settings would not have to be changed when an extension has been published/shipped to users (permissions, extension name, ...) otherwise it could be badly abused by extension developers. So actually it is the behavior Safari devs have chosen to protect the users. If a developer makes an app with very few and harmless permissions and then changes the permissions to harmful ones when enough users have installed his app, that would be bad... that's why **Safari** (not Xcode) restricts this by disabling the extension automatically. – Jeffrey Mvutu Mabilama Sep 01 '19 at 11:35

3 Answers3

5

I have run into this exact problem with Xcode on Mojave. What I have to do is go to Product>Clean Build Folder. It's probably the same thing you are doing, but a little easier.

Grinder
  • 151
  • 1
  • 2
  • 8
  • This is, for me, the correct answer. I assume that once the extension is run it is held in memory so recompiling does nothing. You need to delete it so that Safari understands that something has changed, and then reloads the new version. – Rebecka Jan 15 '20 at 23:42
2

The only way I've been able to correct for this issue is by going to your build directory and deleting the build files.

You will first have to stop your project, then delete this directory: ~/Library/Xcode/DerivedData/[YOUR_PROJECT_NAME]/Build/Projects/Debug

YOUR_PROJECT_NAME will be your project's name plus a bunch of random characters so you will need to search for the real name of this folder yourself.

Kevin Ghadyani
  • 6,829
  • 6
  • 44
  • 62
0

You can edit the scheme for the _____extension.appex, and set its executable to Safari.app. That'll open a new instance of Safari every time you build/run the extension (not the wrapper). This'll also have the Xcode console show the output from the extension. Be careful though; if Safari crashes, you risk losing all the tabs that you'd opened. You neither have to clean the build folder (or manually delete the files in Finder), this way.