Forum Discussion
Unhandled error from powerbi-client embed event listener is surfaced as global browser Script error
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 listener
The stack passes through:
raiseCustomEvent @ powerbi.js
Service.handleEvent @ powerbi.js
receiveMessage @ code-eval-wrapper
The 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.
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