rstudio / pagedown

Paginate the HTML Output of R Markdown with CSS for Print
https://pagedown.rbind.io
Other
889 stars 129 forks source link

New chrome v128 creates connection problem with chrome_print() #329

Closed chiaraherzog closed 1 month ago

chiaraherzog commented 1 month ago

Hi all, thanks for this package! I've been using it to render my CV, but since last week it seems chrome_print has a new error: I tried multiple things and still get the error even when using a basic template (test.rmd, i.e. just the basic template saved) without any edits, leaving me to believe it is an issue with some new edits.

rmarkdown::render("test.rmd",
                  params = list(pdf_mode = FALSE),
                  output_file = "cv.html")
pagedown::chrome_print(input = "cv.html",
                       output = "cv_test.pdf")
Error in force(expr) : 
  Failed to generate output. Reason: Failed to open http://127.0.0.1:6124/favicon.ico (HTTP status code: 404)

I have tried a manual fix by adding a link to an icon to the header of the HTML which displays as a favicon in the browser. When doing this I run into other issues with code recursivity.

Could you look into this for me? Otherwise I can't use this package to generate my CV anymore :(

My session info:

R version 4.4.1 (2024-06-14)
Platform: x86_64-apple-darwin20
Running under: macOS Sonoma 14.4.1

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Europe/London
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] websocket_1.4.2    pagedown_0.20      datadrivencv_0.1.1 magrittr_2.0.3    

loaded via a namespace (and not attached):
 [1] rappdirs_0.3.3      sass_0.4.9          utf8_1.2.4          generics_0.1.3      stringi_1.8.4       hms_1.1.3          
 [7] digest_0.6.36       evaluate_0.24.0     timechange_0.3.0    bookdown_0.40       fastmap_1.2.0       cellranger_1.1.0   
[13] jsonlite_1.8.8      processx_3.8.4      whisker_0.4.1       ps_1.7.7            promises_1.3.0      googledrive_2.1.1  
[19] httr_1.4.7          purrr_1.0.2         fansi_1.0.6         jquerylib_0.1.4     cli_3.6.3           rlang_1.1.4        
[25] crayon_1.5.3        withr_3.0.1         cachem_1.1.0        yaml_2.3.10         tools_4.4.1         tzdb_0.4.0         
[31] gargle_1.5.2        dplyr_1.1.4         webshot_0.5.5       httpuv_1.6.15       curl_5.2.1          mime_0.12          
[37] vctrs_0.6.5         R6_2.5.1            lifecycle_1.0.4     lubridate_1.9.3     stringr_1.5.1       fs_1.6.4           
[43] fontawesome_0.5.2   callr_3.7.6         pkgconfig_2.0.3     pillar_1.9.0        bslib_0.8.0         later_1.3.2        
[49] glue_1.7.0          Rcpp_1.0.13         servr_0.30          xfun_0.46           tibble_3.2.1        tidyselect_1.2.1   
[55] rstudioapi_0.16.0   knitr_1.48          htmltools_0.5.8.1   googlesheets4_1.1.1 rmarkdown_2.27      readr_2.1.5        
[61] compiler_4.4.1      askpass_1.2.0       openssl_2.2.0      
CarlottaHS commented 1 month ago

Hi all, I have gotten the exact same issue. My code was still running three days ago, but now I get the same error. I have tested it with a very simple html file (see below). That works, but the html file, which worked three days ago is not knitting anymore. I tried to change a couple of things in that html file, but so far did not have any luck.

Thanks in advance!

Example html file that works:

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Test Page</title>
    <link rel="icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/wcAAgAB/etM5aQAAAAASUVORK5CYII=" type="image/png">
</head>
edbonneville commented 1 month ago

Same issue here.. and after also trying renderthis::to_pdf() (I needed to export slides) it looks like it could be an issue with chrome? Possibly related to https://github.com/rstudio/chromote/issues/170

jruddy12 commented 1 month ago

Hi all, this is definitely an issue related to the most recent Chrome update. I rolled back to the previous version of Chrome and chrome_print() is working again for me.

Hopefully the issue is resolved with the next Chrome update.

CarlottaHS commented 1 month ago

@jruddy12 how did you roll back to a previous version of Chrome? Do have a trusted site to download a slightly older version?

jruddy12 commented 1 month ago

@CarlottaHS the following was recommended and worked for me:

https://www.slimjet.com/chrome/google-chrome-old-version.php

The only issue is that Chrome wants to auto-update every time you open the browser. I was using Chrome as my primary browser but I've been using Safari the past couple of days to prevent Chrome updating. I rely on chrome_print() pretty heavily for automated reporting at work, so hoping there's a fix for it, but this is a good temporary work around.

cderv commented 1 month ago

@jruddy12 one idea to have a fixed version to use. Install a portable chromium in the version you need, and then configure chrome_print to use this chrome version for any work it does.

Also you can try what has been discussed in chromote repo

There seems to be some changes in chrome that we need to take into account (while trying to see how we be backward compatible). I'll follow chromote work to match their fix.

cderv commented 1 month ago

About new headless mode : https://developer.chrome.com/docs/chromium/new-headless

maxbre commented 1 month ago

same issue here after updating chrome

daviewales commented 1 month ago

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

aegerton commented 1 month ago

Looking forward to a solution to this problem with the new Chrome version. Taking the HTML file and printing/saving to a PDF file each time is tedious, to say the least!

cderv commented 1 month ago

For reference, as explained in other thread https://github.com/rstudio/chromote/issues/170#issuecomment-2310427013

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

We are waiting for news on those one. This seems to be a chrome bug, so we need to wait for now;

Especially tracking this one

gadenbuie commented 1 month ago

@cderv I'm certain that the 404 for the favicon is related to the API changes from Chrome switching to --headless=new by default, but it's not just Windows related (it repros for me on MacOS). My guess is that Chrome is going to have significant fallout over the next few weeks as everyone discovers subtle API changes between the two headless modes.

cderv commented 1 month ago

My guess is that Chrome is going to have significant fallout over the next few weeks as everyone discovers subtle API changes between the two headless modes.

yes I agree. I think we already had some in Quarto too. Though it seems rather limited right now. I'll be watching and let's keep in touch on this topic.

gadenbuie commented 1 month ago

@cderv I think the quickest stop-gap method is to make --headless configurable with a default of old

https://github.com/rstudio/pagedown/blob/6763538deb2cd78de05631715ea57085a85b8bd6/R/chrome.R#L94

This is what I'm proposing in chromote.

MMJansen commented 1 month ago

I had the same problem, asked about it on stackoverflow, and someone suggested placing a dummy flavicon.ico in the directory of the html you want chrome_printed. That workaround works for me. Is it a solution to prevent chrome_print looking for this file? Or else have a dummy flavicon.ico in the chrome_print?

yihui commented 1 month ago

@MMJansen That's a clever hack. I just implemented it in the servr package (which is used by pagedown::chrome_print()). Please try:

remotes::install_github('yihui/servr')

Remember to restart R after installation. Thanks!

Once you confirm that the fix works (I've verified it myself but it'll be nicer if someone can verify it independently), I'll release a new version of servr to CRAN.

MMJansen commented 1 month ago

@yihui , the fix works! I did get an error from yihui-servr-e8a26b8/inst/examples/make2/example.Rmd, that it could not create the example.Rmd on a specific location, but servr_0.30.2 is installed. And pagedown::chrome_print works again without having the manual added ico file in the folder. THANKS!

yihui commented 1 month ago

Okay, I just submitted it to CRAN, and hopefully the new release will appear soon.

cderv commented 1 month ago

Thanks @yihui!

New chrome update could have other problem, like in chromote. So we may need to change the way we call it in pagedown at some point.

I'll watch out!

yihui commented 1 month ago

Sounds good.

The new version of servr is on CRAN now, which means we can install.packages('servr').

ValentineHerr commented 1 month ago

Thank you for the servr update! That resolved the issue for me except one thing: now the PDF title (not the filename but the name that shows up in the tab when you open in a pdf reader like Foxit) is not the name of the file like it used to be, but the [name of the port (I think)]/[name of input html file]. The previous behavior was much better.

MMJansen commented 1 month ago

Thank you for the servr update! That resolved the issue for me except one thing: now the PDF title (not the filename but the name that shows up in the tab when you open in a pdf reader like Foxit) is not the name of the file like it used to be, but the [name of the port (I think)]/[name of input html file]. The previous behavior was much better.

I do not have that issue. The title (as in the yaml title) is shown in the tab from acrobat reader, just as before.

ValentineHerr commented 1 month ago

ok thanks for letting me know! It must be a setting that was changed on my pdf reader.

silvana-takara commented 1 month ago

I used the solution mentioned in #https://stackoverflow.com/a/43042288/27181508 , adding the snippet below solved for me.

<link rel="shortcut icon" href="#">
backenv commented 2 days ago

Thank you @yihui for servr update, it works perfectly!

I use rmarkdown in some of my packages so I just included the new dependency for version 0.31 to ensure new installations don't have the problem.

Following @silvana-takara example did not work for me if included directly into the Rmd file to be rendered, but could be perfectly achieved with a little javascript like so:

<script>
    function add_favicon_link() {
        const link = document.createElement("link");
        link.rel = "shortcut icon";
        link.href = "#";
        document.head.appendChild(link);
    }
    add_favicon_link();
</script>