| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/browser.R |
| 3 |
\name{browser_dom} |
| 4 |
\alias{browser_dom} |
| 5 |
\title{Execute JavaScript on an HTML page via a headless browser and dump the DOM} |
| 6 |
\usage{ |
| 7 |
browser_dom(input, output = NULL, fragment = FALSE, browser = NULL) |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{input}{Path or URL to the HTML page.} |
| 11 |
|
| 12 |
\item{output}{An optional output file path. If not provided, the rendered |
| 13 |
HTML is returned as a character string.} |
| 14 |
|
| 15 |
\item{fragment}{Whether to return only the inner body content instead of the |
| 16 |
full HTML document.} |
| 17 |
|
| 18 |
\item{browser}{Path to the web browser. By default, the browser is found via |
| 19 |
\code{xfun:::find_browser()}. If it cannot be found, you may set the global |
| 20 |
option \code{options(xfun.browser = )} or environment variable \code{R_XFUN_BROWSER} |
| 21 |
to the path of the browser, or simply pass the path to the \code{browser} |
| 22 |
argument.} |
| 23 |
} |
| 24 |
\value{ |
| 25 |
If \code{output} is \code{NULL}, the rendered HTML as a character string; |
| 26 |
otherwise the \code{output} path (invisibly). |
| 27 |
} |
| 28 |
\description{ |
| 29 |
Load an HTML page in a headless browser (Chromium/Chrome/Edge), execute all |
| 30 |
JavaScript on it, and return (or save) the rendered DOM as HTML. |
| 31 |
} |
| 32 |
\examples{\dontshow{if (interactive()) \{} |
| 33 |
f = tempfile(fileext = '.html') |
| 34 |
writeLines(c( |
| 35 |
'<html><body><div id="out"></div>', |
| 36 |
'<script>document.getElementById("out").textContent = "hello";</script>', |
| 37 |
'</body></html>' |
| 38 |
), f) |
| 39 |
xfun::browser_dom(f) |
| 40 |
\dontshow{\}} |
| 41 |
} |