We encountered an error while attempting to embed a report using the Power BI Angular library.
TypeError: Cannot read properties of undefined (reading 'tokenType')
at isSaaSEmbedWithAADToken (reportEmbed?navContentPaneEnabled=false&uid=ame7c8:586:38)
at getModelsAndExploration (reportEmbed?navContentPaneEnabled=false&uid=ame7c8:696:17)
at getModelsAndExplorationAndConceptualSchema (reportEmbed?navContentPaneEnabled=false&uid=ame7c8:840:9)
at xhr.onreadystatechange (reportEmbed?navContentPaneEnabled=false&uid=ame7c8:505:37)
This code snippet illustrates how we are embedding the report.
this.msalService.initialize().subscribe(() => {
this.msalService.acquireTokenSilent({
scopes: environment.powerBiConfig.scopes,
account: this.authService.getUser()
}).subscribe(async (result) => {
const embedConfig: pbi.service.IComponentEmbedConfiguration = {
type: 'report',
id: this.report.identifier,
accessToken: result.accessToken,
tokenType: models.TokenType.Aad,
embedUrl: 'https://app.powerbi.com/reportEmbed?navContentPaneEnabled=false',
settings: {
panes: {
filters: {
visible: false,
}
}
}
};
const defaultFilters = this.createDefaultFilters();
const powerBiReport: any = this.powerBiService.embed(this.reportContainer.nativeElement, embedConfig);
powerBiReport.on('loaded', async () => {
await powerBiReport.setFilters(defaultFilters);
});
});
});
After investigating the stacktrace within Power BI Embedded JS files (which are not under our control), we identified the root cause of the issue. A specific function requires a config parameter to be passed:
function isSaaSEmbedWithAADToken(config) {
// Default token type is Aad (0)
const tokenType = config.tokenType || 0;
return (window.isSaasOrPaasEmbed === true) && (tokenType === 0);
}
The error occurs because the code does not pass the necessary config information as expected.
if (isSaaSEmbedWithAADToken() && config.settings && config.settings.personalBookmarksEnabled) {
url += "&defaultBookmarkEnabled=true";
}
While there may be issues on our side, it seems like a bug in Microsoft's implementation. Simply passing the config parameter correctly should resolve the problem.
Could our setup be causing this issue? Unfortunately, the Power BI Embedded JS files are not open for inspection.