rstudio / chromote

Chrome Remote Interface for R
https://rstudio.github.io/chromote/
156 stars 20 forks source link

Allow enable() methods to be called manually #144

Open ashbythorpe opened 9 months ago

ashbythorpe commented 9 months ago

I would like to call Fetch.enable using the patterns and handleAuthRequests arguments. However, since chromote calls Fetch.enable automatically when a callback is attached to a Fetch event, the method is called twice, which causes an error. I would like not to set the auto_events field to FALSE, since I can't change this value after it has been set.

For example:

library(chromote)

session <- ChromoteSession$new()

session$Fetch$enable(
  patterns = list(
    list(urlPattern = "*")
  ),
  handleAuthRequests = TRUE
)

authenticate <- function(x) {
  id <- x$requestId

  response <- list(
    response = "ProvideCredentials",
    username = "USERNAME",
    password = "PASSWORD"
  )

  session$Fetch$continueWithAuth(
    requestId = id,
    authChallengeResponse = response
  )
}

continue_request <- function(x) {
  id <- x$requestId

  session$Fetch$continueRequest(requestId = id)
}

session$Fetch$requestPaused(
  callback_ = continue_request
)

session$Fetch$authRequired(
  callback_ = authenticate
)

session$Page$navigate("https://google.com")

The session$Page$navigate() call causes the following warning:

#> In callbacks$invoke(params) :
#>  1 errors occurred while executing callbacks:
#>  code: -32602
#>  message: Invalid InterceptionId.

It would be useful if either: