With the new HubSpot Forms (V3 static embed), the iframe now has a src pointing to https://js.hsforms.net/ui-forms-embed-components-app/frame.html, triggering the Same-Origin Policy. This means we can no longer access the iframe’s contentDocument, so any DOM query or event binding fails.
But this breaks because accessing the iframe’s DOM is blocked.
What we’re looking for:
Does HubSpotFormsV4 expose a method to retrieve the form DOM element from the event. HubSpotFormsV4.getFormFromEvent(event) exists but doesn’t return a full DOM element or something we can work with.
Is there any official workaround or supported way to hook into form field events in the new embed model (e.g. keyup on email field)?
Can HubSpot provide an option to inject raw HTML or custom script blocks directly into the form or its wrapper, so that tracking/enrichment code can live within the same DOM context (i.e., not blocked by iframe restrictions)?
We’d really appreciate guidance on how to safely extend or interact with forms under the new embedding behavior while remaining compliant with browser security policies.
I am not aware of any options for working directly with the DOM inside of an iframe for the new HubSpot forms. You can still work with the form field values through the abstracted API calls to retrieve and set the values of a field.
For example, in order to mimic something like the "keyup" event listener, you could use poll the value periodically to look for changes with the getFieldValue() method.
However, I assume that the goal of those event listeners would be to then manipulate the DOM based on user's input, so ultimately it might still not fit your use case.
✔️ Did this post help answer your query? Help the community by marking it as a solution.
From what I can see, it seems that this is working as expected.
In the new editor, you can't interact with the framed form, you need to use the developer form (equivalent of raw html) but you do need to have a Pro+ subscription to get that embed code, see screenshot below.
Let me know if you cannot find the Developer Form @svirchenko? If that's the case, please send me via private message your Hub ID.
Thanks so much to all of you for your help!
Have a lovely day! Bérangère
HubSpot’s AI-powered customer agent resolves up to 50% of customer queries instantly, with some customers reaching up to 90% resolution rates. Learn More.
I am not aware of any options for working directly with the DOM inside of an iframe for the new HubSpot forms. You can still work with the form field values through the abstracted API calls to retrieve and set the values of a field.
For example, in order to mimic something like the "keyup" event listener, you could use poll the value periodically to look for changes with the getFieldValue() method.
However, I assume that the goal of those event listeners would be to then manipulate the DOM based on user's input, so ultimately it might still not fit your use case.
✔️ Did this post help answer your query? Help the community by marking it as a solution.
You’re right — the logic works as follows: once the email is validated, the script sends a request to retrieve data, which is then used to populate values into hidden fields. If any of those hidden fields don’t receive a value, they should be made visible.
With your suggestion, I’m able to get the first part of the script working — thank you for that!
Can HubSpot provide an option to inject raw HTML or custom script blocks directly into the form or its wrapper, so that tracking/enrichment code can live within the same DOM context (i.e., not blocked by iframe restrictions)?
Unable to Access New HubSpot Form in iframe (Same-Origin Policy Issue)
SOLVE
Hi @sylvain_tirreau , no - according to the documentation, there’s no hs-form-event:onFormReady event. I also tried listening for it just in case, but it doesn’t trigger anything.
Unable to Access New HubSpot Form in iframe (Same-Origin Policy Issue)
SOLVE
@sylvain_tirreau I’m currently embedding a form using the provided share code, which inserts the form inside an iframe. I’d really prefer an option without iframe but this is how your embed implemented.
Previously, with legacy forms, the iframe was still present but didn’t include a src attribute — this allowed me to access the form elements (like the email input) using querySelector. However, with the new forms, the iframe has a src pointing to a different origin, which prevents any DOM access due to the Same-Origin Policy.
Unable to Access New HubSpot Form in iframe (Same-Origin Policy Issue)
SOLVE
@sylvain_tirreau I just tried this script with legacy form and new form just by switching form ids, it works with legacy form, but doesn't work with new form: onFormReady event is not fired; and it still creates new form in iframe with src attribute, and legacy form without src attribute
If you can put your form in raw HTML, that will solve the iframe problem, but I'm not sure it works with anything other than legacy forms (in your legacy form, tab "style & preview").
Is there any chance that support for inserting custom HTML inside the form might be introduced in the near future? That would be a great solution — even if the form remains in an iframe, having the script in the same scope would allow much more flexibility and will keep Same-Origin Policy.
In the mean while, I'd love to check on this with our Top Experts: Hi @Anton, @sylvain_tirreau and @stefen are you using the new form in iframe? If yes, do you have any insights to share with @svirchenko, please?
Have a nice day and thanks so much in advance for your valuable contributions! ❤️ Bérangère
HubSpot’s AI-powered customer agent resolves up to 50% of customer queries instantly, with some customers reaching up to 90% resolution rates. Learn More.
Otherwise, you could also use the Developer Embed Code if you are on a professional (and higher) subscription?
Let us know if this works?
Thanks and have a great weekend! Bérangère
HubSpot’s AI-powered customer agent resolves up to 50% of customer queries instantly, with some customers reaching up to 90% resolution rates. Learn More.
Unable to Access New HubSpot Form in iframe (Same-Origin Policy Issue)
SOLVE
Hi @BérangèreL , thank you so much for taking the time to look into this — I really appreciate your help, and thank you again @sylvain_tirreau for your input as well!
Just to clarify: the Developer Embed Code you’re referring to seems to be part of the HubSpot CRM Embed feature, which is intended for displaying interactive HubSpot interfaces inside custom apps. However, in my case, I’m simply embedding a HubSpot form on my website using the provided embed code — not embedding CRM UI components.
Unfortunately, the suggestion doesn’t quite solve the issue I’m facing with the new form iframe structure and restricted access due to the src attribute.
Thanks again, and I hope you both have a great weekend as well!
From what I can see, it seems that this is working as expected.
In the new editor, you can't interact with the framed form, you need to use the developer form (equivalent of raw html) but you do need to have a Pro+ subscription to get that embed code, see screenshot below.
Let me know if you cannot find the Developer Form @svirchenko? If that's the case, please send me via private message your Hub ID.
Thanks so much to all of you for your help!
Have a lovely day! Bérangère
HubSpot’s AI-powered customer agent resolves up to 50% of customer queries instantly, with some customers reaching up to 90% resolution rates. Learn More.