I have not tried my code, but I think that your regular expressions gsub()can be overly aggressive (which is caused by a name transition).
javascript- V8,
DOM- getDevice() getDisplay()
, V8:
library(V8)
library(rvest)
pg <- read_html('<script type="text/javascript">
var utag_data = {
environnement : "prod",
device : getDevice(),
displaytype : getDisplay($(window).innerWidth()),
pagename : "adview",
pagetype : "annonce"}</script>')
script <- html_text(html_nodes(pg, xpath='//script[@type="text/javascript"]'))
ctx <- v8()
ctx$eval(script)
:
# we need to remove the function calls and replace them with blanks
# since both begin with 'getD' this is pretty easy:
script <- gsub("getD[[:alpha:]\\(\\)\\$\\.]+,", "'',", script)
ctx$eval(script)
ctx$get("utag_data")
#
#
#
#
#
#
#
#
#
#
#
#
#
#