microsoft / powerbi-client-angular

Power BI Angular component. This library lets you embed Power BI report, dashboard, dashboard tile, report visual, or Q&A in your Angular application.
Other
135 stars 65 forks source link

TypeError: Cannot read properties of undefined (reading 'tokenType') #66

Closed StephanBis closed 5 months ago

StephanBis commented 5 months ago

Hi,

We're getting the following error when trying to embed a report.

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.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);
        });
      });
    });

This setup has been working great for a while, but after switching up some code, this error started occuring. This block of code has been moved to AfterViewInit, we already tried moving it back to OnInit, but the issues stays. Does anyone have a clue?

StephanBis commented 5 months ago

I think I may have found the issue here.

The config is expected to be passed to this function

function isSaaSEmbedWithAADToken(config) {
    // Default token type is Aad (0)
    const tokenType = config.tokenType || 0;
    return (window.isSaasOrPaasEmbed === true) && (tokenType === 0);
}

However in the calling code, the config isn't actually passed, is this by design or am I missing something here?

if (isSaaSEmbedWithAADToken() && config.settings && config.settings.personalBookmarksEnabled) {
    url += "&defaultBookmarkEnabled=true";
}
vsmakagenzeon commented 5 months ago

We are encountering a similar error when embedding the report, specifically receiving an "undefined method config" error message. This issue has recently surfaced, and it appears that the config parameter is not being passed to the isSaaSEmbedWithAADToken() function, which seems to be causing the error. Does anyone have any ideas on how to fix this issue? Is this a problem that needs to be resolved on the Power BI side?

smartclue commented 5 months ago

I does appear that this would be something caused by changes in the power bi side of things. Looking at the demo playground app for the embedded BI also seems to be encountering this failure.

https://playground.powerbi.com/en-us/showcases-gallery/insight-to-action

This error appears to be non-fatal for version of chromium 94+. The same can not be said about older versions, if you are running a regression that is using older browser versions your embedded report might not load.

StephanBis commented 5 months ago

I does appear that this would be something caused by changes in the power bi side of things. Looking at the demo playground app for the embedded BI also seems to be encountering this failure.

https://playground.powerbi.com/en-us/showcases-gallery/insight-to-action

This error appears to be non-fatal for version of chromium 94+. The same can not be said about older versions, if you are running a regression that is using older browser versions your embedded report might not load.

You are correct, this error is non-fatal on later version of Chromium. We were facing a different issue which caused the reports to not load. This does need to be fixed at Microsoft's end though.

aliabufoul commented 5 months ago

Thanks for reporting this issue. The issue was fixed. Fix should be deployed by this week.

sshresthareach commented 5 months ago

I does appear that this would be something caused by changes in the power bi side of things. Looking at the demo playground app for the embedded BI also seems to be encountering this failure. https://playground.powerbi.com/en-us/showcases-gallery/insight-to-action This error appears to be non-fatal for version of chromium 94+. The same can not be said about older versions, if you are running a regression that is using older browser versions your embedded report might not load.

You are correct, this error is non-fatal on later version of Chromium. We were facing a different issue which caused the reports to not load. This does need to be fixed at Microsoft's end though.

I am assuming a fix has been deployed. Looks like the error does not appear anymore but the embedded reports still do not load in chromium versions older than 94.

andy-peoples commented 5 months ago

Thanks for reporting this issue. The issue was fixed. Fix should be deployed by this week.

Hi, we too are experiencing the same issue running Chromium 92. It is not currently possible to upgrade to a higher version. Do we need to amend any code on our side?

StephanBis commented 5 months ago

Issue has been fixed at Microsoft's end.