有没有办法使用链接从vscode加载网站?

时间:2019-10-17 14:04:07

标签: typescript visual-studio-code

我正在尝试使用vscode的webapp api加载网页。我需要的是从通过vscode提供的URL加载网站。有没有办法做到这一点?我刚刚添加了一个iframe,但对我没有用。

private _getHtmlForWebview(catGif: string) {
        // Local path to main script run in the webview
        const scriptPathOnDisk = vscode.Uri.file(
            path.join(this._extensionPath, 'media', 'main.js')
        );

        // And the uri we use to load this script in the webview
        const scriptUri = scriptPathOnDisk.with({ scheme: 'vscode-resource' });

        // Use a nonce to whitelist which scripts can be run
        const nonce = getNonce();

        return `<!DOCTYPE html>
            <html lang="en">
            <head>
                <meta charset="UTF-8">

                <!--
                Use a content security policy to only allow loading images from https or from our extension directory,
                and only allow scripts that have a specific nonce.
                -->
                <meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src vscode-resource: https:; script-src 'nonce-${nonce}';">

                <meta name="viewport" content="width=device-width, initial-scale=1.0">
                <title>Cat Coding</title>
            </head>
            <body>
            <iframe src="${webLink}" width="100%" height="1000px">
                <p>Your browser does not support iframes.</p>
            </iframe>
                <img src="${catGif}" width="300" />
                <h1 id="lines-of-code-counter">0</h1>

                <script nonce="${nonce}" src="${scriptUri}"></script>
            </body>
            </html>`;
    }

0 个答案:

没有答案
相关问题