From 5dfae968877531978b374b55e34341248a02eb50 Mon Sep 17 00:00:00 2001 From: Vitaliy Gulyy Date: Tue, 23 Jun 2020 13:44:22 +0300 Subject: [PATCH] Wrap into comment Content-Security-Policy meta tag Signed-off-by: Vitaliy Gulyy --- .../plugin-ext/src/main/browser/webview/webview.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/plugin-ext/src/main/browser/webview/webview.ts b/packages/plugin-ext/src/main/browser/webview/webview.ts index 96254daaf5611..65fe4f23e3929 100644 --- a/packages/plugin-ext/src/main/browser/webview/webview.ts +++ b/packages/plugin-ext/src/main/browser/webview/webview.ts @@ -365,7 +365,17 @@ export class WebviewWidget extends BaseWidget implements StatefulWidget { } protected preprocessHtml(value: string): string { - return value + console.log('--------------------------------------------------------------------------------------'); + console.log(value); + console.log('--------------------------------------------------------------------------------------'); + // Comment tag in HEAD section + let html = value + .replace(/<\s*meta([^>]+?(?=Content-Security-Policy)[^>]+)\/?>/gsm, (_, group) => { + return ``; + }); + + // Update all links, using 'vscode-resource:' and 'theia-resource:' scheme + return html .replace(/(["'])(?:vscode|theia)-resource:(\/\/([^\s\/'"]+?)(?=\/))?([^\s'"]+?)(["'])/gi, (_, startQuote, _1, scheme, path, endQuote) => { if (scheme) { return `${startQuote}${this.externalEndpoint}/theia-resource/${scheme}${path}${endQuote}`;