Since I released my Safari extension Tweaks for Twitter three months ago, I've received a number of bug reports from customers saying that the extension doesn't appear in Safari. And when my app calls the API [SFSafariApplication showPreferencesForExtensionWithIdentifier: completionHandler:]
to show the extension in Safari Preferences, there's an error "SFErrorDomain error 1". This issue never happened with my other Safari extension StopTheMadness, which is three years old. The two extensions use different Safari extension API: Tweaks for Twitter is a Safari web extension, a newer API, whereas StopTheMadness is a Safari app extension, an older API. I've never been able to reproduce the issue with Safari web extensions myself until yesterday, so now I have more details to share. I suspect the reason I can now reproduce it is that I recently updated to Big Sur.
If you're just looking for a solution to the issue, here it is: quit Safari, copy the following command to the clipboard, open the Terminal app (located in the Utilities subfolder of the Applications folder), and paste the command.
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f -R /Applications/Safari.app
That's it, problem solved! The rest of this blog post will attempt a diagnosis of the problem.
Call the lsregister
command above with no arguments to see usage information for the tool. I created an alias in my .bash_profile
for convenience.
alias 'lsregister=/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister'
(Yes, I'm still using /bin/bash
on Big Sur, sosumi. By the way, you can add the line export BASH_SILENCE_DEPRECATION_WARNING=1
to your .bash_profile
to silence the Terminal warning about zsh.)
My command above forces Launch Services to re-register the Safari app. In order to diagnose the issue, I saved the output of lsregister -dump
to a file both before and after re-registering Safari. When I compared the files, there were a number of differences, mostly trivial (e.g., timestamps), but one big difference stood out to me. The extension point com.apple.Safari.web-extension
appeared in the "after" dump but not in the "before" dump:
--------------------------------------------------------------------------------
extensionpoint id: com.apple.Safari.web-extension (0x3a4)
ExtPointID: com.apple.Safari.web-extension
platform: native
Name: com.apple.Safari.web-extension
reg date: 2021-08-17 20:51 (POSIX 1629251472, 𝛥 13hr 4min 43sec)
SDKDict: 2 values (54164 (0xd394))
{
NSExtension = {
NSExtensionAttributes = {
NSExtensionPointName = "com.apple.Safari.web-extension";
NSExtensionPointVersion = "1.0";
};
NSExtensionProtocol = NSObject;
PrincipalClass = NSObject;
Subsystems = (
"NSSharingService_Subsystem"
);
};
XPCService = {
JoinExistingSession = 1;
RunLoopType = NSRunLoop;
ServiceType = Application;
"_AdditionalSubServices" = {
"apple-extension-service" = 1;
};
};
}
--------------------------------------------------------------------------------
Safari itself, as well as my Safari web extensions, did appear in the Launch Services dump both before and after. But somehow macOS had lost track of the fact that there was such a thing as a Safari web extension. Re-registering Safari served as a reminder of that fact.
I have two Safari web extensions installed, my own Tweaks for Twitter, as well as a third-party extension. Both web extensions disappeared from Safari — and from Safari Technology Preview — at the same time. My installed Safari app extensions, on the other hand, never disappeared. After I ran the lsregister
command, both of my Safari web extensions reappeared in Safari and in Safari Technology Preview.
I also ran the pluginkit --match
command before and after. Before, my Safari web extensions did not appear in the output (though my Safari app extensions did). After, my Safari web extensions did appear in the output.
I don't know what caused the com.apple.Safari.web-extension
extension point to become unregistered with Launch Services. That's still a mystery. Obviously this appears to be some kind of OS bug that occurs on Big Sur but not Mojave. I'm not sure at the moment whether Catalina is affected. I do know that other Safari extension developers have been affected too. For example, I found a bug report for Bitwarden on the web. Their solution lsregister -kill -r -domain local -domain system -domain user
is similar to mine but a bit of an overkill, because it resets the whole Launch Services database instead of just re-registering Safari. I recommend my own simple solution.