> **Source:** https://knowledge.leegality.com/document-execution/api/sdks/sdk-reference > **Site:** Leegality Knowledge Base — https://knowledge.leegality.com > **About:** Leegality is a document execution platform covering eSigning, stamps, NeSL, workflows, and REST API integration. > **Navigation:** Every article on this site has a plain-text version at `.txt` (this format). To get an index of all articles with their `.txt` links, read: https://knowledge.leegality.com/llms.txt > **AI Guide:** For instructions on how to navigate this knowledge base as an AI agent, read: https://knowledge.leegality.com/ai-readable.txt --- # SDK Reference The Sender SDK is a single JavaScript file hosted by Leegality. It defines one global (`LeegalitySenderSDK`) with one method (`open()`). No npm install, no build step, no framework requirement. ## Loading the script Add the script tag for the environment matching your backend's gateway host. ```html ``` | Environment | Script URL | |---|---| | Production | `https://workflow.leegality.com/sdk/v1/leegality-sender-sdk.js` | | Sandbox | `https://sandbox-workflow.leegality.com/sdk/v1/leegality-sender-sdk.js` | The script exposes `window.LeegalitySenderSDK` as soon as it loads. ## `LeegalitySenderSDK.open(options)` Opens the sending journey in a popup window and subscribes to its lifecycle events. ### Parameters | Parameter | Type | Required | Description | |---|---|---|---| | `url` | string | Yes | The signed launch URL from the [Draft API](https://knowledge.leegality.com/document-execution/api/sdks/draft-api). Pass it through untouched — the SDK validates that the four signed parameters (`exp`, `credentialId`, `signature`, `d`) are present and warns in the console if any are missing, but never edits the URL. | | `onEvent` | function | Yes | Called as `onEvent(envelope, messageEvent)` whenever a lifecycle event arrives. `envelope` is `{ eventType, eventData }`. The three events are `COMPLETED`, `SUBMISSION_FAILED`, and `SUBMISSION_PENDING`. See [Lifecycle Events](https://knowledge.leegality.com/document-execution/api/sdks/events) for payloads and handling. Only messages from the popup window, from Leegality's origin, stamped with `source: 'leegality-sdk'`, reach this callback. | ### Return value `open()` returns an object with three properties: | Property | Type | Description | |---|---|---| | `tab` | `Window` or `null` | The popup window handle. `null` means the browser blocked the popup (see [Popup blocking](#popup-blocking)). The window is cross-origin, so `tab.closed` is the main thing you can read from it. | | `journeyId` | string | A client-side identifier for this journey, available immediately when `open()` returns. Events also carry a `journeyId` in `eventData`, but the value may differ from the one `open()` returned — the event's `journeyId` is assigned by the popup after boot. Use `workflowRunContextId` (not `journeyId`) to correlate events with your backend records. | | `close()` | function | Stops listening for events and closes the popup if it is still open. Safe to call more than once. Closing a live journey means the sender loses their progress, so leave it to the sender unless you have a specific reason. | ### Example ```js const session = LeegalitySenderSDK.open({ url: draft.data.url, onEvent: (envelope) => { console.log(envelope.eventType, envelope.eventData); }, }); // session.tab → the popup window (null if blocked) // session.journeyId → client-side ID (may differ from eventData.journeyId) // session.close() → stop listening + close the window ``` ## Popup window The SDK opens the journey in a popup window sized at 1440 x 900 pixels, centred on the current screen. The size is fixed — the journey screens are not responsive. ### Popup blocking Browsers block popups they cannot trace to a user action. If there is an `await` between the user's click and the `open()` call, the browser treats it as an unsolicited popup and blocks it. **The fix:** fetch the launch URL **before** the click, then call `open()` synchronously inside the click handler. ```js let launchUrl = null; // Fetch first async function prepare() { const res = await fetch('/api/leegality/draft', { method: 'POST' }); launchUrl = (await res.json()).url; } prepare(); // Open on click — no await between click and open() button.addEventListener('click', () => { const session = LeegalitySenderSDK.open({ url: launchUrl, onEvent: handleEvent, }); }); ``` If `session.tab` comes back `null`, the popup was blocked. Prompt the user to allow popups for your domain.