Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in startup(): ! Chrome debugging port not open after 10 seconds. #124

Open
stla opened this issue Aug 17, 2023 · 22 comments
Open

Error in startup(): ! Chrome debugging port not open after 10 seconds. #124

stla opened this issue Aug 17, 2023 · 22 comments

Comments

@stla
Copy link
Contributor

stla commented Aug 17, 2023

Hello,

My package giacR starts with this code:

library(chromote)

chrm <- Chrome$new(
  path = find_chrome(),
  args = "--disable-gpu --headless --remote-debugging-port=9222"
)
chromote <- Chromote$new(browser = chrm)
session  <- ChromoteSession$new(parent = chromote)

I have not tried it today but yesterday it worked fine. However, when I run this code today:

chrm <- Chrome$new(
  path = find_chrome(),
  args = "--disable-gpu --headless --remote-debugging-port=9222"
)

then I get the error message

Error in startup(): 
! Chrome debugging port not open after 10 seconds.

Today I set a value to the environment variables HTTP_PROXY and HTTPS_PROXY. Could it be related? My laptop has also been updated (I don't know what have been updated).

@stla
Copy link
Contributor Author

stla commented Aug 17, 2023

Yeah. I confirm this is due to HTTP_PROXY and NO_PROXY. I removed these two variables and it works now. What does that mean?

@stla
Copy link
Contributor Author

stla commented Aug 17, 2023

I found a solution. In my onLoad function, I add:

.onLoad <- function(libname, pkgname) {

  Sys.unsetenv("HTTP_PROXY")

  ........

This works. In this way the HTTP_PROXY variable does not cause any problem.

Now I'm wondering: should I restore this variable at the end of the session? And how?

@alex-silverman
Copy link

I'm experiencing this same issue. I have not set HTTP_PROXY or NO_PROXY, and I used Sys.unsetenv() to be sure.

The original package I use that calls Chromote was shinytest2. It was working this morning. But now I'm just directly calling:

library(chromote)
b <- ChromoteSession$new()

And I get the error:

Error in `startup()`:
! Chrome debugging port not open after 10 seconds.

I definitely have Chrome (v118.0.5993.71), which I can launch from an R terminal (system2('cmd', args = '/c start chrome https://www.google.com'), and I'm running on Windows 10 (OS=20348.1970, version=21H2).

@dmurdoch
Copy link

Does chromote use chromedriver, like webshot2 does? This sounds like problems updating chromedriver to a version compatible with chrome v118.0.5993.71, which was quite recently released. See ropensci/wdman#34.

@alex-silverman
Copy link

alex-silverman commented Oct 17, 2023

I'm not sure if it does (though GPT says it interacts directly with a Chromium-based browser through Chrome DevTools Protocol), but this definitely coincides roughly with the timing of the Chrome update. I installed the beta version of chromedriver (https://googlechromelabs.github.io/chrome-for-testing/#beta) and updated my Windows system PATH to point to it, but I'm still getting the same error. My PATH wasn't pointing to Chromedriver before, either. So maybe chromote uses something else?

I also tried changing the browser to Edge, which is Chromium-based, following the steps here: https://cran.r-project.org/web/packages/chromote/readme/README.html#specifying-which-browser-to-use

  1. Sys.setenv(CHROMOTE_CHROME="C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\new_msedge.exe")
  2. m <- Chromote$new( browser=Chrome$new(path="C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\new_msedge.exe") )

@stla
Copy link
Contributor Author

stla commented Oct 17, 2023

I think there's a timeout option for Chromote$new, did you try it? 10 seconds is the default value I think.

And did you try the args option?

      chrm <- Chrome$new(
        path = chromePath, # you can use 'find_chrome()'
        args = "--disable-gpu --headless --remote-debugging-port=9222"
      )
      chromote <- Chromote$new(browser = chrm)

@alex-silverman
Copy link

I couldn't figure out how to change the default_timeout parameter. I tried your code, but it resulted in the same error after this:

chrm <- Chrome$new(
    path = find_chrome(),
    args = "--disable-gpu --headless --remote-debugging-port=9222"
)

As a reminder, the error is:

Error in `startup()`:
! Chrome debugging port not open after 10 seconds.

I do have a clue: I've been developing and (recently) shinytest2-ing the app in VS Code. However, I'm not encountering the error in R Studio Server. Not sure what to make of that.

@gadenbuie
Copy link
Member

Try setting options(chromote.timeout = 60) to timeout after 60, rather than 10, seconds.

@alex-silverman
Copy link

That successfully upped the time, but it still didn't work:

Error in `startup()`:
! Chrome debugging port not open after 60 seconds.

@stla

This comment was marked as off-topic.

@stla

This comment was marked as outdated.

@alex-silverman
Copy link

alex-silverman commented Oct 18, 2023

In case it's helpful, here's the backtrace:

Backtrace:
     ▆
  1. └─ChromoteSession$new()
  2.   └─chromote (local) initialize(...)
  3.     └─chromote::default_chromote_object()
  4.       ├─chromote::set_default_chromote_object(Chromote$new())
  5.       └─Chromote$new()
  6.         └─chromote (local) initialize(...)
  7.           └─Chrome$new()
  8.             └─chromote (local) initialize(...)
  9.               └─chromote:::launch_chrome(path, args)
 10.                 └─chromote:::with_random_port(...)
 11.                   ├─base::tryCatch(...)
 12.                   │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
 13.                   │   └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
 14.                   │     └─base (local) doTryCatch(return(expr), name, parentenv, handler)
 15.                   └─chromote (local) startup(port = port, ...)

And here's the specific line that fails:

res <- startup(port = port, ...)

Similar to this StackOverflow post, it's working on RStudio Server, but not VS Code or RStudio app, on my VPN.

@gadenbuie
Copy link
Member

gadenbuie commented Oct 18, 2023

Does chromote use chromedriver, like webshot2 does? This sounds like problems updating chromedriver to a version compatible with chrome v118.0.5993.71, which was quite recently released. See ropensci/wdman#34.

@dmurdoch I don't think chromote (nor webshot2) use chromedriver. webshot2 uses chromote and AFAIK chromote creates its interface from the protocol spec returned from the running Chrome instance that it tries to connect to.

Similar to this StackOverflow post, it's working on RStudio Server, but not VS Code or RStudio app, on my VPN.

@alex-silverman Can you try looking at the error output of the chrome process on your server? You can use code like the following, I've included the results I see when running chrome locally on my Mac.

library(chromote)

chrm <- Chrome$new(
  path = find_chrome(),
  args = "--disable-gpu --headless"
)

chrm$get_path()
#> [1] "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
chrm$get_port()
#> [1] 7676
readLines(chrm$get_process()$get_error_file())
#> [1] ""
#> [2] "DevTools listening on ws://127.0.0.1:7676/devtools/browser/0b0b64c4-039f-4375-9e74-a11a80e0fd29"

@dmurdoch
Copy link

@gadenbuie: Sorry for the noise. I guess it's Rselenium that uses chromedriver.

@alex-silverman
Copy link

alex-silverman commented Oct 18, 2023

@gadenbuie - I get the same error/failure on this line:

chrm <- Chrome$new(
  path = find_chrome(),
  args = "--disable-gpu --headless"
)

So I can't even run get_path() or get_port(), etc.

@gadenbuie
Copy link
Member

gadenbuie commented Oct 18, 2023

@alex-silverman shoot, sorry, in retrospect it makes sense you wouldn't make it that far. I'm trying to figure out how we can get more logging details out of Chrome. We might not get much, but the error file I read above lives in your R session temp directory. You could try looking at the contents of the log files created in the process of launching (or trying to launch) chrome:

dir(tempdir(), pattern = "chrome-")

Is there anything helpful in there?

@alex-silverman
Copy link

woah, I think you might have found the answer! Looks like my admins are blocking it:

DevTools remote debugging is disallowed by the system admin.
[1018/131325.610:ERROR:dns_config_service.cc(273)] DNS config watch failed.

Let me check with them to confirm.

@leeroyaus
Copy link

Is a solution that retains HTTP_PROXY possible? After debugging, it seems running this function is what causes the error

> url(paste0("http://127.0.0.1:", port, "/json/protocol"), "rb")
Error in url(paste0("http://127.0.0.1:", port, "/json/protocol"), "rb") : 
  cannot open the connection to 'http://127.0.0.1:12007/json/protocol'
In addition: Warning message:
In url(paste0("http://127.0.0.1:", port, "/json/protocol"), "rb") :
  cannot open URL 'http://127.0.0.1:12007/json/protocol': HTTP status was '504 Gateway Timeout'

I've checked with our system admins and they have allowed debugging. If I enter the ip address above in Chrome it also seems to work fine

@s-elsheikh
Copy link

Hi,
I am writing here because I noticed that the error occurs depending on linux distro.
I am webscraping on a proxmox container. Everythig works in containers built using 22.04
Same container built on 24.04 gives the error.

after running:

chrm <- Chrome$new(
  path = find_chrome(),
  args = "--disable-gpu --headless"
)

# or
ChromoteSession$new()

I get the timeout error:

Error in startup():
! Chrome debugging port not open after 10 seconds.

trying: dir(tempdir(), pattern = "chrome-", full.names=TRUE)

content of tempfile:
Old Headless mode will be removed from the Chrome binary soon. Please use the new Headless mode (https://developer.chrome.com/docs/chromium/new-headless) or the chrome-headless-shell which is a standalone implementation of the old Headless mode (https://developer.chrome.com/blog/chrome-headless-shell).

[1014/171004.068642:ERROR:socket_posix.cc(93)] CreatePlatformSocket() failed: Permission denied (13)
[1014/171004.068823:ERROR:socket_posix.cc(93)] CreatePlatformSocket() failed: Permission denied (13)
[1014/171004.068845:ERROR:devtools_http_handler.cc(319)] Cannot start http server for devtools.
[1014/171004.138276:WARNING:sandbox_linux.cc(430)] InitializeSandbox() called with multiple threads in process gpu-process.
[1014/171004.139261:WARNING:viz_main_impl.cc(85)] VizNullHypothesis is disabled (not a warning)

I guess chromote is not using new headless mode?
Why is the error only in ubuntu 24.04?
Please let me know if I should provide more info.

Thanks
Samer

@gadenbuie
Copy link
Member

@s-elsheikh These are the most important lines, which indicate that there's some kind of permissions issue. It's very unlikely that it's related to chromote using the legacy headless mode.

[1014/171004.068642:ERROR:socket_posix.cc(93)] CreatePlatformSocket() failed: Permission denied (13)
[1014/171004.068823:ERROR:socket_posix.cc(93)] CreatePlatformSocket() failed: Permission denied (13)
[1014/171004.138276:WARNING:sandbox_linux.cc(430)] InitializeSandbox() called with multiple threads in process gpu-process.
[1014/171004.139261:WARNING:viz_main_impl.cc(85)] VizNullHypothesis is disabled (not a warning)

The issue is probably with Chrome and Ubuntu 24.04 or your specific environment. You can try setting the chromote.launch.echo_cmd option to TRUE so that chromote will echo the command used to launch Chrome, at which point you can use the command to run Chrome in headless mode without chromote's involvment to debug.

library(chromote)
options(chromote.launch.echo_cmd = TRUE)

b <- ChromoteSession$new()
#> Running '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' \
#>   '--headless=old' '--remote-debugging-port=33697' \
#>   '--remote-allow-origins=http://127.0.0.1:33697' \
#>   '--force-color-profile=srgb' --disable-extensions --mute-audio

@fontikar
Copy link

Hi {chromote}maintainers! 👋

I'm new to the {chromote} and found myself here through using {webshot2} in my Quarto book. Pls let me know if you think this comment should be in a different repo! 😊

I'm currently struggling to render my book using Github Actions due to this same error message as OP.

I've had a crack at increasing the time out in the workflow file following @gadenbuie suggestion but I don't think its working because {chromote} is being called by quarto in a different session.

What is interesting is that was passing at one brief moment, however reverting back to that commit seems to now fail Github Actions.

Very hard to write a reprex for this context since its on CI but here is my best attempt. Book renders fine locally.

usethis:: create_from_github("invertau/inverthotspot")

renv::restore()

quarto::quarto_render()
quarto::quarto_preview()

Would really appreciate some advice and tips!

@fontikar
Copy link

Hi {chromote}maintainers! 👋

I'm new to the {chromote} and found myself here through using {webshot2} in my Quarto book. Pls let me know if you think this comment should be in a different repo! 😊

I'm currently struggling to render my book using Github Actions due to this same error message as OP.

I've had a crack at increasing the time out in the workflow file following @gadenbuie suggestion but I don't think its working because {chromote} is being called by quarto in a different session.

What is interesting is that was passing at one brief moment, however reverting back to that commit seems to now fail Github Actions.

Very hard to write a reprex for this context since its on CI but here is my best attempt. Book renders fine locally.

usethis:: create_from_github("invertau/inverthotspot")

renv::restore()

quarto::quarto_render()
quarto::quarto_preview()

Would really appreciate some advice and tips!

Folks, I've managed to bypass Github Actions by freezing my Quarto computations! Free free to mark my above comment as off topic! Thank you again :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants