Adding JS error check to wait for page to load