Folked from official selenium webdriver js