使用WebView API时,Encouter阻止了Webview导航

时间:2019-01-04 01:35:32

标签: visual-studio-code vscode-extensions

嗨,我正在使用vscode webview api来显示本地服务器上的某些网页

网页源代码的关键部分(形式)是这样的。它有一个按钮,单击后将启动发布请求。因此它可以更新其内容

<form method="POST" action="">
    <div class="form-group"><label for="start">Start Date:</label><input id="name" type="date" name="start" value="2019-01-01"
            class="form-control"><label for="end">End Date:</label><input id="name" type="date" name="end" value="2019-01-04"
            class="form-control"></div><button type="submit" class="btn btn-primary">generate report</button>

使用浏览器打开时效果很好。但是当在vscode中启动它时,没有任何显示,vscode告诉我使用webview api时它阻止了webview导航

使用webview api的代码部分就是这样

    public async showDetailedReport(){
    const param: IRequestParam ={
        endpoint:'localhost',
        method:'GET',
        port:23333,
        path:'/report/detailReport'
    };
    try{
        const html: string = await sendRequest(param);
        const panel = vscode.window.createWebviewPanel(
            'Report',
            'Report',
            vscode.ViewColumn.One,
            {
                enableScripts:true,
            }
        );
        panel.webview.html = html;
    } catch(e){
        await vscode.window.showErrorMessage(e);
    }
}

所以我的问题是为什么会发生这种情况以及如何解决它,这意味着我要发送帖子或将其重定向到其他网页。任何事情都会有所帮助。谢谢。

1 个答案:

答案 0 :(得分:0)

从VS Code 1.31开始,Web视图只能显示html内容页面,而不能导航到其他资源(例如使用表单发出POST请求)。

您仍然可以使用fetch或类似的API发出请求,但是标准的POST提交表单将不起作用。