diff --git a/NAMESPACE b/NAMESPACE
index bac57c0..5fedde7 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -41,7 +41,9 @@ export(render_json)
export(render_png)
export(splash)
export(splash_active)
+export(splash_click)
export(splash_debug)
+export(splash_focus)
export(splash_go)
export(splash_har)
export(splash_history)
@@ -51,7 +53,11 @@ export(splash_local)
export(splash_perf_stats)
export(splash_plugins)
export(splash_png)
+export(splash_press)
+export(splash_release)
export(splash_response_body)
+export(splash_send_keys)
+export(splash_send_text)
export(splash_user_agent)
export(splash_version)
export(splash_wait)
diff --git a/R/dsl.r b/R/dsl.r
index b107c35..12c9f51 100644
--- a/R/dsl.r
+++ b/R/dsl.r
@@ -99,6 +99,88 @@ splash_go <- function(splash_obj, url) {
splash_obj
}
+#' Trigger mouse click event in web page.
+#'
+#' @param splash_obj splashr object
+#' @param x,y coordinates (distances from the left or top, relative to the current viewport)
+#' @export
+splash_click <- function(splash_obj, x, y) {
+ splash_obj$calls <- c(splash_obj$calls,
+ sprintf("splash:mouse_click(%s, %s)", x, y))
+ splash_obj
+}
+
+#' Focus on a document element provided by a CSS selector
+#'
+#' @md
+#' @param splash_obj splashr object
+#' @param selector valid CSS selector
+#' @references See [the docs](https://splash.readthedocs.io/en/stable/scripting-ref.html#splash-send-text) for more info
+#' @export
+splash_focus <- function(splash_obj, selector) {
+ splash_obj$calls <- c(splash_obj$calls,
+ sprintf('splash:select("%s").node:focus()', selector))
+ splash_obj
+}
+
+#' Send text as input to page context, literally, character by character.
+#'
+#' This is different from [splash_send_keys]
+#'
+#' @md
+#' @note This adds a call to `splash:wait` so you do not have to
+#' @param splash_obj splashr object
+#' @param text string to send
+#' @references See [the docs](https://splash.readthedocs.io/en/stable/scripting-ref.html#splash-send-keys) for more info
+#' @export
+splash_send_text <- function(splash_obj, text) {
+ splash_obj$calls <- c(splash_obj$calls,
+ sprintf('splash:send_text("%s")', text),
+ "splash:wait(0.1)")
+ splash_obj
+}
+
+#' Send keyboard events to page context.
+#'
+#' - whitespace is ignored and only used to separate the different keys
+#' - characters are literally represented
+#'
+#' This is different from [splash_send_text]
+#'
+#' @md
+#' @param splash_obj splashr object
+#' @param keys string to send
+#' @references See [the docs](https://splash.readthedocs.io/en/stable/scripting-ref.html#splash-send-keys) for more info
+#' @export
+splash_send_keys <- function(splash_obj, keys) {
+ splash_obj$calls <- c(splash_obj$calls,
+ sprintf('splash:send_keys("%s")', keys),
+ "splash:wait(0.1)")
+ splash_obj
+}
+
+#' Trigger mouse release event in web page.
+#'
+#' @param splash_obj splashr object
+#' @param x,y coordinates (distances from the left or top, relative to the current viewport)
+#' @export
+splash_release <- function(splash_obj, x, y) {
+ splash_obj$calls <- c(splash_obj$calls,
+ sprintf("splash:mouse_release(%s, %s)", x, y))
+ splash_obj
+}
+
+#' Trigger mouse press event in web page.
+#'
+#' @param splash_obj splashr object
+#' @param x,y coordinates (distances from the left or top, relative to the current viewport)
+#' @export
+splash_press <- function(splash_obj, x, y) {
+ splash_obj$calls <- c(splash_obj$calls,
+ sprintf("splash:mouse_press(%s, %s)", x, y))
+ splash_obj
+}
+
#' Wait for a period time
#'
#' When script is waiting WebKit continues processing the webpage
diff --git a/README.Rmd b/README.Rmd
index 0f85e1d..13109af 100644
--- a/README.Rmd
+++ b/README.Rmd
@@ -60,6 +60,8 @@ The following functions are implemented:
Mini-DSL (domain-specific language). These can be used to create a "script" without actually scripting in Lua. They are a less-powerful/configurable set of calls than what you can make with a full Lua function but the idea is to have it take care of very common but simple use-cases, like waiting a period of time before capturing a HAR/HTML/PNG image of a site:
- `splash_plugins`: Enable or disable browser plugins (e.g. Flash).
+- `splash_click`: Trigger mouse click event in web page.
+- `splash_focus`: Focus on a document element provided by a CSS selector
- `splash_images`: Enable/disable images
- `splash_response_body`: Enable or disable response content tracking.
- `splash_go`: Go to an URL.
@@ -67,7 +69,11 @@ Mini-DSL (domain-specific language). These can be used to create a "script" with
- `splash_har`: Return information about Splash interaction with a website in HAR format.
- `splash_html`: Return a HTML snapshot of a current page.
- `splash_png`: Return a screenshot of a current page in PNG format.
-- `splash_user_agent: Overwrite the User-Agent header for all further requests. NOTE: There are many "helper" user agent strings to go with `splash_user_agent`. Look for objects in `splashr` starting with `ua_`.
+- `splash_press`: Trigger mouse press event in web page.
+- `splash_release`: Trigger mouse release event in web page.
+- `splash_send_keys`: Send keyboard events to page context.
+- `splash_send_text`: Send text as input to page context, literally, character by character.
+- `splash_user_agent`: Overwrite the User-Agent header for all further requests. NOTE: There are many "helper" user agent strings to go with `splash_user_agent`. Look for objects in `splashr` starting with `ua_`.
`httr` helpers. These help turn various bits of `splashr` objects into `httr`-ish things:
@@ -199,6 +205,19 @@ rawToChar(res) %>%
jsonlite::fromJSON()
```
+### Interacting With Flash sites
+
+```{r eval=FALSE}
+splash_local %>%
+ splash_go("https://gis.cdc.gov/GRASP/Fluview/FluHospRates.html") %>%
+ splash_wait(4) %>%
+ splash_click(460, 550) %>%
+ splash_wait(2) %>%
+ splash_png()
+```
+
+
+
### Rendering Widgets
```{r eval=FALSE}
diff --git a/README.md b/README.md
index 5222508..6ee055b 100644
--- a/README.md
+++ b/README.md
@@ -58,6 +58,8 @@ The following functions are implemented:
Mini-DSL (domain-specific language). These can be used to create a "script" without actually scripting in Lua. They are a less-powerful/configurable set of calls than what you can make with a full Lua function but the idea is to have it take care of very common but simple use-cases, like waiting a period of time before capturing a HAR/HTML/PNG image of a site:
- `splash_plugins`: Enable or disable browser plugins (e.g. Flash).
+- `splash_click`: Trigger mouse click event in web page.
+- `splash_focus`: Focus on a document element provided by a CSS selector
- `splash_images`: Enable/disable images
- `splash_response_body`: Enable or disable response content tracking.
- `splash_go`: Go to an URL.
@@ -65,7 +67,11 @@ Mini-DSL (domain-specific language). These can be used to create a "script" with
- `splash_har`: Return information about Splash interaction with a website in HAR format.
- `splash_html`: Return a HTML snapshot of a current page.
- `splash_png`: Return a screenshot of a current page in PNG format.
-- `splash_user_agent: Overwrite the User-Agent header for all further requests. NOTE: There are many "helper" user agent strings to go with`splash\_user\_agent`. Look for objects in`splashr`starting with`ua\_\`.
+- `splash_press`: Trigger mouse press event in web page.
+- `splash_release`: Trigger mouse release event in web page.
+- `splash_send_keys`: Send keyboard events to page context.
+- `splash_send_text`: Send text as input to page context, literally, character by character.
+- `splash_user_agent`: Overwrite the User-Agent header for all further requests. NOTE: There are many "helper" user agent strings to go with `splash_user_agent`. Look for objects in `splashr` starting with `ua_`.
`httr` helpers. These help turn various bits of `splashr` objects into `httr`-ish things:
@@ -148,13 +154,13 @@ splash_debug()
## List of 7
## $ active : list()
## $ argcache: int 0
- ## $ fds : int 14
+ ## $ fds : int 19
## $ leaks :List of 4
## ..$ Deferred : int 50
## ..$ LuaRuntime: int 1
## ..$ QTimer : int 1
## ..$ Request : int 1
- ## $ maxrss : int 68444
+ ## $ maxrss : int 170252
## $ qsize : int 0
## $ url : chr "http://localhost:8050"
## - attr(*, "class")= chr [1:2] "splash_debug" "list"
@@ -168,7 +174,7 @@ render_html(url = "http://marvel.com/universe/Captain_America_(Steve_Rogers)")
## {xml_document}
##
- ## [1]