CPU on Fire? Douse the Tab

Klaas van Schelven
Klaas van Schelven; May 21 - 2 min read
Left: a webpage; right: a crash
Tabdouse in Action

I’m old. Old enough to get annoyed when a browser tab makes my laptop sound like it’s doing something important. It isn’t.

Could there be a way to punish the web pages that make my fans spin? I mean, I could just close the tab. But that’s not satisfying enough.

Sure, I could have gone the clean route: sandbox Firefox with cgroups, limit its CPU share, and let the kernel enforce good behavior. But that doesn’t feel like justice.

So I grabbed my duct tape and wrote a script that kills the worst offenders. It runs top, adds up Firefox CPU usage. If it’s too high for too long, it starts tracking individual “Isolated Web Co…” and similar subprocesses. After eight seconds, the worst one gets killed. The thresholds for CPU usage and time are arbitrary. But it works.

And yes, it’s extremely satisfying to see the “Gah. This tab crashed” screen right when you started getting irritated at some page for making your laptop sound like a jet engine.

Some primitive part of the brain really enjoys seeing bad actors get what they deserve.

A Useful Filter

I’ve found that websites that make my fans spin are rarely worth reading anyway. Much like the ones that hit you with full-page cookie banners or “subscribe” popups—nothing of value was lost. It’s a useful filter, not a bug.

Select Offenders

The web’s awash in offenders, so this section is limited to “maximum irony” only.

Code & Disclaimer

This has nothing to do with Bugsink, other than reflecting the project lead’s taste in performance. Code: tabdouse.py — written in 30 minutes, no guarantees.