iFrame Embedded Preparation
Learn how to embedded the Embedded Preparation in your own application and discover how manage events
The Embedded Preparation can be embedded directly in your own application, so your users never leave your product. Once embedded, the portal sends JavaScript events to the parent page through window.postMessage, letting you hide your loader, react when the user is done, and recover from an expired link or session.
To embed the portal, you first need a preparation link. To learn how to generate one, follow the detailed guide here: Embedded Preparation - Generate an Embedded Preparation link.
Use the preparation link exactly as returned by the API. It already carries the parameters the portal needs to open a session. A URL rebuilt by hand from a signature request id cannot be authenticated and produces an
invalidevent.
A preparation link expires 10 minutes after it is generated, and the link itself can be used several times during that window: reloading the page that hosts the iFrame is safe as long as the link is still valid. After that, the user gets an
expiredevent withreason: "link"and needs a new link.
Once the portal is open, the preparation session lasts one hour. When it runs out while the user is still working, the portal emits
expiredwithreason: "session".
You never need a new Signature Request to recover from an expired link or session. As long as the Signature Request is still in
draftstatus, you can generate as many preparation links as you want.
Embed the portal
Use the link returned by Generate an Embedded Preparation link as the source of an iFrame.
<iframe src="{{preparation_link}}" />In Production, embedding the Embedded Preparation is restricted for security reasons. You must explicitly configure how and where the Signing Flow can be embedded.
Go to your iFraming settings page to manage your settings.
Events emitted
Every message shares the same envelope:
{ type: "yousign", event, signature_request_id }. Only expired carries an extra key.
| Event | Emitted when | Extra payload |
|---|---|---|
ready | The portal is authenticated and displayed. Sent once per session. | — |
done | The user completed the preparation with the Done button. | — |
back | The user clicked the Back button. | — |
expired | The preparation link has expired, or the one-hour session ran out while the user was working. | `reason: "link" |
invalid | The link could not be opened: malformed or revoked link, or a technical failure. | — |
field.added | A field was successfully added to a document. | — |
field.deleted | A field was successfully deleted. | — |
ping | Every 5 seconds while the portal is displayed. Healthcheck, for debug only. | — |
Listen on the parent page
Always check that the message comes from Yousign before acting on it.
window.addEventListener('message', function (e) {
// Check that the message really comes from Yousign
if (e.origin !== 'https://yousign.app' || e.data.type !== 'yousign') {
return;
}
switch (e.data.event) {
case 'ready':
console.log('Preparation portal is displayed, you can hide your loader');
break;
case 'done':
console.log('User completed the preparation');
// If a Done redirect URL is configured, the iFrame navigates itself right after
break;
case 'back':
console.log('User clicked Back');
// If a Back redirect URL is configured, the iFrame navigates itself right after
break;
case 'expired':
console.log('Preparation stopped:', e.data.reason);
// Request a new preparation link from your backend, then reload the iFrame
break;
case 'invalid':
console.log('The preparation link could not be opened');
break;
case 'field.added':
case 'field.deleted':
console.log('Fields changed, fetch them again from the API');
break;
// Healthcheck, for debug only
case 'ping':
console.log('Ping - preparation portal is loaded');
break;
}
});Handling patterns
ready: Hide your own loading state. The event is sent once, so do not rely on it to detect a reload.done: if a Done redirect URL is set on the Signature Request, the iFrame navigates to it right after the event. Otherwise the portal shows its success screen and stays in place, and redirecting the user afterwards is up to you.back: emitted when the user clicks the Back button. The button is displayed when it is enabled on the Custom Experience attached to the Signature Request. If a Back redirect URL is set on the Signature Request, the iFrame navigates to it immediately after the event; if not, the event is the only signal and the portal stays in place, so the parent page decides what to do.expiredGenerate a new preparation link and load it in the iFrame. The same Signature Request can be reused as long as it is still indraftstatus.reason: "link"means the link had already expired when the portal tried to open it, for instance because the page was reloaded more than 10 minutes after the link was generated;reason: "session"means the one-hour session ran out mid-use.invalid: the link cannot be recovered. Check that you are using the link returned by the API, unchanged.field.added/field.deletedThese are signals, not payloads. Fetch the current fields from the API to know the exact state. A single event covers one successful operation, so deleting several fields at once emits onefield.deleted, while duplicating or pasting several fields emits onefield.addedper created field. Moving, resizing, or editing the settings of a field emits nothing, and adding or removing an option of a radio group emits nothing either: the group itself is the observable unit.pingUse it for debugging only. If your page also embeds the signature iFrame, both send apingcarrying asignature_request_id; the signature one also carries asigner_id.
Configure the redirect URLs
Both Done and Back can redirect the iFrame to a URL of your own, set on the Signature Request when you create or update it:
{
"embedded_preparation": {
"redirect_urls": {
"done": "https://your-app.com/done",
"back": "https://your-app.com/back"
}
}
}The iFrame navigates itself; it never touches the parent page. The done and back events are always emitted before the navigation, so a parent listening for them keeps control.
Displaying the Done and Back buttons is driven by the Custom Experience attached to the Signature Request, not by these URLs: a button enabled without a matching URL emits its event and leaves the portal in place.
Testing in Sandbox
During your integration in the Sandbox environment, you can bypass the domain verification by adding the query parameter disable_domain_validation=true to the preparation link used as a source of the iFrame.
https://yousign.app/embedded-preparation/{{signature_request_id}}?...&sandbox=true&disable_domain_validation=true
A Sandbox link already carries sandbox=true, so there is nothing else to add. This bypass only works in Sandbox: in production, authorizing your domains stays mandatory.
Events behave exactly the same in Sandbox as in production, and the origin to check is the same: https://yousign.app.
Updated 4 days ago

