ropensci / RSelenium

An R client for Selenium Remote WebDriver
https://docs.ropensci.org/RSelenium
344 stars 81 forks source link

Adding Profile Setting to RSelenium Firefox #289

Open Vanderser opened 6 months ago

Vanderser commented 6 months ago

I am using Windows 7, I have both chrome webdriver version 108.0.5359.71 and geckodriver with version 0.34.0, and also installed mozilla firefox browser with version 115, In this case I am trying to reach web.whatsapp.com by both chrome and firefox for comparisons.

With chrome, I actually can surf the whatsapp web (automatically bypass the qr-code), with these settings:

user_agent <- "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.5359.71 Safari/537.36"
language <- "en-US,en;q=0.5"
accept_language <- "en-US,en;q=0.9"
platform <- "Windows NT 6.1; Win64; x64"
chrome_user_data_dir <- "C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\User Data"
firefox_user_data_dir <- "C:\\Users\\User\\AppData\\Local\\Mozilla\\Firefox\\Profiles"

options <- list(
      chromeOptions = list(
        args = c(
          paste0("--user-agent=", user_info$user_agent),
          paste0("--lang=", user_info$language),
          paste0("--user-data-dir=",chrome_user_data_dir)
        )
      )
    )

rD <- rsDriver(browser="firefox", port = 4567L, chromever = NULL, verbose=F, 
               extraCapabilities = options)
remDr <- rD[["client"]]
remDr$navigate("https://web.whatsapp.com/")

However I need to access the whatsapp web using firefox since the chrome browser has known issues/limitation of videos playback element for whatsapp web, which I need to load in my project. These are my current settings for the firefox RSelenium setup:

firefox_profile_template <- list(
    browserName = "firefox",
    "moz:firefoxOptions" = list(
      prefs = list("intl.accept_languages" = language),
      args = list(paste0("--user-agent=", user_agent), paste0("--user-data-dir=", user_data_dir))
    )
  )
)

rD <- rsDriver(browser="firefox", port = 4567L, chromever = NULL, verbose=F, 
               extraCapabilities = firefox_profile_template)
remDr <- rD[["client"]]
remDr$navigate("https://web.whatsapp.com/")

And unfortunately these settings still make it stuck at whatsapp qr-code everytime the code run. I dont have any clue to solve this since its my first experience to attach user profile to firefox.

These are Note with pictures before navigate to web.whatsapp.com:

Actual Firefox Browser:

1

RSelenium firefox launch:

2