Skip to content

Commit bc51e74

Browse files
committed
Fix Graphviz WASM module not loading for graph viewer
It seems that when we added the CSP policy to the webview, we did not take into account that `d3-graphviz` uses `@hpcc-js/wasm` to load Graphviz as a WASM module. This commit adds `'wasm-unsafe-eval'` to the CSP policy to allow this.
1 parent 5933f09 commit bc51e74

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

extensions/ql-vscode/src/interface-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export function getHtmlForWebview(
163163
/*
164164
* Content security policy:
165165
* default-src: allow nothing by default.
166-
* script-src: allow only the given script, using the nonce.
166+
* script-src: allow the given script, using the nonce. also allow loading WebAssembly modules.
167167
* style-src: allow only the given stylesheet, using the nonce.
168168
* connect-src: only allow fetch calls to webview resource URIs
169169
* (this is used to load BQRS result files).
@@ -172,7 +172,7 @@ export function getHtmlForWebview(
172172
<html>
173173
<head>
174174
<meta http-equiv="Content-Security-Policy"
175-
content="default-src 'none'; script-src 'nonce-${nonce}'; font-src ${fontSrc}; style-src ${styleSrc}; connect-src ${
175+
content="default-src 'none'; script-src 'nonce-${nonce}' 'wasm-unsafe-eval'; font-src ${fontSrc}; style-src ${styleSrc}; connect-src ${
176176
webview.cspSource
177177
};">
178178
${stylesheetsHtmlLines.join(` ${EOL}`)}

extensions/ql-vscode/src/view/results/graph.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
InterpretedResultSet,
66
GraphInterpretationData,
77
} from "../../pure/interface-types";
8-
import { graphviz } from "d3-graphviz";
8+
import { graphviz, GraphvizOptions } from "d3-graphviz";
99
import { tryGetLocationFromString } from "../../pure/bqrs-utils";
1010
export type GraphProps = ResultTableProps & {
1111
resultSet: InterpretedResultSet<GraphInterpretationData>;
@@ -59,11 +59,12 @@ export class Graph extends React.Component<GraphProps> {
5959
return;
6060
}
6161

62-
const options = {
62+
const options: GraphvizOptions = {
6363
fit: true,
6464
fade: false,
6565
growEnteringEdges: false,
6666
zoom: true,
67+
useWorker: false,
6768
};
6869

6970
const element = document.querySelector(`#${graphId}`);
@@ -77,8 +78,7 @@ export class Graph extends React.Component<GraphProps> {
7778
const borderColor = getComputedStyle(element).borderColor;
7879
let firstPolygon = true;
7980

80-
graphviz(`#${graphId}`)
81-
.options(options)
81+
graphviz(`#${graphId}`, options)
8282
.attributer(function (d) {
8383
if (d.tag === "a") {
8484
const url = d.attributes["xlink:href"] || d.attributes["href"];

0 commit comments

Comments
 (0)