Skip to content

Commit

Permalink
fix: don't try to detect the browser version (#39)
Browse files Browse the repository at this point in the history
* don't try to find the browser version

* rename find_browser_and_version.R

* remove scripts

* move tests
  • Loading branch information
ashbythorpe authored Dec 14, 2024
1 parent c79ca82 commit 2c8b914
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 267 deletions.
98 changes: 98 additions & 0 deletions R/find_browser.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Tries to find a browser that we can use
find_browser <- function() { # nolint: cyclocomp_linter
if (is_mac()) {
path <- "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"

if (file.exists(path)) {
return("chrome")
} else {
find_browser_linux()
}
} else if (is_windows()) {
find_browser_windows()
} else if (is_linux()) {
find_browser_linux()
}
}

find_browser_linux <- function() {
possible_names <- c(
"google-chrome",
"google-chrome-stable",
"chromium-browser",
"chromium",
"google-chrome-beta",
"google-chrome-unstable",
"chrome"
)

for (path in possible_names) {
path <- Sys.which(path)
if (nzchar(path)) {
return("chrome")
}
}

path <- Sys.which("firefox")

if (nzchar(path)) {
"firefox"
} else {
NULL
}
}

find_browser_windows <- function() {
path <- tryCatch(
{
path <- utils::readRegistry(
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe\\"
)
path[["(Default)"]]
},
error = function(e) {
NULL
}
)

if (!is.null(path)) {
return("chrome")
}

path <- tryCatch(
{
path <- utils::readRegistry(
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\firefox.exe\\"
)
path[["(Default)"]]
},
error = function(e) {
NULL
}
)

if (!is.null(path)) {
return("firefox")
}

batch_file <-
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\iexplore.exe\\"

path <- tryCatch(
{
path <- utils::readRegistry(
batch_file
)
path[["(Default)"]]
},
error = function(e) {
NULL
}
)

if (!is.null(path)) {
return("internet explorer")
} else {
NULL
}
}
201 changes: 0 additions & 201 deletions R/find_browser_and_version.R

This file was deleted.

41 changes: 11 additions & 30 deletions R/session.R
Original file line number Diff line number Diff line change
Expand Up @@ -260,20 +260,12 @@ selenider_session <- function(session = getOption("selenider.session"),

options <- check_options(session, options)

browser_version <- browser_and_version(
browser <- get_browser(
session,
browser = browser,
driver = driver
)

browser <- browser_version$browser

if (inherits(options, "selenium_options") &&
inherits(options$server_options, "wdman_server_options") && # nolint: indentation_linter
is.null(options$server_options$version)) {
options$server_options$version <- browser_version$version
}

driver <- get_driver(
browser = browser,
options = options,
Expand Down Expand Up @@ -475,38 +467,29 @@ check_session_dependencies <- function(session,
session
}

browser_and_version <- function(session,
browser,
driver,
call = rlang::caller_env()) {
version <- NULL
get_browser <- function(session,
browser,
driver,
call = rlang::caller_env()) {
if (session == "chromote" && is.null(driver)) {
if (!is.null(browser) && browser != "chrome") {
warn_browser_chromote(call = call)
}

browser <- "chrome"
"chrome"
} else if (is.null(browser)) {
if (is.null(driver) || is_selenium_server(driver)) {
bv <- find_browser_and_version()
browser <- find_browser()

if (is.null(bv)) {
if (is.null(browser)) {
stop_default_browser(call = call)
}

browser <- bv$browser
version <- bv$version
browser
}
} else {
if (browser != "phantomjs") {
version <- get_browser_version(browser)
}
browser
}

list(
browser = browser,
version = version
)
}

#' Deprecated functions
Expand Down Expand Up @@ -904,13 +887,11 @@ check_supplied_driver_list <- function(x, browser, options, call = rlang::caller
stop_invalid_driver(x, is_list = TRUE, call = call)
} else if (is.null(client)) {
if (is.null(browser)) {
bv <- find_browser_and_version()
browser <- find_browser()

if (is.null(bv)) {
stop_default_browser(call = call)
}

browser <- bv$browser
}

client_options <- get_client_options(options, server, call = call)
Expand Down
Loading

0 comments on commit 2c8b914

Please sign in to comment.