Fix issues on JS evaluation during page loading

Evaluating JS code during some load steps causes some errors.
We should recreate the sandbox at each step to be sure we have
the right window and document object.