As a Safari extension developer, I run into a lot of Safari bugs. A week ago I wrote about a bug where Safari forgets your history. This week I'm writing about a different bug. The bug was reported to me by one of my customers, as many bugs are, including last week's. Technically, it was more of a feature request than a bug report: the request was for my extension to "stop the madness". The madness in this case is Safari background tabs spontaneously coming to the front again, an obviously undesirable behavior. The initial report was for an obscure (to me) web site in New Zealand, but then I asked around, and someone said it also happened on ESPN, which is not so obscure (to me).
After spending many hours in the Safari web inspector debugging the issue, I finally found the surprisingly simple cause. If
window.open is called in a Safari background tab with an
iframe browsing context, the tab comes to the front. The bug occurs in the latest versions of Safari and Safari Technology Preview on macOS. It does not occur in Chrome or Firefox on macOS, nor does it occur in Mobile Safari. To reproduce the bug in Mac Safari, just press the button below, switch to a different tab, and then wait 5 seconds. The button loads the web page for my extension StopTheMadness into the
<iframe> element below the button.
Unfortunately, there's not a good way for StopTheMadness to stop this madness, so we have to wait for Apple to fix the bug. Don't hold your breath, though, because the bug exists in older Safari versions as far back as I could test (Safari 11 on macOS 10.13 High Sierra). At least you know now why it happens. As far as I know, I'm the first person to definitively diagnose these years old Safari bugs, which is honestly more depressing than delightful.