You can make a difference in the Apple Support Community!

When you sign up with your Apple ID, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

How do I delete all tab groups in Safari?

I don't know how it happened, but I can't use Safari on any of my devices due to it being bogged down with over 1200 tab groups. I checked my cameras at home and sure enough one of my cats sat on my keyboard and somehow created over 1200 duplicate tab groups, each containing over 380 bookmarks. I have tried turning off iCloud syncing. I am unable to delete any tab group individually as it just freezes the computer. How can I delete all tab groups simultaneously? Thanks!

Posted on May 31, 2024 6:56 PM

Reply
11 replies

Jul 16, 2024 7:37 AM in response to francisperea

Okay, we'll try! This is not me (don't want to steal credit!). But it worked for me. Courtesy of Alexander Neth who posted this at Medium.


DISCLAIMER. It's very hard on a modern Mac, especially with Apple silicon, to "lock" the OS, but scripts are running right there in the UI, simulating your own keystrokes and mouse movements, so I recommend not having anything terribly significant — unsaved — in any other application window when you do this. Run it when it won't break your heart if, halfway through, you feel the need to reboot.


Here we go!


Starting on your Mac …

#1 Quit and then relaunch Safari, #2 get one browser window open and make sure that the sidebar with that endless list of tab groups is visible in it (View > Show sidebar); in other words, the active window in Safari needs to be the window containing the tab groups you want to delete or the script will end up just banging its head against the wall, so to speak


#3 Now open Script Editor, create a new script (File > New), and #4 plop this in via Copy and Paste:


-- Function to log messages to the Script Editor result

on logMessage(message)

log message

end logMessage


-- Activate Safari

tell application "Safari"

activate

end tell


delay 1


-- Main block for interacting with Safari's UI

tell application "System Events"

-- Verify Safari process exists

if exists process "Safari" then

tell process "Safari"

-- Navigate through each Personal Tab Group

repeat

try

-- Select the next tab group

keystroke (ASCII character 31) using {command down, option down}

delay 0.5

-- Close the tab group

keystroke "w" using {command down, control down}

delay 0.2

on error errMsg number errNum

-- Log the error if unable to delete a Personal Tab Group

my logMessage("Failed to delete a Personal Tab Group: " & errMsg & " (" & errNum & ")")

end try

try

-- Check for delete confirmation dialog

if exists (sheet 1 of window 1) then

click button "Delete" of sheet 1 of window 1 -- Confirm deletion by clicking the "Delete" button

delay 1

end if

on error errMsg number errNum

-- Log the error if unable to confirm deletion

my logMessage("Failed to delete a Personal Tab Group: " & errMsg & " (" & errNum & ")")

exit repeat

end try

end repeat

end tell

else

-- Log if Safari process is not found

my logMessage("Safari process not found.")

end if

end tell


(in theory this next part is optional, but I saved it to the Desktop before the next step, just in case it broke and I had to reboot)


Ready? Last step is to ... #5 run the script (press the 'play' button) in Script Editor.


At least in my experience, while it's running, you're kind of captive to it. You can't do much else. I was able to COMMAND-TAB to Safari and 'watch' the tab groups slowly disappear (Safari will give you a running summary of tab groups deleted and tab groups remaining), and that's when you might want to go make some coffee or read a nice, long Atlantic article. 😊 It will take a little while. Empty tab groups will disappear faster than those with embedded favorites.


NOW … WHAT ABOUT MY PHONE?

Going into this process, I had tried several combinations of activating Safari — and de-activating Safari — from the list of apps that use iCloud (iOS > Settings > [your Apple ID] > APPS USING ICLOUD > Show All > Safari). I did that on the Mac a few times, too, just to see if removing some of Safari's supporting containers from the Library hierarchy helped. It didn't.


But I point this out because one of my fears in running the script was that, upon completion, the Mac would query iCloud, see all the tab groups on the PHONE, and just copy them all over again.


At least for me, that did NOT happen. 😅


For me, I just needed to be patient. It took about 30-45 minutes for the iPhone to sync and retire its "copy" of those extraneous tab groups.


Hopefully this works for folks! If it does, thank Mr. Neth and check him out on Medium.


Jul 24, 2024 11:04 AM in response to iGrayBeard

Hi iGrayBeard,


Thanks a lot for your contribution.


Yesterday I got a call from Apple Support. They said that they know the existence of this bug and that it should be supposedly corrected in next MacOS update.


By the moment I decided to give a try to your script and after adjusting a bit the waiting times for my situation (I had some groups with more than 12 tabs that wew heavy to load) and after more than 6 hours working I finally get rid of all those thousands of tab groups!


After that I have back enabled Safari in iCloud and they have also disappeared in my iPhone and iPad.


By the moment I'm not still able to see iCloud tabs shared among devices but I hope it is just a question of time and/or restart, but the heavy weight of the tabs groups has ended.


Thanks a lot once again!


I'll leave my adapted version of the script in case any one can use it.


Regards,


tell application "Safari"
	activate
end tell

delay 1

tell application "System Events"
	if exists process "Safari" then
		tell process "Safari"
			repeat
				keystroke (ASCII character 31) using {command down, option down}
				delay 0.5
				keystroke "w" using {command down, control down}
				delay 0.5
				if exists (sheet 1 of window 1) then
					click button "Delete" of sheet 1 of window 1
					delay 1			
				end if
			end repeat
		end tell
	end if
end tell

Jul 11, 2024 3:03 PM in response to Eric Extreme

I was able to mass delete the unwanted tab groups under Sonoma on the Mac


You do need to make sure you have the sidebar visible in Safari before you run it and it does take a while (and it's not the kind of thing where, at least in my experience, you can do anything else while it's running as it's effectively a screen macro).


BUT! Once done, the tab groups are gone. For your other devices, you do need to be patient. It took about an hour for everything to stabilize.


[Edited by Moderator]




Jul 15, 2024 7:13 AM in response to Eric Extreme

Hi all,


I finally had to get in contact with Apple Support, they asked for lots of information because it seems they know already that there is some kind of problem with this. More than a month later I still have no solution for this.


The only thing I've been able to do is delete all tabs on Mac (they are stored on several SafariTabs* files on ~/Library/Containers/com.apple.Safari/Data/Library/Safari/) and disable iCloud for Safari in all my devices.


If I get some news from Apple Support I'll let you know.


Regards,

Jul 15, 2024 11:18 AM in response to hendrikfromparis

I apologize. My initial post included a link to a script I found that automated the process, but guidelines for Apple support forums bar the inclusion of external links (which I get; for every noble effort to point someone to a useful resource, there would be spam links or other malicious cruft).


So, I posted — and then that section was removed! Automatically.


If it's permitted to include the text of the script in a post, with attribution, I'm happy to do it, but someone overseeing the thread needs to give me their blessing first.


How do I delete all tab groups in Safari?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.