Forum Discussion
Pass value to the embedded app from custom visual
Hi,
has anyone been able to find a solution for this case?
I was able to "postMessage" from "visual" and receive it in my host app like this:
constructor(options: VisualConstructorOptions) {
this.target = options.element;
}
public update(options: VisualUpdateOptions) {
const value = dataView.single.value.toString();
(this.target as any).ownerDocument.defaultView.parent.parent.postMessage(value, "*");
}
Basically: visual sandbox iframe window -> embed report iframe window -> app window.
However, it already looks rather hacky, and they might one day decide to introduce another iframe or remove one, causing this postMessage communication to fail.
The Local Storage API ( https://learn.microsoft.com/en-us/power-bi/developer/visuals/local-storage?tabs=v1 ) might be an alternative for communication, but I haven't tried it yet.