Describe the bug
browseURL("http://www.google.com") does not work and neither does a file that exists locally, say, also local files, say browseURL("docs//authors.html").
To Reproduce
Steps to reproduce the behavior:
browseURL("docs//authors.html")Do you want to fix by self? (I hope your help!)
Don't think I can.
Expected behavior
A browser window should open, either via webView inside vscode, or alternatively, my default browser.
Environment (please complete the following information):
Additional context
browseURL("http://www.google.com") works fine in an unattached session.
Also, manually setting (options="/usr/bin/open") inside an attached sessions, thereby overwriting the browser from init.R fixes the problem
It is known that browseURL("http://www.google.com") opens a WebView with content blocked since VSCode WebView does not allow to browse non-localhost URL. You may try .vsc.browser("http://www.google.com", viewer = FALSE) to open it in an external web browser (just like the old behavior). We could also detect if the URL is from localhost (127.0.0.1) and auto open it in external browser.
browseURL("docs//authors.html") does not work because we use an iframe to display the content from a localhost HTTP server in VSCode WebView. This does not work with local file due to security reason. You may try .vsc.viewer("docs/author.html") in this case, which is supposed to work since it creates a WebView and put the HTML content directly in the WebView.
We may need to make these browser or viewer functions smarter to deal with inputs to make them have similar behavior in native R.
ah, thanks for clarifying -- I wasn't fully aware of the limitations imposed by VSCode WebView.
I didn't have any luck with .vsc.viewer("docs//authors.html"), which silently did nothing.
Same with .vsc.browser("http://www.google.com", viewer = FALSE).
We may need to make these browser or viewer functions smarter to deal with inputs to make them have similar behavior in native R.
I'd love to help, if I can.
Can you clarify for which purposes/inputs the custom .vsc.browser() is expected to do something useful/special via WebView?
Then all other inputs, perhaps, should be routed back to the default browseURL() behavior.
I understand that static HTML (without being served from localhost) and external websites (http:) both won't work inside of VSCode anyway.
So that basically leaves only localhost stuff.
Did I get this right?
If so, I can try and write up some logic in a PR if you think that makes sense.
Currently,
.vsc.browser are used to browse localhost URL (e.g. shiny apps, R html help, rmarkdown::run()). It is only expected to work with a URL, (e.g. http://localhost:1234, http://google.com, file:///C:/Users/user/Documents/test.html, file:///home/user/Documents/test.html). A web URL should work with remote development (via WebView port mapping to client localhost) while a file URL does not work with remote development unless the HTML file is served by an HTTP server).vsc.viewer shows htmlwidgets (e.g. DT::datatable()) and .vsc.page_viewer (e.g. profvis::profvis()). These two functions work with local file full path and vscode-R will replace the JS/CSS resources with vscode-resource:// schema and put the HTML in a VSCode WebView. These two functions are not supposed to work with any HTML file.I understand that static HTML (without being served from localhost) and external websites (http:) both won't work inside of VSCode anyway.
If the static HTML uses some external resources, all the resource URL must be rewritten to vscode-resource:// schema or the resource won't load due to security reason.
I think it makes sense to fallback to the old behavior of browser if we handle those cases where VSCode WebView could not properly show the file or URL:
.vsc.browser should detect if the supplied url is a localhost URL that uses localhost or 127.0.0.1 as the doman. If so, then use VSCode WebView; otherwise,url is suppled a file path, normalize it to be a full path and make it a file URL like file://.....vsc.browser(url, viewer = FALSE). This will work with VSCode Remote Development or otherwise a remote browser = "/usr/bin/open" won't work on client side.It would be nice if you try and make a PR for this. New contributors are always welcome!
.vsc.browser("https://google.com", viewer = FALSE) works for me, i.e. opens the url in my external browser.
browseURL("https://google.com") open a blank webview within vscode.
Given that many packages make use of browseURL(), it would be great if the default behavior of .vsc.browser() could support the normal browseURL() behavior for the time being, i.e. opening in an external browser.