ropensci / RSelenium

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

How to keep the browser opening? #241

Closed yuanzhouIR closed 3 years ago

yuanzhouIR commented 3 years ago

Hi there. I'm using this package on Mac OS. It works fairly well. However, when my code finished running, Chrome automatically closed after a few minutes. I want to keep the browser opening regardless of there are operations running or not. How should I set the code to prevent the browser from closing?

taiyodayo commented 3 years ago

similar issue here: https://stackoverflow.com/questions/55438913/is-there-a-way-too-prevent-selenium-automatically-terminating-idle-sessions

untested, but something like this should work:

chrome_prefs = 
  list(  
   # chrome prefs
    "profile.default_content_settings.popups" = 0L,
    "download.prompt_for_download" = FALSE
    )

chrome_args = 
  c(
  # chrome command arguments
    '--headless',
    '--window-size=1200,1800',
    '-sessionTimeout 57868143'
    )

eCaps_notimeout = 
  list(chromeOptions = 
         list(
           prefs = chrome_prefs,
           args = chrome_args 
  ))

  remDr <- remoteDriver(
    browserName = "chrome",
    extraCapabilities = eCaps_withhead
  )
yuanzhouIR commented 3 years ago

similar issue here: https://stackoverflow.com/questions/55438913/is-there-a-way-too-prevent-selenium-automatically-terminating-idle-sessions

untested, but something like this should work:

chrome_prefs = 
  list(  
   # chrome prefs
    "profile.default_content_settings.popups" = 0L,
    "download.prompt_for_download" = FALSE
    )

chrome_args = 
  c(
  # chrome command arguments
    '--headless',
    '--window-size=1200,1800',
    '-sessionTimeout 57868143'
    )

eCaps_notimeout = 
  list(chromeOptions = 
         list(
           prefs = chrome_prefs,
           args = chrome_args 
  ))

  remDr <- remoteDriver(
    browserName = "chrome",
    extraCapabilities = eCaps_withhead
  )

Thanks for your reply! Increasing the value of sesssionTimeout works for me.