How to prevent/close duplicate tabs in Safari?

Solution 1:

I can't find any extension that achieves this, but (9 years after question was asked), Safari does have built-in tab sorting in the Window menu ("Arrange tabs by"). So, that might be a good-enough solution. First sort tabs by "Website", then it's easier to go through them with command+shift+] and remove duplicates.