Change timeout/wait handling

timeout now means "total time limit", not "maximum time before window.onload". 
Also, max 'wait' value is decreased to 10s.

The code can be slightly refactored to specify the 'wait' max value in a single place, but it will introduce merge conflicts with other PRs so I haven't done that.