Skip to contents

Opens a Chrome with a throwaway profile on the host, lets any browser check run, and keeps it open, for read_page() and fetch() to use through their session argument. Close it with close(); a session that is not closed lives until the R session ends. Should the browser go away meanwhile – its window closed, say – the next read or download opens another, the same way, and says so.

Usage

browser_session(
  url,
  quiet = FALSE,
  wait = NULL,
  headed = "auto",
  useragent = TRUE
)

Arguments

url

A URL on the host. The browser is opened on the host's root. headed and useragent hold for the session's life, through any reopening of its browser.

quiet

Suppress progress messages.

wait

Seconds to wait for the check to pass. The default is two minutes when a window is shown, so that a person can click a box if one appears, and thirty seconds headless.

headed

How to run the browser, when one is needed: "auto", the default, tries headless Chrome first and opens a window only when the headless run does not get through, so that a window is shown only when someone may need to click; TRUE opens a window at once and FALSE never does. Without a display "auto" is headless. A host may run a second check at the file's URL, after the one at its root; headless Chrome has passed such a check with nothing clicked, but only after about two minutes, where a window shows a box that gets it through as soon as it is clicked. "auto" waits those minutes and opens a window if they pass without; TRUE skips the wait.

useragent

The user-agent string the browser announces. Headless Chrome's own calls it HeadlessChrome, and some hosts refuse it on that word alone. TRUE, the default, drops the word, so that the string says the Chrome version and platform it is and nothing it is not; NULL leaves Chrome's own string; a string is used as given. Set before the browser's first request, and what clearance() then reports.

Value

An object of class safeconduct_session. Its clearance is what clearance() would return. Errors as fetch() does.

Examples

if (FALSE) { # \dontrun{
s <- browser_session("https://results.vancouver.ca/")
r <- read_page("https://results.vancouver.ca/data/arearesults.json",
               session = s)
close(s)
} # }