Occasionally, when I transition from one tab to another, the Firefox window loses focus. This is especially notable when I switch or close tabs via keyboard shortcuts. For example, I can be closing a bunch of tabs with Ctrl+w and suddenly it stops working. I have noticed that the Firefox window title is grayed out, indicating that the window has lost focus. Alt tabbing or clicking the window regains focus, but this is disruptive to the browsing experience.
To test if another application is stealing focus from Firefox, I kept this line running in a terminal
while true; do sleep 20; xdotool getwindowfocus getWindowname; done
which prints the name of the currently active window to stdout every 20 s. When Firefox loses focus, no window title is printed (just a newline), indicating that there is no other application that steals the focus from Firefox. Firefox is the only application that displays this behavior.
I am on Firefox 47.0 on Antergos (Arch derivative) Linux with Gnome 3.20.2 and kernel 184.108.40.206. Why does this happen and what can I do to make Firefox stop losing the window focus?