-
Notifications
You must be signed in to change notification settings - Fork 12
/
perform_with_chrome.Rd
99 lines (85 loc) · 3.04 KB
/
perform_with_chrome.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/Chrome.R
\name{perform_with_chrome}
\alias{perform_with_chrome}
\title{Execute an asynchronous CDP flow with Chrome}
\usage{
perform_with_chrome(
...,
.list = NULL,
timeouts = 30,
cleaning_timeout = 30,
async = FALSE,
bin = NULL,
debug_port = 9222L,
local = FALSE,
extra_args = NULL,
headless = TRUE,
retry_delay = 0.2,
max_attempts = 15L
)
}
\arguments{
\item{...}{Asynchronous remote flow functions.}
\item{.list}{A list of asynchronous remote flow functions - an alternative to
\code{...}.}
\item{timeouts}{A vector of timeouts applied to each asynchronous function.
Repeated.}
\item{cleaning_timeout}{The delay for cleaning Chrome.}
\item{async}{Is the result a promise? Required for using \code{perform_with_chrome()}
in Shiny.}
\item{bin}{Character scalar, the path to Chromium or Chrome executable.
If not provided, \code{crrri} will try to find the chrome binary itself using
\code{find_chrome_binary()}. You can set a path in \code{HEADLESS_CHROME} environment
variable to indicate where it is located.}
\item{debug_port}{Integer scalar, the Chromium/Chrome remote debugging port.}
\item{local}{Logical scalar, indicating whether the local version of the
protocol (embedded in \code{crrri}) must be used or the protocol must be
fetched \emph{remotely}.}
\item{extra_args}{Character vector, extra command line arguments passed to
Chromium/Chrome. You can know more about command line flags (or switches)
from \href{https://www.chromium.org/developers/how-tos/run-chromium-with-flags}{chromium developers}}
\item{headless}{Logical scalar, indicating whether Chromium/Chrome is launched
in headless mode.}
\item{retry_delay}{Number, delay in seconds between two successive tries to
connect to headless Chromium/Chrome.}
\item{max_attempts}{Logical scalar, number of tries to connect to headless
Chromium/Chrome.}
}
\value{
An invisible list with the values of the fulfilled promises for each
async function.d If there is only async function, the return value is the value of the
fulfilled promise.
}
\description{
The \code{perform_with_chrome()} function executes an asynchronous Chrome DevTools
Protocol flow with Chromium/Chrome and can turn it into a synchronous function.
An asynchronous remote flow is a function that takes a connection object and
returns a \link[promises:promise]{promise}.
If several functions are passed to \code{perform_with_chrome()}, their execution is
serial. If one of the asynchronous functions fails, the whole execution also
fails.
}
\examples{
\dontrun{
async_save_as_pdf <- function(url) {
function(client) {
Page <- client$Page
Page$enable() \%...>\% {
Page$navigate(url = url)
Page$loadEventFired()
} \%...>\% {
Page$printToPDF()
} \%...>\% {
write_base64(., paste0(httr::parse_url(url)$hostname, ".pdf"))
}
}
}
save_as_pdf <- function(...) {
list(...) \%>\%
purrr::map(async_save_as_pdf) \%>\%
perform_with_chrome(.list = .)
}
save_as_pdf("https://www.r-project.org/", "https://rstudio.com/")
}
}