rstudio / webshot2

Take screenshots of web pages from R

Home Page:https://rstudio.github.io/webshot2/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error trying to find path to Chrome

Minh-AnhHuynh opened this issue · comments

webshot2::webshot(file)
Error trying to find path to Chrome
Error in initialize… : Invalid path to Chrome

So I don't have Chrome installed, on Windows 11. How do I set webshot2 so that it seeks another chromium browser ? It seems strange that there isn't even the option to do so or I am missing something. Everyone has Edge installed which should do the trick

That's done by the chromote::find_chrome function:

> chromote::find_chrome
function () 
{
    if (Sys.getenv("CHROMOTE_CHROME") != "") {
        return(Sys.getenv("CHROMOTE_CHROME"))
    }
    ...

So if you set the CHROMOTE_CHROME environment variable to the appropriate path it will override the search. There's also a registry entry that it looks at on Windows:

...
if (is_windows()) {
        tryCatch({
            path <- utils::readRegistry("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe\\")
            path <- path[["(Default)"]]
        }, error = function(e) {
            message("Error trying to find path to Chrome")
            path <<- NULL
        })
...

Do you have an entry like that, but with different spelling somewhere?

Probably makes sense to document this in webshot2 somewhere.

So looking at the registry, I simply don't have chrome.exe. I have brave.exe which is a chromium browser, and I'm not eseeing edge.exe either in App Paths, even though Edge is already installed. Ideally it should switch to Edge by default as everyone has it.

Does it work if you set the environment variable to point to edge.exe or brave.exe?

Sorry for the late answer. I'm currently using another computer.

For some reason, I do not have edge.exe in my App Paths which is weird. Would you know how to set the app paths in R or add it to the registry ?

No, I rarely use Windows nowadays. I'd use the environment variable, Sys.setenv(CHROMOTE_CHROME = "path/to/edge.exe").

So if you set the CHROMOTE_CHROME environment variable to the appropriate path it will override the search.

This is very helpful, @dmurdoch. Thank you. This resolved an issue I was having and couldn't figure out.

Hello, I tried to set environment to msedge.exe and used a link as a test. However it doesn't seem like it is working. Is this an expected error ?

Here is the code:

> Sys.setenv(CHROMOTE_CHROME = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application.msedge.exe")
> webshot2::webshot("https://www.unitslab.com/node/84")
Error in `process_initialize(self, private, command, args, stdin, stdout, …`:
! Native call to `processx_exec` failed
Caused by error in `chain_call(c_processx_exec, command, c(command, args), pty, pty_options, …`:
! Command 'C:\Program Files (x86)\Microsoft\Edge\Application.msedge.exe' not found @win/processx.c:982 (processx_exec)
Type .Last.error to see the more details.
> .Last.error
<c_error/rlib_error_3_0/rlib_error/error>
Error in `process_initialize(self, private, command, args, stdin, stdout, …`:
! Native call to `processx_exec` failed
Caused by error in `chain_call(c_processx_exec, command, c(command, args), pty, pty_options, …`:
! Command 'C:\Program Files (x86)\Microsoft\Edge\Application.msedge.exe' not found @win/processx.c:982 (processx_exec)
---
Backtrace:
 1. webshot2::webshot("https://www.unitslab.com/node/84")
 2. chromote::default_chromote_object()
 3. chromote::set_default_chromote_object(Chromote$new())
 4. Chromote$new()
 5. local initialize…
 6. Chrome$new()
 7. local initialize…
 8. chromote:::launch_chrome(path, args)
 9. process$new(command = path, args = c("--headless", "--remote-debugging-port=0", …
10. local initialize(...)
11. processx:::process_initialize(self, private, command, args, stdin, stdout, …
12. processx:::chain_call(c_processx_exec, command, c(command, args), pty, pty_options, …
13. | base::withCallingHandlers(do.call(".Call", list(.NAME, ...)), error = function(e) { …
14. | base::do.call(".Call", list(.NAME, ...))
15. | base::.handleSimpleError(function (e) …
16. | local h(simpleError(msg, call))
17. | processx:::throw_error(err, parent = e)

Is the executable really named Application.msedge.exe? That looks like a typo.

I'm sorry, how did I miss that ? It was indeed a typo.

I executed the code again and it works as expected. Though the given image is pretty blurry. It does look like the issue is solved however. Thanks!

Sys.setenv(CHROMOTE_CHROME = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe")
webshot2::webshot("https://github.com/rstudio/webshot2/issues/39")

The blurriness is probably caused by resizing. You can play with vwidth and vheight args to webshot2::webshot().