chrome_options | R Documentation |
Create browser options to pass into the capabilities
argument of
SeleniumSession$new().
chrome_options(
binary = NULL,
args = NULL,
extensions = NULL,
prefs = NULL,
...
)
firefox_options(binary = NULL, args = NULL, profile = NULL, prefs = NULL, ...)
edge_options(binary = NULL, args = NULL, extensions = NULL, prefs = NULL, ...)
binary |
Path to the browser binary. |
args |
A character vector of additional arguments to pass to the browser. |
extensions |
A character vector of paths to browser extension ( |
prefs |
A named list of preferences to set in the browser. |
... |
Additional options to pass to the browser. |
profile |
Path to a Firefox profile directory. This will be base64 encoded before being passed to the browser. |
These functions allow you to more easily translate between Selenium code in other languages (e.g. Java/Python) to R. For example, consider the following Java code, adapted from the the Selenium documentation
ChromeOptions options = new ChromeOptions(); options.setBinary("/path/to/chrome"); options.addArguments("--headless", "--disable-gpu"); options.addExtensions("/path/to/extension.crx"); options.setExperimentalOption("excludeSwitches", List.of("disable-popup-blocking"));
This can be translated to R as follows:
chrome_options( binary = "/path/to/chrome", args = c("--headless", "--disable-gpu"), extensions = "/path/to/extension.crx", excludeSwitches = list("disable-popup-blocking") )
You can combine these options with non-browser specific options simply using
c()
.
Note that Microsoft Edge options are very similar to Chrome options, since it is based on Chromium.
A list of browser options, with Chrome options under the name
goog:chromeOptions
, Firefox options under moz:firefoxOptions
, and Edge
options under ms:edgeOptions
.
For more information and examples on Chrome options, see: https://developer.chrome.com/docs/chromedriver/capabilities
For Firefox options: https://developer.mozilla.org/en-US/docs/Web/WebDriver/Capabilities/firefoxOptions
For other options that affect Firefox but are not under mox:firefoxOptions
,
see:
https://firefox-source-docs.mozilla.org/testing/geckodriver/Capabilities.html
For Edge options, see: https://learn.microsoft.com/en-us/microsoft-edge/webdriver-chromium/capabilities-edge-options#edgeoptions-object
# Basic options objects
chrome_options(
binary = "/path/to/chrome",
args = c("--headless", "--disable-gpu"),
detatch = TRUE, # An additional option described in the link above.
prefs = list(
"profile.default_content_setting_values.notifications" = 2
)
)
firefox_options(binary = "/path/to/firefox")
edge_options(binary = "/path/to/edge")
# Setting the user agent
chrome_options(args = c("--user-agent=My User Agent"))
edge_options(args = c("--user-agent=My User Agent"))
firefox_options(prefs = list(
"general.useragent.override" = "My User Agent"
))
# Using a proxy server
chrome_options(args = c("--proxy-server=HOST:PORT"))
edge_options(args = c("--proxy-server=HOST:PORT"))
PORT <- 1
firefox_options(prefs = list(
"network.proxy.type" = 1,
"network.proxy.socks" = "HOST",
"network.proxy.socks_port" = PORT,
"network.proxy.socks_remote_dns" = FALSE
))
# Combining with other options
browser_options <- chrome_options(binary = "/path/to/chrome")
c(browser_options, list(platformName = "Windows"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.