Use Userflow with iframes

Prev Next

Userflow works inside iframes in your app without extra setup, as long as the iframe is on the same domain as the page around it. For iframes on another domain, you can still guide users with speech bubbles, or run Userflow.js inside the iframe too.

When does Userflow work in iframes without extra setup?

Userflow supports an iframe directly when:

  • The page and the iframe are on the same domain.

    • ✅ Same domain: the page is https://example.com/app and the iframe is https://example.com/components/dashboard.

    • ✅ Different subdomains of the same domain, with the subdomain work-around: the page is https://app.example.com/ and the iframe is https://components.example.com/dashboard.

    • ❌ Different domains: the page is https://example.com/app and the iframe is https://other.com/components/dashboard. See What if my iframe is on a different domain?

  • The <iframe> element doesn't have a sandbox attribute.

In these cases, install the Userflow.js snippet in the top-level page only, not inside the iframe. Nested iframes (iframes inside iframes) work too, as long as they follow the same rules.

Work-around for iframes on a different subdomain

If the page and the iframe are on different subdomains of the same domain, such as app.example.com and components.example.com, add this line to both documents:

document.domain = 'example.com'

This tells the browser the two frames may talk to each other. You may want to check this with your security team first.

Since Chrome 115 (July 2023), Chrome only allows this if your app sends the HTTP header Origin-Agent-Cluster: ?0 with the HTML of both the page and the iframe. See Chrome's note on the change.

What if my iframe is on a different domain?

If the iframe is on a completely different domain, Userflow can't select elements inside it from the top-level page. There are two ways around this.

Option 1: Use speech bubbles for the iframe steps

The simplest fix is to use speech bubbles, which don't point at an element, for the steps about the iframe. Add a Next button so users move through each step.

Speech bubble steps with a Next button

Option 2: Run separate flows in the page and the iframe

To use tooltips inside the iframe:

  1. Install Userflow.js in both the top-level page and the iframe. This is the one case where it goes in both.

  2. Split the flow into one flow for the page and one for the iframe. Start the iframe flow from the last step of the page flow with Add action > Start flow. See How to start flows or checklists.

  3. When you select elements for the iframe flow, use the iframe's own URL, not the top-level page's URL.

Selecting an element using the iframe's URL

Stop content showing twice. With Userflow.js running in both places, the same flow, checklist or banner can appear twice, once from each. Open the content that should only show in the top-level page and add a Temporarily hide flow condition using Current page that matches the iframe's URL.

What if an iframe covers my whole app?

If an iframe covers the entire page, install Userflow.js inside the iframe and use the iframe's URL when you select elements. If Userflow.js also runs in the top-level page, content can show twice: add a Temporarily hide flow condition using Current page that matches the iframe's URL to the content that should only show outside the iframe.