From d33b2d2af9ce87b789e256ed16b94ddc81ff13f3 Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 27 Aug 2019 13:42:53 -0500 Subject: [PATCH] Fix web view sometimes not loading correctly Fixes #929. --- scripts/vscode.patch | 26 +++++++++++--------------- src/util.ts | 2 +- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/scripts/vscode.patch b/scripts/vscode.patch index 101c1a20..0c77456f 100644 --- a/scripts/vscode.patch +++ b/scripts/vscode.patch @@ -1109,7 +1109,7 @@ index 0d2d53003b..03489411bb 100644 group: '5_update', command: { diff --git a/src/vs/workbench/contrib/webview/browser/pre/index.html b/src/vs/workbench/contrib/webview/browser/pre/index.html -index ac53ce590e..69dbbd859c 100644 +index ac53ce590e..5411601483 100644 --- a/src/vs/workbench/contrib/webview/browser/pre/index.html +++ b/src/vs/workbench/contrib/webview/browser/pre/index.html @@ -4,7 +4,7 @@ @@ -1117,12 +1117,12 @@ index ac53ce590e..69dbbd859c 100644 -+ content="default-src 'none'; script-src 'self' 'unsafe-inline'; frame-src 'self'; style-src 'self' 'unsafe-inline'; worker-src 'self'; img-src https: data:; font-src 'self';" /> ++ content="default-src 'none'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; frame-src 'self'; style-src 'self' 'unsafe-inline'; worker-src 'self'; img-src https: data:; font-src 'self';" /> diff --git a/src/vs/workbench/contrib/webview/browser/pre/main.js b/src/vs/workbench/contrib/webview/browser/pre/main.js -index 63585fc25c..f49b63e024 100644 +index 63585fc25c..16102b89f1 100644 --- a/src/vs/workbench/contrib/webview/browser/pre/main.js +++ b/src/vs/workbench/contrib/webview/browser/pre/main.js @@ -256,7 +256,7 @@ @@ -1134,19 +1134,15 @@ index 63585fc25c..f49b63e024 100644 const newDocument = new DOMParser().parseFromString(text, 'text/html'); newDocument.querySelectorAll('a').forEach(a => { -@@ -265,6 +265,12 @@ - } - }); +@@ -379,7 +379,7 @@ -+ // REVIEW: Why is it required for scripts to be loaded at the end? -+ // Without this the document in the iframe appears to simply truncate. -+ newDocument.querySelectorAll('script').forEach(script => { -+ newDocument.body.appendChild(script); -+ }); -+ - // apply default script - if (options.allowScripts) { - const defaultScript = newDocument.createElement('script'); + newFrame.contentWindow.addEventListener('keydown', handleInnerKeydown); + +- newFrame.contentWindow.addEventListener('DOMContentLoaded', e => { ++ newFrame.contentWindow.addEventListener('load', e => { + if (host.fakeLoad) { + newFrame.contentDocument.open(); + newFrame.contentDocument.write(newDocument); diff --git a/src/vs/workbench/contrib/welcome/walkThrough/browser/editor/editorWalkThrough.ts b/src/vs/workbench/contrib/welcome/walkThrough/browser/editor/editorWalkThrough.ts index 7a95ffda9e..fdb14da4ee 100644 --- a/src/vs/workbench/contrib/welcome/walkThrough/browser/editor/editorWalkThrough.ts diff --git a/src/util.ts b/src/util.ts index 9e8a6ffd..46ea8741 100644 --- a/src/util.ts +++ b/src/util.ts @@ -66,7 +66,7 @@ export const getMediaMime = (filePath?: string): string => { return filePath && (vsGetMediaMime(filePath) || (<{[index: string]: string}>{ ".css": "text/css", ".html": "text/html", - ".js": "text/javascript", + ".js": "application/javascript", ".json": "application/json", })[extname(filePath)]) || "text/plain"; };