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:
on logMessage(message)
log message
end logMessage
tell application "Safari"
activate
end tell
delay 1
tell application "System Events"
if exists process "Safari" then
tell process "Safari"
repeat
try
keystroke (ASCII character 31) using {command down, option down}
delay 0.5
keystroke "w" using {command down, control down}
delay 0.2
on error errMsg number errNum
my logMessage("Failed to delete a Personal Tab Group: " & errMsg & " (" & errNum & ")")
end try
try
if exists (sheet 1 of window 1) then
click button "Delete" of sheet 1 of window 1
delay 1
end if
on error errMsg number errNum
my logMessage("Failed to delete a Personal Tab Group: " & errMsg & " (" & errNum & ")")
exit repeat
end try
end repeat
end tell
else
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.