More disappearing Safari extensions

July 6 2022 by Jeff Johnson

A year ago I blogged about a macOS bug that causes all of your installed Safari web extensions to disappear silently and mysteriously from Safari. The bug seems to have started on Big Sur, and unfortunately it hasn't gotten any better on Monterey. If anything, the bug gotten worse. It's happening to me rather frequently now. And it continues to happen to other Safari users, not just users of my Safari web extension Tweaks for Twitter, but to users of all Safari web extensions from every developer. The problem has plagued all of us for more than a year, and Apple seems to refuse to make it a priority.

As a reminder, if your Safari web extensions have disappeared, you can restore them with a command in Terminal:

/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f -R /Applications/

However, this command might not restore your extension data. I've found that in some cases, Safari not only forgets the extensions, it also erases the extension storage! Extension storage files are located inside the folder ~/Library/Containers/ on your Mac. Tweaks uses local extension storage for your Tweaks preferences. Fortunately, Tweaks preferences are just a series of checkboxes that you enable or disable, so it's fairly easy to set them again if lost. But other Safari extensions may store important data that would be difficult to restore and distressing if lost, which makes this bug egregiously bad. Data loss bugs are the worst kind of bug. (I would also mention that Safari Intelligent Tracking Protection automatically deletes website storage after 7 days, but Apple considers this to be a "feature" rather than a bug.)

Although I haven't discovered how to reproduce the Safari web extensions bug reliably, its frequent occurrence has allowed me to investigate further. I've found that the removal of web extensions from Safari seems to occur in two stages. If you open the file ~/Library/Containers/, you'll see every Safari web extension installed on your Mac, and for each extension there's an AddedDate key. When the disappearing extension bug first occurs, you'll also see a RemovedDate key for each extension. This comes from the WBSExtensionStateExtensionRemovedDateKey symbol in the macOS SafariShared and SafariSharedUI frameworks. It appears that this key is added when you launch Safari, though I don't know what circumstances cause Safari to add it on launch. At this point, your Safari extension storage files are still safe on disk. On a subsequent launch of Safari, sometime later, it empties the Extensions.plist file and also deletes all of the extension storage. This is the second step. If you notice and restore your extensions with the Terminal command before the storage is erased by Safari, then you can get everything back safely. Otherwise it's too late, unless you've made a timely backup of your home folder, in which case you can restore the storage files from there.

I hope that Apple will take this new information, along with the information I've previously provided, to devote immediate attention and resources to finding and fixing the bug. I do know that Apple engineers have been aware of this bug for quite some time, so I don't understand why they've allowed it to linger.

Jeff Johnson (My apps, PayPal.Me)