Mode 1: Render static content; allow unobtrusive JavaScript operations (perhaps capped by total operations or CPU usage).
Mode 2: Run unlimited JS operations, allow alert() and window.onbeforeunload events handers.
The second mode could be called "Application Mode" and could be turned on selectively per site.
This would allow you to give gmail.com whatever resources it needed. But clickbait-headline-slideshows.com could not, unless you explicitly allowed it.