Skip to content

Commit 335ac00

Browse files
committed
add check for undefined panel and webview
1 parent df5215c commit 335ac00

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

src/extension.ts

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,34 @@ import { cssUri } from './markupParser';
1212

1313
function getRenderedContent(contentProvider: ConfluenceContentProvider, uri: vscode.Uri, panel: vscode.WebviewPanel) {
1414
contentProvider.provideTextDocumentContent(packConfluenceUri(uri)).then((renderedContent) => {
15-
// Security
16-
// https://code.visualstudio.com/api/extension-guides/webview#security
17-
18-
const cssFile = cssUri('confluence.css')
19-
let cssLink = ""
20-
if (cssFile) {
21-
const cssUrl = panel.webview.asWebviewUri(cssFile)
22-
cssLink = `<link rel="stylesheet" href="${cssUrl}">`
23-
}
15+
if (panel && panel.webview) {
16+
// Security
17+
// https://code.visualstudio.com/api/extension-guides/webview#security
18+
19+
const cssFile = cssUri('confluence.css')
20+
let cssLink = ""
21+
if (cssFile) {
22+
const cssUrl = panel.webview.asWebviewUri(cssFile)
23+
cssLink = `<link rel="stylesheet" href="${cssUrl}">`
24+
}
2425

25-
panel.webview.html = `<!DOCTYPE html>
26-
<html>
27-
<head>
28-
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
29-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
30-
<meta http-equiv="Content-Security-Policy"
31-
content="default-src 'none';
32-
img-src self vscode-resource: https:;
33-
script-src self vscode-resource:;
34-
style-src 'unsafe-inline' self vscode-resource:;"/>
35-
${cssLink}
36-
</head>
37-
<body>
38-
${renderedContent}
39-
</body>
40-
</html>`;
26+
panel.webview.html = `<!DOCTYPE html>
27+
<html>
28+
<head>
29+
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
30+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
31+
<meta http-equiv="Content-Security-Policy"
32+
content="default-src 'none';
33+
img-src self vscode-resource: https:;
34+
script-src self vscode-resource:;
35+
style-src 'unsafe-inline' self vscode-resource:;"/>
36+
${cssLink}
37+
</head>
38+
<body>
39+
${renderedContent}
40+
</body>
41+
</html>`;
42+
}
4143
}, (reason) => {
4244
vscode.window.showErrorMessage(reason);
4345
});

0 commit comments

Comments
 (0)