RLesur / crrri

A Chrome Remote Interface written in R
https://rlesur.github.io/crrri/
Other
157 stars 12 forks source link

Cannot open URL 'http://localhost:9222/json/new': HTTP status was '405 Method Not Allowed' #111

Open bakaburg1 opened 1 year ago

bakaburg1 commented 1 year ago

Hello,

I used to use crrri in the past and it worked well. Now I'm running a function written with it after some time and I get the following error:

cannot open URL 'http://localhost:9222/json/new': HTTP status was '405 Method Not Allowed'

My function is the following:

get_website_resources <- function(url, url_filter = ".*", type_filter = ".*",
                                  wait_for = 20,
                                  n_of_resources = NULL, interactive = FALSE) {

  # Silence CMD CHECK about non standard eval
  . <- NULL

  crrri::perform_with_chrome(function(client) {
    Fetch <- client$Fetch
    Page <- client$Page

    if (interactive) client$inspect()

    out <- new.env()

    out$results <- list()
    out$resolve_function <- NULL

    out$pr <- promises::promise(function(resolve, reject) {
      out$resolve_function <- resolve

      Fetch$enable(patterns = list(list(urlPattern = "*", requestStage = "Response"))) %...>%
        {
          Fetch$requestPaused(callback = function(params) {
            if (stringr::str_detect(params$request$url, url_filter) & stringr::str_detect(params$resourceType, type_filter)) {
              Fetch$getResponseBody(requestId = params$requestId) %...>% {
                resp <- .

                if (resp$body != "") {
                  if (resp$base64Encoded) resp$body <- jsonlite::base64_dec(resp$body) %>% rawToChar()

                  body <- list(list(
                    url = params$request$url,
                    response = resp
                  )) %>% setNames(params$requestId)

                  # str(body)

                  out$results <- append(out$results, body)

                  if (!is.null(n_of_resources) & length(out$results) >= n_of_resources) out$resolve_function(out$results)
                }
              }
            }

            Fetch$continueRequest(requestId = params$requestId)
          })
        } %...>%
        {
          Page$navigate(url)
        } %>%
        crrri::wait(wait_for) %>%
        crrri::then(~ out$resolve_function(out$results))
    })

    out$pr$then(function(x) x)
  }, timeouts = max(wait_for + 3, 30), cleaning_timeout = max(wait_for + 3, 30))
}

it is run like this:

get_website_resources(
      url = "https://ieeexplore.ieee.org/search/searchresult.jsp?queryText=Adversarial%20machine%20learning&rowsPerPage=100&ranges=2020_2020_Year",
      url_filter = "rest/search",
      type_filter = "XHR", wait_for = 20
    )

I used it the last time successfully a couple of years ago

lisovyk commented 1 year ago

Running into the same issue :(

staropram commented 1 year ago

if you try and manually browse to http://localhost:9222/json/new on chrome it says:

"Using unsafe HTTP verb GET to invoke /json/new. This action supports only PUT verb."

So I guess the chrome API has changed?

If you look at the backtrace:

    ▆
 1. └─chrome$connect()
 2.   └─self$connectToNewTab(callback = callback)
 3.     └─crrri::new_tab(...)
 4.       └─crrri:::fetch_json(host, port, secure, "new", url)

fetch_json calls jsonlite::fromJSON which itself gets the URL using base::url which does a GET and not a PUT. So if this is the issue it is a bit cumbersome to change.

I did have a play and create a crrri:::fetch_json_PUT and modified jsonlite to have a fromJSON_PUT and it did then get past that error. Everything then worked but clearly this isn't a good long-term solution. A solution would be to not use fromJSON if a put is needed.

springhuasheng commented 1 year ago

我在使用 java cdp4j 时使用 Session.create()也遇到了这个问题 : (

springhuasheng commented 1 year ago

我在使用 java cdp4j 时使用 Session.create()也遇到了这个问题 : ( 有时候没问题, 有时候有问题