Skip to contents

Opens a Chrome with a throwaway profile on the host's root, lets any check run, and keeps it open for read_page() and fetch() through their session argument. Close it with close(); otherwise it lives until the R session ends. A browser that has gone away, its window closed, is reopened the same way at the next call, which says so.

Usage

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

Arguments

url

A URL on the host. headed and useragent hold for the session's life.

quiet

Suppress progress messages.

wait

Seconds to wait for the check to pass: by default two minutes with a window, so that a person can click, and thirty seconds headless.

headed

How to run the browser when one is needed. "auto", the default, runs headless and opens a window only when the headless run ends on a check or a block and there is a display to show it on; TRUE opens a window at once; FALSE never does. A second check, at the file's URL, takes headless Chrome about two minutes to pass unclicked, where a window is through as soon as its box is clicked: "auto" waits those minutes before opening a window, TRUE skips the wait.

useragent

The browser's user-agent string. TRUE, the default, drops the word Headless from Chrome's own string, which some hosts refuse on that word alone, and changes nothing else; NULL leaves Chrome's own; a string is used as given.

Value

A safeconduct_session, whose clearance is what clearance() would return. Errors as fetch()'s.

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)
} # }