Hi,
I am trying to set up Visualizer with Plotly library, and facing few issues.
Firstly I tried to load plotly min js via <script> tag, but got into CSP issues, for the unsafe inline script.
Then I researched and came across the below link, which guides about how we can load extenral/CDN js in POSTMAN test scripts and I tried that for Plotly.
The Plotly script URL is https://cdn.plot.ly/plotly-latest.min.js
After this, it seems not able to parse the script and failing for syntax error. Below is the error.
2RgBbPrVy.html: 21 Uncaught SyntaxError: Unexpected token â&â
I tried many minor alternatives, but none worked. Please guide further.
My test script code is as below:
var jsonData = JSON.parse(responseBody);
var template = `
<script>
console.log('creating chart');
const script_plt_fn = (new Function({{script_fn}}))();
const chart_data = {{chart_data}};
const chart_layout = {{chart_layout}};
var div_plot = document.getElementById("myplot");
Plotly.newPlot(
div_plot,
chart_data,
chart_layout,
{displaylogo: false}
);
</script>
<div id=âmyplotâ>this is my div</div>
`;
console.log("this is console log: ",jsonData);
script_plt = pm.environment.get(âplotly.min.jsâ);
//var fn = new Function(script_plt);
pm.visualizer.set(template, {script_fn: script_plt, chart_data: jsonData.data, chart_layout:jsonData.layout });