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

Problem with Chrome v128 #170

Closed
bradvf opened this issue Aug 23, 2024 · 41 comments
Closed

Problem with Chrome v128 #170

bradvf opened this issue Aug 23, 2024 · 41 comments

Comments

@bradvf
Copy link

bradvf commented Aug 23, 2024

Having errors after Chrome update to v128, for example:

When Chrome is already running on the machine, b <- ChromoteSession$new() produces the following error:

Error in with_random_port():
! Cannot find an available port. Please try again.
Caused by error in startup():
! Failed to start chrome. Error:

When Chrome is not already running b <- ChromoteSession$new() will run, but executing b$view() will not open any window. Trying to open Chrome app will also not run after creating a new session with this command.

@ValentineHerr
Copy link

I am having the same issue since today. Everything worked yesterday.

Error in with_random_port():! Cannot find an available port. Please try again.

The ports that are tried are: 33403 5029 35925 8541 2155 33826 46754 41097 42704 22106

@gadenbuie
Copy link
Member

I just updated to Chrome 128.0.6613.85 and chromote is working fine for me. That's usually a sign that there are some environment or operating system characteristic at play with your issue. Can you please include the results of devtools::session_info()?

@bradvf
Copy link
Author

bradvf commented Aug 23, 2024

 setting  value
 version  R version 4.3.0 (2023-04-21 ucrt)
 os       Windows 10 x64 (build 19045)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  English_United States.utf8
 ctype    English_United States.utf8
 tz       America/Chicago
 date     2024-08-23
 rstudio  2023.06.2+561 Mountain Hydrangea (desktop)
 pandoc   3.1.1 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)

@gadenbuie
Copy link
Member

@bradvf can you please include all of the output? If the output prints too many packages, try this devtools::session_info(pkgs = "chromote").

@bradvf
Copy link
Author

bradvf commented Aug 23, 2024

@gadenbuie

─ Session info ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.3.0 (2023-04-21 ucrt)
 os       Windows 10 x64 (build 19045)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  English_United States.utf8
 ctype    English_United States.utf8
 tz       America/Chicago
 date     2024-08-23
 rstudio  2023.06.2+561 Mountain Hydrangea (desktop)
 pandoc   3.1.1 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)

─ Packages ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 package     * version  date (UTC) lib source
 AsioHeaders   1.22.1-2 2022-12-08 [1] CRAN (R 4.3.0)
 chromote    * 0.2.0    2024-02-12 [1] CRAN (R 4.3.3)
 cpp11         0.4.3    2022-10-12 [1] CRAN (R 4.3.0)
 curl          5.0.0    2023-01-12 [1] CRAN (R 4.3.0)
 fastmap       1.1.1    2023-02-24 [1] CRAN (R 4.3.0)
 jsonlite    * 1.8.8    2023-12-04 [1] CRAN (R 4.3.2)
 later         1.3.1    2023-05-02 [1] CRAN (R 4.3.0)
 magrittr      2.0.3    2022-03-30 [1] CRAN (R 4.3.0)
 processx      3.8.2    2023-06-30 [1] CRAN (R 4.3.2)
 promises      1.2.0.1  2021-02-11 [1] CRAN (R 4.3.0)
 ps            1.7.5    2023-04-18 [1] CRAN (R 4.3.0)
 R6            2.5.1    2021-08-19 [1] CRAN (R 4.3.0)
 Rcpp          1.0.10   2023-01-22 [1] CRAN (R 4.3.0)
 rlang         1.1.1    2023-04-28 [1] CRAN (R 4.3.0)
 websocket     1.4.1    2021-08-18 [1] CRAN (R 4.3.1)

@kumarnishanthtr
Copy link

kumarnishanthtr commented Aug 24, 2024

Having the issue since yesterday after chrome update to 128

> b <- ChromoteSession$new()
Error in launch_chrome(path, args) : Failed to start chrome. Error: 

Here is the session info:

> devtools::session_info(pkgs = "chromote")
─ Session info ──────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.3.3 (2024-02-29 ucrt)
 os       Windows 11 x64 (build 22621)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  English_United States.utf8
 ctype    English_United States.utf8
 tz       Asia/Calcutta
 date     2024-08-24
 rstudio  2023.12.1+402 Ocean Storm (desktop)
 pandoc   NA

─ Packages ──────────────────────────────────────────────────────────────────────────────
 package     * version  date (UTC) lib source
 AsioHeaders   1.22.1-2 2022-12-08 [1] CRAN (R 4.3.0)
 chromote    * 0.1.1    2022-09-07 [1] CRAN (R 4.3.1)
 cpp11         0.4.3    2022-10-12 [1] CRAN (R 4.3.1)
 curl          5.0.1    2023-06-07 [1] CRAN (R 4.3.1)
 fastmap       1.1.1    2023-02-24 [1] CRAN (R 4.3.1)
 jsonlite      1.8.5    2023-06-05 [1] CRAN (R 4.3.1)
 later         1.3.1    2023-05-02 [1] CRAN (R 4.3.1)
 magrittr      2.0.3    2022-03-30 [1] CRAN (R 4.3.1)
 processx      3.8.1    2023-04-18 [1] CRAN (R 4.3.1)
 promises      1.2.0.1  2021-02-11 [1] CRAN (R 4.3.1)
 ps            1.7.5    2023-04-18 [1] CRAN (R 4.3.1)
 R6            2.5.1    2021-08-19 [1] CRAN (R 4.3.1)
 Rcpp          1.0.10   2023-01-22 [1] CRAN (R 4.3.1)
 rlang         1.1.1    2023-04-28 [1] CRAN (R 4.3.1)
 websocket     1.4.1    2021-08-18 [1] CRAN (R 4.3.1)

@gadenbuie
Copy link
Member

gadenbuie commented Aug 24, 2024

Can you please try with the latest development version of chromote? At the very least it might surface more context about the error.

remotes::install_github("rstudio/chromote")

@shafiul0304034
Copy link

Very stressful situation since yesterday. Today me with my little team spent whole day to fix this issue but unable. We found out, the port number returned after execution with_random_port() function is always null. I expect a help from a guru to find out where is the problem. Our hosted product in shinyapps.io for hotels room price analysis seems still working. However, problem is coming from desktop trial.

Cheers
Shafiul Islam || Founder of SaleForecast

remotes::install_github("rstudio/chromote")
Downloading GitHub repo rstudio/chromote@HEAD
Running R CMD build...

  • checking for file 'C:\Users\USER\AppData\Local\Temp\Rtmpe0PPHK\remotes114876f2531a\rstudio-chromote-f030285/DESCRIPTION' ... OK
  • preparing 'chromote':
  • checking DESCRIPTION meta-information ... OK
  • checking for LF line-endings in source and make files and shell scripts
  • checking for empty or unneeded directories
  • building 'chromote_0.2.0.9000.tar.gz'
    Installing package into ‘C:/Users/USER/AppData/Local/R/win-library/4.4’
    (as ‘lib’ is unspecified)
  • installing source package 'chromote' ...
    ** using staged installation
    ** R
    ** byte-compile and prepare package for lazy loading
    ** help
    *** installing help indices
    *** copying figures
    ** building package indices
    ** testing if installed package can be loaded from temporary location
    ** testing if installed package can be loaded from final location
    ** testing if installed package keeps a record of temporary installation path
  • DONE (chromote)

library(chromote)
find_chrome()
[1] "C:\Program Files\Google\Chrome\Application\chrome.exe"
ChromoteSession$new()
Error in with_random_port():
! Cannot find an available port. Please try again.
Caused by error in startup():
! Failed to start chrome. (No error messages were printed.)
Run rlang::last_trace() to see where the error occurred.

@bradvf
Copy link
Author

bradvf commented Aug 24, 2024

@gadenbuie same error with the development version: Cannot find an available port. Please try again. Also tried updating all dependent packages.

@Migchw
Copy link

Migchw commented Aug 25, 2024

Having the same issue here

Error in with_random_port():
! Cannot find an available port. Please try again.
Caused by error in startup():
! Failed to start chrome. Error:

@bradvf
Copy link
Author

bradvf commented Aug 25, 2024

For anyone struggling with this, a temporary solution was to download Chrome For Testing version 127 (https://storage.googleapis.com/chrome-for-testing-public/127.0.6533.120/win64/chrome-win64.zip). You can then point chromote to that browser via:

chrome_path <- "C:\\chrome-win64\\chrome.exe"
m <- Chromote$new(browser = Chrome$new(path = chrome_path))
b <- m$new_session()

@gadenbuie
Copy link
Member

gadenbuie commented Aug 26, 2024

I was able to reproduce the issue with Chrome v128 in Windows 11 via Parallels. Immediately after installing the updated Chrome version, the following would fail as described above:

library(chromote)
b <- ChromoteSession$new()
#> Error in `with_random_port()`:
#> ! Cannot find an available port. Please try again.
#> Caused by error in `startup()`:
#> ! Failed to start chrome. Error:
#> Run `rlang::last_trace()` to see where the error occurred.

The lack of error message is a result of the Chrome process exiting almost immediately, or before chromote has a chance to do anything with the process.

Running the following in a command prompt was exiting immediately without starting a Chrome process:

"C:\Program Files\Google\Chrome\Application\chrome.exe" --headless --remote-debugging-port=9876 --remote-allow-origins=http://127.0.0.1:9876

As I understand it, Chrome is in the process of transitioning from --headless=old to --headless=new (described here):

Note: Passing the --headless command-line flag without an explicit value still activates the old Headless mode, but we intend to change this default. We intend to remove the old Headless from the Chrome binary and stop supporting this mode in Puppeteer in 2024.

I couldn't find anything mentioning a change to the --headless flag in Chrome's v128 release notes.

That said, when I changed --headless to --headless=new in the command prompt, headless chrome began working as expected. After running starting headless Chrome once with --headless=new, changing back to --headless started working again, too. At this point, starting a new Chrome session with chromote via b <- ChromoteSession$new() also started working as expected.

Can anyone in this thread try my process to see if it works for you? Use find_chrome() to find the path to Chrome on your machine

chromote::find_chrome()
#> [1] "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"

and then, in a command or power shell prompt, run the executable once with the --headless=new flag.

"C:\Program Files\Google\Chrome\Application\chrome.exe" --headless=new --remote-debugging-port=9876 --remote-allow-origins=http://127.0.0.1:9876

I included the --remote-... flags so that the process will print out a line like

DevTools listening on ws://127.0.0.1:9876/devtools/browser/d5ba3a11-3293-4482-a7ac-7e518acd2d5f

After that, you can stop the process by pressing Ctrl + C and then try using chromote in R to start a new session with

b <- ChromoteSession$new()

@bradvf
Copy link
Author

bradvf commented Aug 26, 2024

@gadenbuie I found that I can only run your command line when Chrome is closed. When Chrome is already open, the command fails immediately. However, I still receive the same errors in R after successfully running the command line.

@gadenbuie
Copy link
Member

@bradvf Does headless Chrome work correctly when called from the command line? Try running this command, it should output the HTML of https://example.com.

"C:\Program Files\Google\Chrome\Application\chrome.exe" --headless --dump-dom https://example.com
# <html><head>
#    <title>Example Domain</title>
# [...snip...]
# </body></html>

@gadenbuie
Copy link
Member

gadenbuie commented Aug 26, 2024

When Chrome is already open, the command fails immediately. However, I still receive the same errors in R after successfully running the command line.

@bradvf Do you receive the same errors when Chrome is open or closed? You might need to use Task Manager to verify that there aren't any running Chrome processes.

@bradvf
Copy link
Author

bradvf commented Aug 26, 2024

@bradvf Does headless Chrome work correctly when called from the command line? Try running this command, it should output the HTML of https://example.com.

"C:\Program Files\Google\Chrome\Application\chrome.exe" --headless --dump-dom https://example.com
# <html><head>
#    <title>Example Domain</title>
# [...snip...]
# </body></html>

When Chrome is closed, this will work. When Chrome is open, this produces no output. Guessing this is a problem directly with Chrome that chromote won't be able to get around.

@gadenbuie
Copy link
Member

oh! So the cause might be having or not having Chrome open, rather than the commands I was using. I stopped all chrome processes while testing --headless=new vs --headless so that I could correctly count the number of processes. But now I can reproduce the issue by opening and closing Chrome.

@gadenbuie
Copy link
Member

When Chrome is closed, this will work. When Chrome is open, this produces no output. Guessing this is a problem directly with Chrome that chromote won't be able to get around.

That's right, this is certainly a Chrome-specific issue, especially since we can reproduce the error without using chromote at all. That's a good start! I'm surprised this hasn't been reported in other chrome-automation packages, though. 🤔

@gadenbuie
Copy link
Member

Also related: once I start a Chrome session via chromote, I can't then start a normal headful instance of Chrome until I completely shut down the R session.

@gadenbuie
Copy link
Member

Same behavior for Chrome Beta (129.0.6668.12 (arm64))

@gadenbuie
Copy link
Member

This has been reported in the Chromium bug tracker in at least two places, we'll have to wait for an upstream fix.

@shafiul0304034
Copy link

"C:\Program Files\Google\Chrome\Application\chrome.exe" --headless --remote-debugging-port=9876 --remote-allow-origins=http://127.0.0.1:9876

I have tried with this approach. However, it provides same error.
Error in with_random_port():

@shafiul0304034
Copy link

For anyone struggling with this, a temporary solution was to download Chrome For Testing version 127 (https://storage.googleapis.com/chrome-for-testing-public/127.0.6533.120/win64/chrome-win64.zip). You can then point chromote to that browser via:

chrome_path <- "C:\\chrome-win64\\chrome.exe"
m <- Chromote$new(browser = Chrome$new(path = chrome_path))
b <- m$new_session()

Many thanks Bro. At least I have something now to work with.

@daviewales
Copy link

Chromium is a snap on Ubuntu.
Some commands to get you back to a working version:

https://snapcraft.io/docs/quickstart-tour#pause-or-stop-automatic-updates
https://snapcraft.io/docs/quickstart-tour#revert-to-an-earlier-revision

@cderv
Copy link
Contributor

cderv commented Aug 28, 2024

@gadenbuie
Copy link
Member

gadenbuie commented Aug 29, 2024

The latest version of chromote v0.3.0 (now on CRAN!) uses --headless=old by default:

If you're encountering the problem in this thread, please use the latest version of chromote:

install.packages("chromote")

--headless=new will end up being the default eventually, so please consider testing it in the future. You can use options(chromote.headless = "new") to try the new headless mode.

@gadenbuie gadenbuie pinned this issue Aug 29, 2024
@Billy-Pilgrim-UIT
Copy link

Hi - having big issues related to this chrome v128 update.

`> library(gt)

Create a sample gt table

gt_table <- gt(mtcars[1:5, ])

Save the gt table to PNG using gtsave()

gtsave(gt_table, "table.png")
Error in with_random_port():
! Cannot find an available port. Please try again.
Caused by error in Sys.getenv():
! wrong type for argument
Run rlang::last_trace() to see where the error occurred.`

Attempted the workaround suggested by bradvf and end up with same error:

`chrome_path <- "C:\chrome-win64\chrome.exe"

m <- Chromote$new(browser = Chrome$new(path = chrome_path))
Error in with_random_port():
! Cannot find an available port. Please try again.
Caused by error in Sys.getenv():
! wrong type for argument
Run rlang::last_trace() to see where the error occurred.`

Any help appreciated - I am very reliant on this! Thankyou!

@tatvabodhini
Copy link

I too encountered an error when the chrome got updgated.

Right now I initiate the chrome session like this.. and I get the error 'Cannot find an available port. Please try again.'

chromote::set_default_chromote_object(
chromote::Chromote$new(chromote::Chrome$new(
args = c("--disable-gpu",
"--no-sandbox",
"--mute-audio",
"--disable-timeouts-for-profiling",
"--disable-dev-shm-usage",
c("--force-color-profile", "srgb"))
))
)

Is is suggested to add --headless=new ?? like below?

chromote::set_default_chromote_object(
chromote::Chromote$new(chromote::Chrome$new(
args = c("--disable-gpu",
"--no-sandbox",
"--mute-audio",
"--disable-timeouts-for-profiling",
"--disable-dev-shm-usage",
c("--force-color-profile", "srgb"),
c("--headless", "new")
)
))
)

@gadenbuie
Copy link
Member

@Billy-Pilgrim-UIT Can you please install the latest chromote (v0.3.1) and try again? There was a small but consequential bug in v0.3.0

@tatvabodhini
Copy link

@Billy-Pilgrim-UIT Can you please install the latest chromote (v0.3.1) and try again? There was a small but consequential bug in v0.3.0

do you recommend including c("--headless", "new") option? I would like to keep the old behaviour as is.

@tatvabodhini
Copy link

@gadenbuie here is the full trace of the error when trying to iniate new chrome session.

Error in fetching the screenshot of the URL:Cannot find an available port. Please try again.
Caused by error in startup():
! Failed to start chrome. Error: mkdir: cannot create directory ‘/nonexistent’: Permission denied
touch: cannot touch '/nonexistent/.local/share/applications/mimeapps.list': No such file or directory
chrome_crashpad_handler: --database is required
Try 'chrome_crashpad_handler --help' for more information.
[114:114:0830/113516.429972:ERROR:socket.cc(120)] recvmsg: Connection reset by peer (104)

@gadenbuie
Copy link
Member

do you recommend including c("--headless", "new") option? I would like to keep the old behaviour as is.

@tatvabodhini if you install the latest version of chromote, you won't need to change anything to keep the old behavior. With the latest version you can test the new headless mode by setting options(chromote.headless = "new").

@ValentineHerr
Copy link

ValentineHerr commented Aug 30, 2024

The new version of chromote resolved my issue with saving to a png file (using gt::gtsave), thanks a lot!

But it has not solved my issue of converting an html to a pdf (using pagedown::chrome_print):

tab_1 <-
  gtcars |>
  dplyr::select(model, year, hp, trq) |>
  dplyr::slice(1:5) |>
  gt(rowname_col = "model") |>
  tab_stubhead(label = "car")

tab_1 |> gtsave(filename = "tab_1.html")
pagedown::chrome_print(input = "tab_1.html",
                       output = "tab_1.pdf")

This may be unrelated to the Chrome package.

For those having this issue you can add the path to another browser in argument pagedown::chrome_print:

tab_1 |> gtsave(filename = "tab_1.html")
pagedown::chrome_print(input = "tab_1.html",
                       output = "tab_1.pdf",
                       browser = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe")

@gadenbuie
Copy link
Member

@ValentineHerr Great to hear the new version of chromote is working for you! Unfortunately, while pagedown uses headless Chrome, it doesn't use chromote, so you'll have to wait for a pagedown-specific fix for chrome_print().

@tatvabodhini
Copy link

do you recommend including c("--headless", "new") option? I would like to keep the old behaviour as is.

@tatvabodhini if you install the latest version of chromote, you won't need to change anything to keep the old behavior. With the latest version you can test the new headless mode by setting options(chromote.headless = "new").

@gadenbuie The issue still persisted. So I had to go back to old version of chrome. Chrome version "127.0.6533.119" worked for me with chromote 0.3.1 version package. I did not set the environment variables as refrerenced in package updates. I guess the old behaviour persisted and worked.

@gadenbuie
Copy link
Member

@tatvabodhini please feel free to open a new issue with a reproducible example

@Billy-Pilgrim-UIT
Copy link

@Billy-Pilgrim-UIT Can you please install the latest chromote (v0.3.1) and try again? There was a small but consequential bug in v0.3.0

Thankyou @gadenbuie - that was my blind spot. I was running Chromote v0.3.0.

Upgrading to v0.3.1 appears to have fixed the issue.
Thanks so much.

@NJKode
Copy link

NJKode commented Sep 1, 2024

Adding this for posterity:

I was having issues with image sizes in Webshot. We have a Shiny app with Webshot image downloads that is deployed to shinyapps.io. After making a deploy to shinyapps.io on 23/08/24 (NZT), all images were getting downloaded with a width of 780px no matter what. After a lot of investigating (including finding this gh issue), I theorized that shinyapps.io had updated their server image to Chrome 128, and that our problems might also be caused by this version.

Just chiming in to say that updating to Chromote v0.3.1 (with no code updates) has fixed the issue! Images are now downloading at the correct size.

Thanks so much for this!

@wch wch closed this as completed Sep 1, 2024
@wch
Copy link
Collaborator

wch commented Sep 1, 2024

Closing because the problem is resolved with Chromote 0.3.1.

@Migchw
Copy link

Migchw commented Sep 2, 2024

I got error when try to update chromote package

package ‘chromote’ successfully unpacked and MD5 sums checked
Error in install.packages : ERROR: failed to lock directory ‘C:\Users\kaoakesu\AppData\Local\R\win-library\4.3’ for modifying
Try removing ‘C:\Users\kaoakesu\AppData\Local\R\win-library\4.3/00LOCK’

@Migchw
Copy link

Migchw commented Sep 2, 2024

I can fix the problem with this code
options("install.lock"=FALSE)

thank so much !

I got error when try to update chromote package

package ‘chromote’ successfully unpacked and MD5 sums checked Error in install.packages : ERROR: failed to lock directory ‘C:\Users\kaoakesu\AppData\Local\R\win-library\4.3’ for modifying Try removing ‘C:\Users\kaoakesu\AppData\Local\R\win-library\4.3/00LOCK’

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