gradio icon indicating copy to clipboard operation
gradio copied to clipboard

Communication between gradio(iframe) and the parent site

Open SmartDever02 opened this issue 11 months ago • 3 comments

I am using an iframe to embed my gradio app, but how can I make communication between my parent app and gradio app? https://stackoverflow.com/questions/9153445/how-to-communicate-between-iframe-and-the-parent-site From this link, I tried to send message from parent website to this iframe (gradio app) But I don't see any possible way to get that message in gradio.

SmartDever02 avatar Mar 05 '24 12:03 SmartDever02

We need more information about what you are trying to do.

pngwn avatar Mar 05 '24 17:03 pngwn

Thanks for replying @pngwn So I have a Laravel + React web application and I have a gradio app embed inside an iframe in one of React page. I would like to pass username (authenticated username) from react or laravel => gradio. So that I can keep logging of who used my gradio app when they click on a button in gradio app or at some point. I have couple of approaches in my mind like

  1. if I try to pass username as query parameter e.g http://localhost:5000/&username=john I want to get john in my gradio app

  2. I tried to use window.postMessage https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage so that I can send a message from parent website to gradio iframe app but how can I get that message in gradio app?

Please help me :pray:

SmartDever02 avatar Mar 05 '24 17:03 SmartDever02

Hi @SmartDever02 can you please provide a minimal code example that we can use to reproduce the issue above? See: https://stackoverflow.com/help/minimal-reproducible-example

abidlabs avatar Mar 07 '24 14:03 abidlabs

Will close for now, but happy to reopen with more details. If you can please share the code of what approach you tried, and what happened vs. what you expected, that'll help us look into this.

abidlabs avatar Mar 08 '24 23:03 abidlabs

@SmartDever02 Did you find a way to pass authentification data to an embedded gradio iframe?

ccharest93 avatar May 25 '24 13:05 ccharest93

@ccharest93 I setup fast api server and mounted different gradio apps with different routes. and then for different users, I embed different gradio apps with different slugs in the route. e.g let say I have users and I have unique id for the users right? like uuid With that uuid I mount a new gradio app and embed it in my website. No authentication data passed to the iframe and I use uuid from the route path as identifier.

SmartDever02 avatar May 25 '24 15:05 SmartDever02