metabase icon indicating copy to clipboard operation
metabase copied to clipboard

shareable URLs for iframed embedded dashboards, with param filter values

Open snarfed opened this issue 8 years ago • 11 comments

hi all! we're working on a public embedded dashboard with filter widgets, and we'd love a way to let users share URLs to specific queries they've come up with, ie including filter values.

this is obviously doable when you load a public/embedded dashboard at the top level in the browser. when you filter, it updates the URL in the browser to include query params for each filter value. this feels very natural, and sharing works great, without needing any explicit UI affordance. yay!

i've been looking for a way to do the same thing when a dashboard is embedded in an iframe. obviously this needs some support from the outer application/ HTML that's embedding the dashboard, since it controls its URL. i'm happy to write JS to eg look at the dashboard iframe's src attribute and grab its query params, but from what i can tell, iframed dashboards don't update src when their filters change. i don't know if this is an HTML/DOM limitation, or just something that's not implemented in metabase, or a bug...?

i know i could hack metabase's Content-Security-Policy script-src to let my embedding HTML reach inside the iframe's document, and i might end up doing that, but it feels ugly.

another option would be a new "permalink" UI affordance in embedded dashboards. the drawback is, that would be the dashboard's direct URL, not the embedding parent's URL...unless we add a new setting for that, which starts to maybe feel overcomplicated.

the last idea i have is to let users provide optional arbitrary HTML header and footer snippets that metabase would inject wrap around the dashboard HTML it serves. sounds like a bad idea for all sorts of reasons.

apologies for rambling. thanks in advance for considering this!

:arrow_down: Please click the :+1: reaction instead of leaving a +1 or update? comment

snarfed avatar Jun 06 '18 17:06 snarfed

related past discussions in #2595, #3681.

snarfed avatar Jun 06 '18 17:06 snarfed

i've implemented this in #7817 by hacking metabase to notify the parent document of param changes with Window.postMessage(), and also propagate params from URL fragments back in by updating the iframe's src URL query params. example JS in that PR.

snarfed avatar Jun 06 '18 21:06 snarfed

Can this be done w/private embeds? Looking for a way to let private embed users save off their favorite filter choices.

MarcGJA avatar Jan 19 '20 22:01 MarcGJA

probably! I've forgotten the auth details for private embeds, but if it's HTTP header, that should be orthogonal, and if it's query param, you can merge those, so either should be doable.

snarfed avatar Jan 19 '20 23:01 snarfed

Private embeds using JWT, for example, gives an iframe url source in the form: src="http://www.yourapp.com/embed/dashboard/JWT-generate-token#bordered=true&titled=true" So something along these lines isn't applicable: https://data.color.com/v1/#gender=M&age=51-55

The only way I know of to save off filter values would be to create a set of dropdown menus in the embed app completely outside of Metabase, store them in the app's db for retrieval, and feed in the values as parameters. Is there an easier way or is that about the size of it?

MarcGJA avatar Jan 31 '20 01:01 MarcGJA

In #7817 @tlrobinson mentioned there would be an alternative to postMessage? Is this already in the repo?

Trying to find a way to have auto-refresh for embedded dashboard without losing the configured filters...

winnephew avatar Feb 18 '20 14:02 winnephew

@winnephew According to this https://github.com/metabase/metabase/pull/11773, it was merged, but it's missing some setting (in the UI, I figure).

petrusgomes avatar Mar 12 '20 15:03 petrusgomes

@petrusgomes Thanks, but I don't seem to get it working in v34.3, I'd expect something like

iframe.contentWindow.postMessage({ metabase: { type: 'location', location:'/dashboard/39?[myfilterstring]' }}, '*');

to work in changing the filters.

I just checked and don't see the changes when checking the file in the current release.

As for the missing "embedding_app_origin", I checked the code and it should return null which in turn gets interpreted as '*' by postmessage so the message should still be deployed.

@tlrobinson Will this be included in the next release?

winnephew avatar Mar 16 '20 10:03 winnephew

@winnephew From https://html.spec.whatwg.org/multipage/web-messaging.html

A target origin can be specified using the targetOrigin member of options. If not provided, it defaults to "/". This default restricts the message to same-origin targets only.

Currently MB_EMBEDDING_APP_ORIGIN is only implemented in the Enterprise Edition for FullApp Embedding.

Related #12069 and #9494

flamber avatar Mar 16 '20 11:03 flamber

Indeed, I only quickly tested in the developer console and it came through, so I misinterpreted the behavior, thanks for pointing that out.

In that case we would definitely need some changes in order to be able to receive messages from metabase.

Is it planned to include the origin parameter? Otherwise having it default to '*' might be the way to go for now.

winnephew avatar Mar 16 '20 11:03 winnephew

@winnephew I think #9494 is the issue to follow. There's definitely going to be some changes, but I cannot tell you a specific release. It will not default to * - as it means no security - with how it's implemented currently. This might change in in future.

flamber avatar Mar 16 '20 12:03 flamber