Add logic that was accidentally removed in #38745. Otherwise it is very
weird when using webdriver as a human, as we still stays on the original
tab.
Testing: ~this should not affect any test. Even if the tab is not
"visible" previously, all programmatic interaction works fine.~ Stably
pass `test_history_pushstate` in `back.py` and `forward.py`.
---------
Signed-off-by: Euclid Ye <euclid.ye@huawei.com>