Safari Closes Window When Closing Tab

I’m wondering if anyone else has encountered what appears to be a long-standing Safari bug, going back at least a couple of major macOS releases.

I often have two or three Safari windows open, each with multiple tabs. Sometimes, but not always, if I have a YouTube video in the active tab and then attempt to close the tab using ⌘W, the entire window closes, not just the intended tab. It happens often enough that I’ve noticed that it always involves a YouTube video as the tab I want to close, but it happens sporadically enough that I cannot reliably repeat the bug on demand.

Internet searching hasn’t turned up much information, but an A.I. query suggested that it is a known issue that occurs when script-heavy pages slow down and interfere with “dynamic menu mapping” in Safari, making Safari behave like the window only has one tab.

The A.I. suggested creating an explicit Safari keyboard shortcut that sets ⌘W to mean “close tab”. I’m trying that, but I do wonder if anyone else has encountered this issue or knows of a better fix.

Yes. Absolutely. I have experienced this multiple times. It always seems to involve closing a tab that contains some video content I had been playing. Perhaps not even strictly just YouTube (I use Vinegar anyway). I find it rather annoying, but unlike many other annoying bugs, I can usually just march on thanks to shift-cmd-t (History > Reopen Last Closed Window).

2 Likes

Agreed, though sometimes I fail to notice that the entire window closed when there is another window immediately beneath the first one. On at least a couple of occasions, the “Reopen Last Closed Window” item has not been available.

PS. A quirk of the A.I.'s advice to set a Safari keyboard shortcut for ⌘-W: it has the curious side effect of preventing ⌘-W from closing a window with a single open tab.