Safari Extension doesn't load after running Product > Archive

I've been developing a Safari web extension for MacOS and iOS, and I'm running into a very strange issue.

I ported over my Chrome extension to Safari, and for several days as I was iterating on the extension (change code, build, run, test in Safari), everything worked perfectly fine.

Once I was finished with the extension, I followed the instructions on how to prepare to submit the Safari web extension (and it's containing MacOS and iOS apps) to the App Store for review.

For the MacOS app and Safari web extension on Mac, I changed my target from "My Mac" (which I'd been using for testing), to "Any Mac". I then went to the "Product" menu in Xcode and selected "Archive"

That's when things started to go wrong.

The next time I went to Safari, my web extension could no longer find critical files to run the extension (such as background.js, popup.html, etc.) This was despite there being no code changes before or after me creating a build archive.

When I restarted Safari, the extension no longer appeared in the list of extensions within preferences. No matter what I do (clean build folder and re-run, restart Safari, restart Xcode, restart computer), nothing will get my extension to show up in Safari again.

Note that this does not happen with the Safari web extension in the iOS simulator. It only happens on Mac.

I was confident that my extension was working, so I submitted my extension to the Mac App Store for review. It was approved, and a few users have downloaded it and it works totally fine.

To further try to figure out what's going on, I created a new sample Xcode project. From the new project screen, I chose the "Safari web extension" under "Multiplatform".

Without making any code changes, I build and run that project, and the default MacOS app and Safari web extension from the template. I then immediately create an archive (with no code changes). Once I try to run the project for my Mac again, the extension no longer works.

So I have verified that this problem does not have to do with my extension's code, but I cannot for the life of me figure out what is wrong. I have examined every possible build setting, but given that I ran a default project template, made no changes, and it still had this problem, I'm not sure what else could be wrong.

Answered by Engineer in 821488022

You may have several of the same app and extension on your machine. Check your Xcode project's build products and derived data and ensure to delete all previous archived versions of the app with extension on device. I am able to reproduce this when several copies of the same app are on the same machine. It seems to be an issue with Safari, but that is a workaround that should get your extension to show again.

This is likely a Launch Services issue. See my blog post and the appendix: https://lapcatsoftware.com/articles/2024/12/2.html

See also FB16144327 - Xcode clean of a Safari extension app causes the extension to disappear from Safari Settings https://github.com/lapcat/SafariExtensions/issues/54

Accepted Answer

You may have several of the same app and extension on your machine. Check your Xcode project's build products and derived data and ensure to delete all previous archived versions of the app with extension on device. I am able to reproduce this when several copies of the same app are on the same machine. It seems to be an issue with Safari, but that is a workaround that should get your extension to show again.

Safari Extension doesn't load after running Product > Archive
 
 
Q