How to remove “stuck” iCloud Tabs in Safari

Things at Apple work great until the day they don’t. A silly example that really bugs me is “stuck” iCloud tabs on Safari — a glitch in Apple’s tab syncing feature that lets me access tabs from one device on others.

The issue happens when one or a set of tabs refuses to disappear from the synced list. For example: I’m on device A and Safari shows two tabs open on device B. I close both tabs from B (either on A or on B), but they almost immediately reappear on A as if they were still open on B, which they’re not.

I use Safari’s tab syncing quite a bit, and seeing a stuck tab there pretty much kills the appeal of the feature for me.

There is a solution, but it’s far from the beautiful UIs Apple takes such pride in their software. To fix this problem, you need to turn to the command line. (Which isn’t rocket science, just a bit intimidating for those unfamiliar with Terminal.)

The tip below is a transcription of this Reddit post, written by user u/lando55. We’ll need Terminal (so, a Mac) and a database editing application. In this case, we’ll use the same one they did, sqlite3, which (unless I’m mistaken) comes pre-installed on macOS. Run the command where sqlite3 or sqlite3 --version in Terminal and see if it returns something. If you get an invalid command error, Homebrew or MacPorts are your friends.

The first step is to close Safari on all devices connected to your Apple Account and disable Safari syncing with iCloud on all of them.

Now, open Terminal and navigate to the directory ~/Library/Containers/com.apple.Safari/Data/Library/Safari1:

cd ~/Library/Containers/com.apple.Safari/Data/Library/Safari

There should be a database file that stores Safari tabs synced by iCloud, called CloudTabs.db. Open it with this command:

sqlite3 CloudTabs.db

The Terminal prompt will change, indicating you’re inside the database.

Use this command:

SELECT * FROM cloud_tabs LIMIT 100;

This will list all synced Safari tabs. The stuck ones should appear somewhere in there. To see a list of just the synced tabs (URLs), use this command:

SELECT url FROM cloud_tabs;

Each device connected to iCloud is associated with an identifier, the device_uuid. To list all of them, use this command:

SELECT DISTINCT device_uuid FROM cloud_tabs;

If you have many tabs open and want to keep them, identify which device_uuid the problematic tabs are associated with from that first sqlite3 command, and with that code in hand, run this command:

DELETE FROM cloud_tabs WHERE device_uuid = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX';

Replace all those “X”s with the device_uuid of the troubled device. Note that this action is destructive and irreversible unless you’ve made a backup of the database.

If you don’t have important tabs and closing all of them won’t cause any harm, run the above command for all the device_uuid values you found.

By the way…

Over here, I’ve found some device_uuid entries from old devices or current ones that were wiped at some point. I always delete all of them.

Once you’re done editing the database, exit with the command .quit and re-enable Safari syncing in iCloud.

If everything goes right, when you open Safari again it should be free of those stuck tabs.

  1. In some cases, the synced tabs database might be in the ~/Library/Safari/ directory instead.

Subscribe to my newsletter

Or, subscribe to the RSS Feed.