-1

I am working on PowerBI custom visual. What I want to do is access outer most body tag to attach an element using jQuery but I am not able to do that as all custom visual are loaded in an iFrame and my current window object only points to iframe container area.

How can I access outside from this iFrame to parent window (topmost)? I know and I have gone through similar answers on StackOverflow and GitHub. I even liked this answer here. How to communicate between iframe and the parent site?

Now the problem is, It is the same domain iframe as what I see in URL i.e. https://app.powerbi.com.

The second thing is while developing custom visual in VSC or other editors using PBIVIZ APIs, you only have access to iframe container where your custom visual is loaded. Thus you can't access code that is there outside or at the parent location of this iFrame. I believe it is part of PowerBI environment itself.

Third thing is, there is no configuration available to remove or load custom visual without iFrame itself. Please let me know if there is one.

This is also done for one of the Power BI's own visual (date slicer) which doesn't load any iFrame when you inspect that code in the browser.

Does anyone have any Idea? GitHub issue for more information: https://github.com/microsoft/PowerBI-visuals/issues/544

Aakash Kumar
  • 893
  • 4
  • 15
  • 38
  • 1
    This reference is [`top`](https://developer.mozilla.org/en-US/docs/Web/API/Window/top), and specifically to the body of top, it's `top.document.body`. – Teemu May 10 '19 at 06:02
  • I tried it already. My visual fails when I try this in my constructor or update method. – Aakash Kumar May 10 '19 at 06:06
  • You asked for a reference to the top most body, that's what you've got. If you have an other problem, then, please post a new question about that specific problem. See https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem – Teemu May 10 '19 at 06:10
  • I mean. I have access to a window or similar object like top. When I access top or window. My visual only points iFrame contained area. Not the main body which is containing this iFrame. – Aakash Kumar May 10 '19 at 06:12
  • If I try to access top.document, it gives me the error Exception: DOMException: Blocked a frame with origin "null" from accessing a cross-origin frame. at invokeGetter. I know it's cross-origin but I don't have access to parent code as it is powerBI application and I only have access to iframe containing area. – Aakash Kumar May 10 '19 at 10:14
  • See https://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy , but in all cases, you've to be able to control both the sources. – Teemu May 10 '19 at 10:29
  • @Teemu Thank you and Yes, I know I need access to both sources but I don't have access to it. In my developer environment, what I have control is what is coming in that iframe, outside of it, it is completely PowerBI application code so developers don't have access to it. – Aakash Kumar May 10 '19 at 11:00
  • There is no option to get access to parent DOM. The visuals execute inside iframe by security reasons and also iframe isolates in functionality aspects. (ex. prevent changing styles of Power BI interface) – Ilfat Galiev May 20 '19 at 12:01
  • @AakashKumar do you have a `src` or `srcdoc` with a valid value? That error message looks familiar... – zer00ne May 24 '19 at 13:57

1 Answers1

0

There is no option to get access to parent DOM. The visuals execute inside iframe by security reasons and also iframe isolates in functionality aspects. (ex. prevent changing styles of Power BI interface)