wdman icon indicating copy to clipboard operation
wdman copied to clipboard

wdman Fails to Download Correct ChromeDriver for Chrome 133

Open STS912 opened this issue 10 months ago • 1 comments

Operating System: [Your operating system, e.g., macOS 14.5, Windows 10, Ubuntu 22.04]

R Version: [Output of R --version in your terminal]

wdman Version: 0.2.6

Chrome Version: 133.0.6943.127

Problem Description:

I am encountering an issue where wdman fails to download the correct ChromeDriver version for my Chrome browser (version 133.0.6943.127). I am using the Chrome for Testing API to retrieve the chromedriver version.

Steps to Reproduce:

  1. Installed the latest wdman package (0.2.6).

  2. Used the following R code:

    library(RSelenium)
    library(dplyr)
    library(logger)
    library(wdman)
    library(jsonlite)
    
    

#' Setup logging configuration setup_logging <- function() { log_threshold(INFO) log_layout(layout_simple) }

#' Initialize Selenium WebDriver with automatic ChromeDriver management using Chrome for Testing initialize_driver <- function() { setup_logging()

tryCatch({ log_info("Initializing Chrome driver")

# Get Chrome version from Chrome browser
chrome_version_string <- system("/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --version", intern = TRUE)
chrome_version_string <- gsub("Google Chrome ", "", chrome_version_string)
chrome_version_string <- trimws(chrome_version_string) # Trim whitespace

# Extract major version
major_chrome_version <- strsplit(chrome_version_string, "\\.")[[1]][1]

# Fetch ChromeDriver version from Chrome for Testing API
api_url <- paste0("https://googlechromelabs.github.io/chrome-for-testing/LATEST_RELEASE_", major_chrome_version)
chromedriver_version <- readLines(api_url, warn = FALSE) # Read as text

log_info(sprintf("Using ChromeDriver version: %s", chromedriver_version))

selServer <- chrome(port = 4445L, version = "133")

remDr <- remoteDriver(
  remoteServerAddr = "localhost",
  port = 4445L,
  browserName = "chrome"
)

# Attempt to connect with retries
max_retries <- 3
for (i in 1:max_retries) {
  tryCatch({
    log_info(sprintf("Connection attempt %d of %d", i, max_retries))
    remDr$open()
    log_info("Successfully connected to Chrome WebDriver")
    break
  }, error = function(e) {
    if (i == max_retries) {
      stop(sprintf("Failed to connect after %d attempts: %s", max_retries, e$message))
    }
    log_warn(sprintf("Connection attempt %d failed, retrying...", i))
    Sys.sleep(2)
  })
}

return(list(driver = remDr, server = selServer))

}, error = function(e) { log_error(paste("Driver initialization failed:", e$message)) stop(paste("Chrome WebDriver initialization failed.", "\nCheck Chrome installation and internet connectivity.", "\nDetailed error:", e$message)) }) }

#' Scroll and load all recruits load_all_recruits <- function(driver) { log_info("Starting to load all recruits")

repeat { driver$executeScript("window.scrollTo(0, document.body.scrollHeight);") Sys.sleep(2)

tryCatch({
  load_more_buttons <- driver$findElements(using = 'css selector', ".primary")
  
  load_more_button <- NULL
  for (button in load_more_buttons) {
    if (grepl("Load More", button$getElementText())) {
      load_more_button <- button
      break
    }
  }
  
  if (!is.null(load_more_button)) {
    button_visible <- driver$executeScript("return arguments[0].offsetParent !== null", load_more_button)
    
    if (unlist(button_visible)) {
      log_info("Clicking Load More button")
      load_more_button$clickElement()
      Sys.sleep(3)
    } else {
      log_info("No more content to load")
      break
    }
  } else {
    log_info("Load More button not found - reached end of list")
    break
  }
  
}, error = function(e) {
  log_warn(paste("Error with Load More button:", e$message))
  break
})

} }

#' Parse player data from HTML parse_player_data <- function(player_elements) { player_text <- sapply(player_elements, function(x) x$getElementText()) player_html <- sapply(player_elements, function(x) x$getElementAttribute("outerHTML"))

df <- data.frame(raw_text = unlist(player_text, use.names = FALSE))

df <- df %>% separate(raw_text, into = c("name_school", "location", "details"), sep = "\n[(]|[)]\s*\n", extra = "merge") %>% separate(name_school, into = c("name", "school"), sep = "\n", fill = "right") %>% separate(location, into = c("city", "state"), sep = ",\s*", fill = "right") %>% separate(details, into = c("position", "height_weight", "composite_rtg", "nat_rk", "pos_rk", "st_rk", "interest"), sep = "\n", fill = "right") %>% mutate(composite_rtg = as.numeric(composite_rtg), nat_rk = as.numeric(str_extract(nat_rk, "\d+")), pos_rk = as.numeric(str_extract(pos_rk, "\d+")), st_rk = as.numeric(str_extract(st_rk, "\d+")), interest = as.numeric(str_extract(interest, "\d+"))) %>% separate(height_weight, into = c("height", "weight"), sep = "/", fill = "right") %>% mutate(height = str_trim(height), weight = as.numeric(str_trim(weight))) %>% separate(height, into = c("feet", "inches"), sep = "-", fill = "right") %>% mutate(height_in = ifelse(!is.na(feet) & !is.na(inches), as.numeric(feet) * 12 + as.numeric(inches), NA)) %>% select(-feet, -inches)

df$star_count <- str_count(player_html, "yellow") df$commit_link <- str_extract(player_html, "img src="([^"]+)"") df$commit_link <- str_replace_all(df$commit_link, "img src="|"", "")

return(df) }

#' Main scraping function scrape_recruiting_data <- function(year) { log_info(paste("Starting scrape for year", year)) url <- sprintf("https://247sports.com/Season/%d-Football/Recruits/", year)

driver_info <- initialize_driver() remDr <- driver_info$driver

tryCatch({ remDr$navigate(url) Sys.sleep(2)

load_all_recruits(remDr)

player_elements <- remDr$findElements(using = 'css selector', ".results .player")

if (length(player_elements) == 0) {
  log_warn("No players found")
  return(NULL)
}

df <- parse_player_data(player_elements)
df$class <- year

log_info(paste("Successfully scraped", nrow(df), "players"))

filename <- paste0("recruiting_data_", year, "_", format(Sys.Date(), "%Y%m%d"), ".csv")
write.csv(df, filename, row.names = FALSE)
log_info(paste("Saved data to", filename))

return(df)

}, error = function(e) { log_error(paste("Error scraping data:", e$message)) return(NULL)

}, finally = { remDr$close() driver_info$server$stop() }) }

#' Scrape multiple years scrape_multiple_years <- function(years) { log_info("Starting multi-year scrape") all_recruits <- list()

for (year in years) { log_info(sprintf("Processing year %d", year)) result <- scrape_recruiting_data(year) if (!is.null(result)) { all_recruits[[length(all_recruits) + 1]] <- result } }

final_df <- bind_rows(all_recruits) log_info(sprintf("Completed scraping for %d years", length(years))) return(final_df) }

Example usage

years <- (2025) recruits_df <- scrape_multiple_years(years)

```
  1. Ran the script.

  2. Received the following error message:

ERROR [2025-02-21 19:14:10] Driver initialization failed: version requested doesnt match versions available = 105.0.5195.19,105.0.5195.52,106.0.5249.21 Error in value[3L] : Chrome WebDriver initialization failed. Check Chrome installation and internet connectivity. Detailed error: version requested doesnt match versions available = 105.0.5195.19,105.0.5195.52,106.0.5249.21 ```

Additional Information:

  • I have verified that the ~/.cache/wdman directory does not exist on my system.
  • I have tried explicitly specifying the ChromeDriver version.
  • I have checked for conflicting chromedriver executables.
  • I have confirmed that my network connectivity is stable.
  • I have confirmed that the Chrome for Testing API is responding.
  • I have tried using the major version of chrome.
  • I have tried using the full version of chrome.
  • I have verified that ChromeDriver version 133.0.6943.126 is available for download on the official Chrome for Testing availability page: https://googlechromelabs.github.io/chrome-for-testing/

Expected Behavior:

wdman should download and use the correct ChromeDriver version that matches my Chrome browser.

Actual Behavior:

wdman fails to download the correct ChromeDriver version, resulting in a version mismatch error.

Please investigate this issue. Thank you.

STS912 avatar Feb 22 '25 00:02 STS912

This was fixed quite a while ago in PR #39. I've been using the fork for quite a while and it works well. I don't know why it hasn't been merged.

To use the fork, run

remotes::install_github("ashbythorpe/wdman@chromefix")

dmurdoch avatar May 25 '25 11:05 dmurdoch