diff --git a/R/session/vsc.R b/R/session/vsc.R index cc1728664..f2c4c1ed0 100644 --- a/R/session/vsc.R +++ b/R/session/vsc.R @@ -494,11 +494,24 @@ request_browser <- function(url, title, ..., viewer) { show_browser <- function(url, title = url, ..., viewer = getOption("vsc.browser", "Active")) { + proxy_uri <- Sys.getenv("VSCODE_PROXY_URI") + if (nzchar(proxy_uri)) { + is_base_path <- grepl("\\:\\d+$", url) + url <- sub("^https?\\://(127\\.0\\.0\\.1|localhost)(\\:)?", + sub("{port}", "", proxy_uri, fixed = TRUE), url) + if (is_base_path) { + url <- paste0(url, "/") + } + } if (grepl("^https?\\://(127\\.0\\.0\\.1|localhost)(\\:\\d+)?", url)) { request_browser(url = url, title = title, ..., viewer = viewer) } else if (grepl("^https?\\://", url)) { message( - "VSCode WebView only supports showing local http content.\n", + if (nzchar(proxy_uri)) { + "VSCode is not running on localhost but on a remote server.\n" + } else { + "VSCode WebView only supports showing local http content.\n" + }, "Opening in external browser..." ) request_browser(url = url, title = title, ..., viewer = FALSE) @@ -535,11 +548,24 @@ show_webview <- function(url, title, ..., viewer) { stop("Invalid object") } } + proxy_uri <- Sys.getenv("VSCODE_PROXY_URI") + if (nzchar(proxy_uri)) { + is_base_path <- grepl("\\:\\d+$", url) + url <- sub("^https?\\://(127\\.0\\.0\\.1|localhost)(\\:)?", + sub("{port}", "", proxy_uri, fixed = TRUE), url) + if (is_base_path) { + url <- paste0(url, "/") + } + } if (grepl("^https?\\://(127\\.0\\.0\\.1|localhost)(\\:\\d+)?", url)) { request_browser(url = url, title = title, ..., viewer = viewer) } else if (grepl("^https?\\://", url)) { message( - "VSCode WebView only supports showing local http content.\n", + if (nzchar(proxy_uri)) { + "VSCode is not running on localhost but on a remote server.\n" + } else { + "VSCode WebView only supports showing local http content.\n" + }, "Opening in external browser..." ) request_browser(url = url, title = title, ..., viewer = FALSE)