Forum Discussion
Unhandled error from powerbi-client embed event listener is surfaced as global browser Script error
Hi Power BI team, we believe we found a bug/limitation in powerbi-client event handling for embedded reports.
When a report is embedded in an iframe (cross-origin), an exception thrown in an embed event listener appears to escape as a global browser error (window.onerror / Script error) instead of being contained in the SDK event pipeline.
Environment
- powerbi-client: 2.23.1
- Angular: 21.2.x
- Browser: Chrome (prod build)
- Embed host and iframe are cross-origin
Observed behavior
- powerbi-client receives a postMessage from iframe, routes it to event handling, and dispatches embed events.
- If one listener throws during this flow, the app receives a global window error (generic Script error / event-wrapped error), which can trigger app-level global error handling/UI alerts.
- The global error lacks actionable context and looks like app failure, even though it is iframe/event-listener noise.
Expected behavior
- Exceptions from embed event listeners should be safely handled/isolated by SDK (or surfaced only through SDK error channel), not leaked as global browser errors.
- At minimum, provide reliable error metadata so host apps can distinguish SDK listener failures from real app errors.
Workaround on our side
We suppress non-actionable global errors in our Angular ErrorHandler when:
- message contains Script error, or
- wrapped error has cause instanceof Event
This avoids user noise, but ideally the SDK should not leak these as global errors.
Repro outline
- Embed Power BI report with powerbi-client.
- Register at least one embed event listener (e.g. loaded, rendered, error).
- Throw an exception inside that listener.
- Observe global window error event and host app global error handler invocation.
6 Replies
- v-ssriganeshCommunity Support
Hi MadsMAndersen,
Thank you for posting your query in the Microsoft Fabric Community Forum.Based on your description, the exception appears to originate from a custom event listener registered in the host application rather than from the Power BI report itself. The Power BI Embedded SDK provides event handlers (for example, loaded, rendered, and error) and an error event mechanism for handling embed-related failures. Microsoft documentation recommends using the SDK's error event and standard JavaScript error handling (try/catch for async operations) when processing embed events.
could you please provide below information:
- A minimal reproducible code sample that demonstrates the behavior.
- Whether the issue can be reproduced in the Power BI Embedded Playground.
- Browser console logs/screenshots showing the global Script error.
- Confirmation whether the behavior persists with the latest powerbi-client version.
Best regards,
Ganesh Singamshetty.- v-achippaCommunity Support
Hi MadsMAndersen,
As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided by the user for the issue worked? or let us know if you need any further assistance.
Thanks and regards,
Anjan Kumar Chippa
- v-achippaCommunity Support
Hi @MadsMAndersen,
We wanted to kindly follow up to check if the solution provided by the user for the issue worked? or let us know if you need any further assistance.
Thanks and regards,
Anjan Kumar Chippa
- masonreed11tAdvocate II
This looks like a valid SDK issue. Your workaround is reasonable, but ideally listener exceptions should be contained by the SDK instead of surfacing as global errors. Hopefully the Power BI team can clarify if this is expected behavior or a bug.
- MadsMAndersenNew Member
Hi v-achippa
Sorry for the late reply, I have been quite busy lately.I have now reproduced the behavior in the Power BI Embedded Analytics Playground using the sample report.
let loadedResolve; let reportLoaded = new Promise((resolve) => { loadedResolve = resolve; }); let renderedResolve; let reportRendered = new Promise((resolve) => { renderedResolve = resolve; }); // Capture errors that escape into the browser's global error pipeline. window.addEventListener("error", function (event) { console.error("GLOBAL WINDOW ERROR", { message: event.message, error: event.error, filename: event.filename, line: event.lineno, column: event.colno }); }); window.addEventListener("unhandledrejection", function (event) { console.error("GLOBAL UNHANDLED REJECTION", event.reason); }); // Get Power BI models. models = window["powerbi-client"].models; function embedPowerBIReport() { let accessToken = EMBED_ACCESS_TOKEN; let embedUrl = EMBED_URL; let embedReportId = REPORT_ID; let tokenType = TOKEN_TYPE; let config = { type: "report", tokenType: tokenType === "0" ? models.TokenType.Aad : models.TokenType.Embed, accessToken: accessToken, embedUrl: embedUrl, id: embedReportId, permissions: models.Permissions.All, settings: { panes: { filters: { visible: true }, pageNavigation: { visible: true } }, bars: { statusBar: { visible: true } } } }; let embedContainer = $("#embedContainer")[0]; report = powerbi.embed(embedContainer, config); report.off("loaded"); report.on("loaded", function () { console.log("Power BI loaded event received"); loadedResolve(); throw new Error( "Intentional reproduction: error thrown inside Power BI loaded event listener" ); }); report.off("error"); report.on("error", function (event) { console.error("POWER BI SDK ERROR EVENT", event.detail); }); report.off("rendered"); report.on("rendered", function () { renderedResolve(); report.off("rendered"); }); } embedPowerBIReport(); await reportLoaded; await reportRendered;Result:
Power BI loaded event received
GLOBAL WINDOW ERROR
Uncaught Error: Intentional reproduction: error thrown inside Power BI loaded event listenerThe stack passes through:
raiseCustomEvent @ powerbi.js
Service.handleEvent @ powerbi.js
receiveMessage @ code-eval-wrapperThe registered Power BI error event is not invoked for this listener exception. This confirms that an exception thrown by a host event listener escapes the SDK event pipeline and reaches the browser’s global error handler.
- v-achippaCommunity Support
Hi MadsMAndersen,
Thank you for the detailed response. Based on the code you have shared, the exception is being thrown from your application's loaded event handler, not from the power bi SDK.
- Since this exception is not handled within the callback, it goes to the browser's global error handler (window.onerror), which is expected JavaScript behaviour. The power bi error event only reports errors from the SDK/report and does not catch exceptions thrown in custom event handlers.
- To avoid the global error, handle the exceptions within your event listener for example, using a try/catch block.
If you want the SDK itself should automatically handle such exceptions, you can submit it as a product feedback request for the engineering team to review.
Fabric Ideas - Microsoft Fabric Community
Thanks and regards,
Anjan Kumar Chippa