GitHub user dosubot[bot] added a comment to the discussion: How can a host app capture embedDashboard iframe errors (404/5xx) in Sentry?
<!-- Greeting --> Hi @Y-Havryliv! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the superset team. <!-- Answer --> Currently, there is no built-in mechanism in the Superset Embedded SDK or the embedDashboard function to directly notify the host application when the iframe fails to load due to errors like 404 (not found) or 401 (unauthorized). The SDK's promise resolves when the iframe is injected, but it does not propagate errors from the iframe's internal loading process or HTTP failures. The SDK does not emit postMessage events for these error cases either, which is why your attempts to catch promise rejections or listen for postMessage events did not work. >From the Superset codebase, errors such as a missing dashboard (404) or access >denied (401/403) are handled server-side and result in the iframe returning an >error page or blank content, but this is not surfaced to the parent window via >JavaScript events or messages >([source](https://github.com/apache/superset/blob/master/superset/commands/dashboard/embedded/exceptions.py), > >[source](https://github.com/apache/superset/blob/master/superset/embedded/view.py)). Standard browser limitations prevent the parent window from accessing the iframe's content or errors directly due to cross-origin restrictions. However, you can use the iframe's onLoad and onError events to detect some loading issues, but these do not distinguish between successful loads and error pages (e.g., a 404 page still triggers onLoad). A common workaround is to periodically check the iframe's contentWindow.location or contentDocument for known error markers, but this only works if the iframe is same-origin, which is not the case for most Superset deployments. For cross-origin iframes, the most reliable approach is to implement a custom error reporting mechanism in the embedded Superset instance. For example, you could modify the embedded dashboard template to send a postMessage to the parent window when a fatal error occurs (such as rendering a 404 or 401 page). The host app could then listen for these messages and forward them to Sentry. However, this requires changes on the Superset side. In summary: - There is no out-of-the-box way to capture these errors from the host app using the current SDK or embedDashboard API. - Standard browser events and postMessage do not provide this information for cross-origin iframes. - Capturing these errors reliably would require a change to the embedded Superset frontend to emit postMessage events on error. If you control the Superset deployment, consider adding a postMessage in the error boundary or error page of the embedded dashboard frontend ([example location](https://github.com/apache/superset/blob/master/superset-frontend/src/embedded/index.tsx)). The host app could then listen for these messages and report them to Sentry. If you need guidance on how to implement this in Superset, let me know! <!-- Dosu Comment Footer --> *To reply, just mention my name [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/b8f30f52-63d3-46f6-9037-2579aebecd2a?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/b8f30f52-63d3-46f6-9037-2579aebecd2a?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/b8f30f52-63d3-46f6-9037-2579aebecd2a?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/b8f30f52-63d3-46f6-9037-2579aebecd2a?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/b8f30f52-63d3-46f6-9037-2579aebecd2a?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/b8f30f52-63d3-46f6-9037-2579aebecd2a?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/b8f30f52-63d3-46f6-9037-2579aebecd2a?feedback_type=other)</sup> [](https://go.dosu.dev/discord-bot) [](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/discussions/33600) GitHub link: https://github.com/apache/superset/discussions/33600#discussioncomment-13294627 ---- This is an automatically sent email for [email protected]. To unsubscribe, please send an email to: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
