import { TableauEventType } from 'https://public.tableau.com/javascripts/api/tableau.embedding.3.latest.js'; (async () => { // Get the viz object from the HTML web component const viz = document.querySelector('tableau-viz, tableau-authoring-viz'); // The value of the token variable is generated and available when this code executes in the playground. // You will have to generate this token. See CA documentation- https://sfdc.co/chGcg5. viz.token = window.token; // Wait for the viz to become interactive await new Promise((resolve, reject) => { // Add an event listener to verify the viz becomes interactive viz.addEventListener(TableauEventType.FirstInteractive, () => { console.log('Viz is interactive!'); resolve(); }); viz.addEventListener(TableauEventType.VizLoadError, (error) => { const message = JSON.parse(error.detail.message); const errorMessage = JSON.parse(message.errorMessage); const displayMessage = `ca-error-${errorMessage.result.errors[0].code}`; reject(displayMessage); }); }); })();