Skip to content

Instantly share code, notes, and snippets.

@jjesusfilho
Last active January 26, 2024 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjesusfilho/241dd3e13068f36c4d82396d5fe4a7c3 to your computer and use it in GitHub Desktop.
Save jjesusfilho/241dd3e13068f36c4d82396d5fe4a7c3 to your computer and use it in GitHub Desktop.
Compatibiliza o chromdriver com o google chrome
#' Baixa e atualiza versão do chromedriver com a versão do chrome.
#'
#' @return OK!
#' @export
#'
compatibilizar_chromever <- function(){
driver <- binman::list_versions("chromedriver") |>
unlist() |>
utils::tail(1) |>
unname()
chrome <- system("google-chrome --version", intern = T) |>
stringr::str_extract("\\d.+") |>
stringr::str_trim()
v1 <- chrome |>
stringr::str_extract("\\d+") |>
as.numeric()
v2 <- driver |>
stringr::str_extract("\\d+") |>
as.numeric()
if (v1 > v2) {
u <- "https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json"
udrive <- jsonlite::fromJSON(u) |>
purrr::pluck("versions") |>
dplyr::filter(version == chrome) |>
purrr::pluck("downloads","chromedriver", 1) |>
dplyr::filter(platform == "linux64") |>
dplyr::pull("url")
arquivo <- binman::app_dir("chromedriver") |>
paste0("/linux64/", chrome,".zip")
utils::download.file(udrive, arquivo)
lista <- utils::unzip(arquivo, list = T)
nd <- file.path(dirname(arquivo), chrome)
path <- utils::unzip(arquivo, exdir = dirname(arquivo)) |>
purrr::pluck(1) |>
dirname()
file.rename(path, nd)
file.remove(arquivo)
}
return("Ok!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment