@@ -494,11 +494,24 @@ request_browser <- function(url, title, ..., viewer) {
494494
495495show_browser <- function (url , title = url , ... ,
496496 viewer = getOption(" vsc.browser" , " Active" )) {
497+ proxy_uri <- Sys.getenv(" VSCODE_PROXY_URI" )
498+ if (nzchar(proxy_uri )) {
499+ is_base_path <- grepl(" \\ :\\ d+$" , url )
500+ url <- sub(" ^https?\\ ://(127\\ .0\\ .0\\ .1|localhost)(\\ :)?" ,
501+ sub(" {port}" , " " , proxy_uri , fixed = TRUE ), url )
502+ if (is_base_path ) {
503+ url <- paste0(url , " /" )
504+ }
505+ }
497506 if (grepl(" ^https?\\ ://(127\\ .0\\ .0\\ .1|localhost)(\\ :\\ d+)?" , url )) {
498507 request_browser(url = url , title = title , ... , viewer = viewer )
499508 } else if (grepl(" ^https?\\ ://" , url )) {
500509 message(
501- " VSCode WebView only supports showing local http content.\n " ,
510+ if (nzchar(proxy_uri )) {
511+ " VSCode is not running on localhost but on a remote server.\n "
512+ } else {
513+ " VSCode WebView only supports showing local http content.\n "
514+ },
502515 " Opening in external browser..."
503516 )
504517 request_browser(url = url , title = title , ... , viewer = FALSE )
@@ -535,11 +548,24 @@ show_webview <- function(url, title, ..., viewer) {
535548 stop(" Invalid object" )
536549 }
537550 }
551+ proxy_uri <- Sys.getenv(" VSCODE_PROXY_URI" )
552+ if (nzchar(proxy_uri )) {
553+ is_base_path <- grepl(" \\ :\\ d+$" , url )
554+ url <- sub(" ^https?\\ ://(127\\ .0\\ .0\\ .1|localhost)(\\ :)?" ,
555+ sub(" {port}" , " " , proxy_uri , fixed = TRUE ), url )
556+ if (is_base_path ) {
557+ url <- paste0(url , " /" )
558+ }
559+ }
538560 if (grepl(" ^https?\\ ://(127\\ .0\\ .0\\ .1|localhost)(\\ :\\ d+)?" , url )) {
539561 request_browser(url = url , title = title , ... , viewer = viewer )
540562 } else if (grepl(" ^https?\\ ://" , url )) {
541563 message(
542- " VSCode WebView only supports showing local http content.\n " ,
564+ if (nzchar(proxy_uri )) {
565+ " VSCode is not running on localhost but on a remote server.\n "
566+ } else {
567+ " VSCode WebView only supports showing local http content.\n "
568+ },
543569 " Opening in external browser..."
544570 )
545571 request_browser(url = url , title = title , ... , viewer = FALSE )
0 commit comments