Ah this is a good point. So it would literally need to be visible, focused, and the computer likely shouldn't enter sleep mode during the mining process. That's a lot of hoops.
Visible is enough. It does not have to be focused. It can mostly also be covered by other (browser) windows, but if it is minimized or in another tab, it gets throttled.
That hit me a few times, but ads and malware ruined that for everyone. (and there is no simple permission dialog possible, where you ask the user to allow it)