cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Zuv Frequent Visitor
Frequent Visitor

Replace powerbi report on same div with a new one

We do have application where user can select from a few reports and load them over ajax on a same reportContainer div.

We have been using powerbi js for quite a long time, it was version -- v2.4.7

It worked pretty well, stable, fast and the most important it could use same created iFrame for a new report without reloading it from scratch.

Here is the code that worked:

var config = {
          type: 'report',
          tokenType: models.TokenType.Embed,
          accessToken: embedToken,
          embedUrl: embedUrl,
          id: report_id
};
powerbi.embed(reportContainer,config);

Recently we started Powerbi js version -- v2.6.5

It basically can't use same div container, in order to place a new report I need to reset it first with:

powerbi.reset(reportContainer); 
OR
powerbi.embedNew(reportContainer, config);

Well, it works, but it takes time to load all the frame every time and it looks much slower compared with old version of Powerbi JS.

Also I am having this error on Javascript level when doing powerbi.reset(reportContainer):

Error: target window is not provided.  You must either provide the target window explicitly as argument to request, or specify default target window when constructing instance of this class.

Maybe this is something that down the speed?

Is it possible to make it faster? Or maybe mine modus operandi is not the good one and I should use something different?
Many thanks

 

6 REPLIES 6
ndothanh Occasional Visitor
Occasional Visitor

Re: Replace powerbi report on same div with a new one

I also meet the same issue, and the error happens when embedding new report, it happens in the handler for front load 'ready' message.

I concern that whether this error is harmful or not.

gicagugui Visitor
Visitor

Re: Replace powerbi report on same div with a new one

We face the same issue when using reset or embedNew to replace the report in a div container. 

Is this a bug or the approach we followed is not the correct one? Thanks.

brianl Visitor
Visitor

Re: Replace powerbi report on same div with a new one

I have the some problem with 2.6.5. I was able to go back just one version, to 2.6.4, in order to avoid the error. I did not notice a performance difference between the two versions.

 

Here is how I am switching out the report.

 

let config = {
    type: "report",
    tokenType: pbi.models.TokenType.Embed,
    accessToken: accessToken,
    embedUrl: embedUrl,
    id: reportId,
    permissions: pbi.models.Permissions.All,
    viewMode: pbi.models.ViewMode.View,
    pageView: 'fitToWidth',
    settings: {
        filterPaneEnabled: false,
        navContentPaneEnabled: true
    }
};
let embedDiv = document.getElementById('embedDiv');
if (embedDiv !== null) {
    powerbi.reset(embedDiv);
    let embeddedReport = powerbi.embed(embedDiv, config);
}
DanT Frequent Visitor
Frequent Visitor

Re: Replace powerbi report on same div with a new one

Having the same issue here.  This error came after 'powerbi.reset' and try to reload a new report "powerbi.embed(X,Y)". Nothing seems to be affected. But is this a bug? Will it bring bad effects?

stizz001 Regular Visitor
Regular Visitor

Re: Replace powerbi report on same div with a new one

I am getting the same issue and where it is affecting me is when I try to turn the report's edit mode on.  The report rendered fine and looks all correct, but I give SysAdmin's the ability to edit the report directly in my app, and when I hit that button, I get the same error.  

 

"Uncaught Error: target window is not provided. You must either provide the target window explicitly as an argument to request or specify the default target window when constructing an instance of this class."

Can anyone help, please? Thanks.

stizz001 Regular Visitor
Regular Visitor

Re: Replace powerbi report on same div with a new one

In case you still are having this issue I found that in my code the part that loaded the report was being run 2 times. The first time everything works great.  The 2nd time is when the contentWindow was not there and thus threw the error message.  So I put an "if" statement around the code that loads the report that will only pass if.....

 

report && report.iframe && report.iframe.contentWindow

 

so if you wrap your report loading code in an if statment like this, that will get rid of the error message.  

 

//get the report container and the report from the container for further use
						var $reportContainer = $('#reportEmbed');
						report = powerbi.embed($reportContainer.get(0), self.embedConfig);
						//when the report is loaded
						report.on('loaded', function (event) {

							if (report && report.iframe && report.iframe.contentWindow) {
								report.getPages().then(function (pages) {
									if (pages) {
										pages[0].setActive();
									}
								});

								report.on('rendered', function (_) {
									$('#reportEmbed').css('opacity', '100');
								});
							}
						});

 

Helpful resources

Announcements
Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Summit North America

Power Platform Summit North America

Register by September 5 to save $200

Virtual Launch Event

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Top Kudoed Authors
Users Online
Currently online: 6 members 3,378 guests
Please welcome our newest community members: