我正在尝试实现自己的VSCode扩展。扩展将启动一些子流程,创建
localhost:port
.网站
localhost:端口
应加载
WebView
。目前它在本地机器上完全可以工作,但当我使用SSH连接时,webview没有加载到远程机器上。
据我所知,VSCode有一些
problems
从web视图使用localhost。我已经尝试过使用上述两种解决方法。但不幸的是,没有人工作。
例如,我从网站上实现了第二项工作。我创建
panel
使用以下代码:
let panel = vscode.window.createWebviewPanel(view_type, tab_name,
vscode.ViewColumn.One,
{
enableScripts: true,
retainContextWhenHidden: true
});
然后,我尝试从子流程中可视化localhost:
const process = subprocess.spawn(cmd, [model_path]);
process.stdout.on('data', async (data) => {
const output = data.toString();
const url_path = output;
const web_uri = await vscode.env.asExternalUri(vscode.Uri.parse(url_path));
panel.webview.html = this.getHTMLForWebview(web_uri);
});
private getHTMLForWebview(web_uri: vscode.Uri): string {
return `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Visualization</title>
</head>
<body>
<iframe
width="100%"
height="800"
src="${web_uri}"
></iframe>
</body>
</html>`;
}
正如我之前所说的,它可以在我的本地Windows机器上运行。但我在远程Linux机器上看到了空的webview(只是一个空帧):
这是我的第一次延期,所以我可能错过了什么。
我应该添加/重写什么来在远程机器上渲染localhost?
我也已经看过了
another
解决方案这只是一个已知网站的链接。