Add in-app support to an Electron app
Give your Electron app a "Get help" button that shares your app's window with your support team, with consent, in your own name, colour and logo.
Give your Electron app a "Get help" button: your customer clicks it and agrees, and your support team sees your app's window in the GaiaDesk console — and, if you allow it, guides it — without the customer installing anything.
GaiaDesk's Electron SDK is the npm package @gaiadesk/embed-native. It works in Electron's main process (and in plain Node desktop apps) on macOS, Windows and Linux. Its TypeScript is open source (MIT), at github.com/Gaia-Desk/gaiadesk-embed-electron. It wraps the same signed native library, libgaiadesk_embed, as GaiaDesk's other embed SDKs; the library is a prebuilt binary that ships, unmodified, inside your app. For how in-app support fits together, see In-app support.
What your customer sees
One button. Your app shows "Get help" wherever you put it.
A consent dialog in your colours. It names your company, says what will be shared (this app's window, or the screen if you chose it) and whether your team will be able to guide it. Nothing is shared until the customer agrees. It is attached to the window that asked (a sheet on macOS, an owned window on Windows), never behind it. For a live preview, choices, who is waiting and a stored receipt, use the consent step.
An indicator for as long as anything is shared. "Sharing with Acme · Stop sharing", drawn by the library on top of your app. Your app cannot hide it. In a guided session it also has Pause control. While the customer waits for an agent it offers Cancel instead, and your customer can drag it anywhere (see The indicator).
A support code. Nine digits your customer can read to an agent over the phone.
When the session ends — the customer presses Stop sharing, your app stops it, the session expires, or the app quits — sharing stops at once and nothing is left behind: the library installs nothing, runs no service and writes nothing to disk.
What your support team sees
Agents open Support in the GaiaDesk console, see the waiting customer (with the details your backend passed) and join, or type the support code. Only your own account and team can join, and only team members with a support seat.
1. Install the package
npm install @gaiadesk/embed-nativeVersion 0.4.0 (libgaiadesk_embed 0.4.0) needs Node 18 or later. It has no runtime dependencies besides the native library for your platform.
2. The native library
npm installs the library for the machine you install on as an optional dependency, one package per platform:
Platform | Package |
|---|---|
macOS, Apple silicon |
|
macOS, Intel |
|
Windows x64 |
|
Linux x64 (glibc) |
|
Each holds one file, gaiadesk-embed.<platform>.node. Two things to get right when you package:
Keep optional dependencies on. If your install skips them, reinstall with
npm install --include=optional. Install on (or for) each platform you build, so the right package is there.Unpack
*.nodefrom the asar archive. With electron-builder or Forge, add*.nodetoasarUnpack: Node cannot load a native addon from inside an asar.
The package looks for the library in this order: the path in $GAIADESK_EMBED_NATIVE_BINARY, a gaiadesk-embed.<platform>.node beside the package, then the platform package. If none loads, the error says what it tried.
3. Create sessions on your backend
Your server decides who may get help. It creates the support session with a secret API key (scope support) and hands the app only its embed token:
curl -s -X POST https://api.gaiadesk.net/v1/support/sessions \
-H "Authorization: Bearer $GAIADESK_API_KEY" -H "Content-Type: application/json" \
-d '{"mode": "view", "customer": {"name": "Ada", "plan": "pro"}}'The response carries embed_token (gdemb_…), which your app passes to GaiaDeskEmbed.start as embedToken. mode is view (look only) or cobrowse (see Guided sessions).
Never ship the secret key in your app: the embed token is all it needs. The full request is in the support API reference.
4. Add the button
The session runs in the main process: the library's indicator lives on Electron's main thread. Your page asks for help over IPC.
// main.ts
import { BrowserWindow, dialog, ipcMain } from "electron";
import { EmbedError, GaiaDeskEmbed, windowIdOf } from "@gaiadesk/embed-native";
let help: GaiaDeskEmbed | null = null;
async function askConsent(win: BrowserWindow): Promise<boolean> {
// The library's own dialog on macOS and Windows; null on Linux, so ask yourself.
const answer = GaiaDeskEmbed.requestConsent("Acme", "window");
if (answer !== null) return answer;
const { response } = await dialog.showMessageBox(win, {
message: "Share this window with Acme support?",
detail: "Acme support will see this window, not the rest of your screen. You can stop at any time.",
buttons: ["Share", "Don't share"],
cancelId: 1,
});
return response === 0;
}
ipcMain.handle("get-help", async (event, embedToken: string) => {
const win = BrowserWindow.fromWebContents(event.sender);
if (!win || (help && !help.isEnded)) return;
if (!(await askConsent(win))) return;
try {
help = GaiaDeskEmbed.start(
{ embedToken, company: "Acme", windowId: windowIdOf(win) },
{ consentGranted: true },
(e) => {
if (e.type === "code") win.webContents.send("help-status", `Your support code is ${e.code}`);
if (e.type === "ended") win.webContents.send("help-status", "Sharing ended.");
},
);
} catch (e) {
if (e instanceof EmbedError) win.webContents.send("help-status", `Could not start (${e.code})`);
else throw e;
}
});
ipcMain.handle("stop-help", () => help?.stop());// preload.ts
import { contextBridge, ipcRenderer } from "electron";
contextBridge.exposeInMainWorld("support", {
getHelp: (embedToken: string) => ipcRenderer.invoke("get-help", embedToken),
stop: () => ipcRenderer.invoke("stop-help"),
});Your page fetches the embed token from your backend and calls window.support.getHelp(token) from its "Get help" button.
start refuses with EmbedError code consent_required unless it gets the consent step's consentToken / consentReceipt, or consentGranted literally true — and that must be your customer's answer to a consent dialog, the library's or your own. help.ended is a promise of the end reason, and help.on(listener) adds more listeners. Events arrive on the JS thread, in order:
Event | |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The consent step (recommended)
Ask with GaiaDesk's consent step rather than requestConsent + consentGranted: true or a dialog of your own. It shows your customer a live preview of exactly what support will see (masked rects blacked out), lets them choose (view only or click-and-type, app logs, this window or the screen), says who is waiting and for how long, links your privacy policy and terms, can auto-decline after a timeout, is localized (14 languages, right to left included) and themed to your app, and leaves a receipt stored on the session (see Proof of consent). A decline or timeout ends the waiting request at once (customer_declined / consent_timeout). Needs version 0.4.0 (libgaiadesk_embed 0.4.0); an older binary throws unsupported from the consent functions.
In your page (the usual choice in Electron): the @gaiadesk/consent web component, with this package's consentBridge running in the main process (the native library takes the preview and makes the receipt) and reached over IPC, so the renderer and preload keep Electron's sandbox on:
// main.ts
import { ipcMain } from "electron";
import { consentBridge, GaiaDeskEmbed } from "@gaiadesk/embed-native";
ipcMain.handle("gaiadesk:preview", (_e, o) => consentBridge.preview!(o));
ipcMain.handle("gaiadesk:record-consent", (_e, input) => consentBridge.recordConsent(input));
ipcMain.handle("gaiadesk:start-help", (_e, d) =>
GaiaDeskEmbed.start({ embedToken, company: "Acme", guided: true, consentToken: d.consent_token, consentReceipt: d.receipt }));
// preload.ts (sandboxed)
import { contextBridge, ipcRenderer } from "electron";
contextBridge.exposeInMainWorld("gaiadeskConsent", {
preview: (o: unknown) => ipcRenderer.invoke("gaiadesk:preview", o),
recordConsent: (input: unknown) => ipcRenderer.invoke("gaiadesk:record-consent", input),
});
contextBridge.exposeInMainWorld("acme", { startHelp: (d: unknown) => ipcRenderer.invoke("gaiadesk:start-help", d) });
// renderer.ts
import "@gaiadesk/consent";
const el = document.body.appendChild(document.createElement("gaiadesk-consent"));
el.bridge = (window as any).gaiadeskConsent;
const d = await el.open({ company: "Acme", guided: true, choices: { offer_logs: true } });
el.remove();
if (d.decision === "accepted") await (window as any).acme.startHelp(d);Keep the sandbox on: only the preload's contextBridge reaches the page, and the native library stays in the main process. consentBridge posts an accepted receipt with start. When your backend already created the session, expose createConsentBridge({ embedToken, sessionId }) instead (its waitInfo over IPC too): it also shows who is waiting, and every receipt (a decline too) is posted at once.
The library's dialog (main process; macOS and Windows, and X11 on Linux), with the same options:
import { consent, GaiaDeskEmbed, parentWindowOf } from "@gaiadesk/embed-native";
const d = consent({ company: "Acme", guided: true, theme: { accent: "#5b4cf0" }, timeout_seconds: 120,
parent_window: parentWindowOf(win) }, (e) => track(e.type));
if (d.decision === "accepted")
GaiaDeskEmbed.start({ embedToken, company: "Acme", guided: true, consentToken: d.consent_token, consentReceipt: d.receipt });
// "unavailable": no dialog on this system: use <gaiadesk-consent>.The options (ConsentStepOptions) are the library's (snake_case, every key optional), the same object the web component takes: company, capture, guided, masked, brand_color, logo_png_base64, parent_window, theme (appearance, background, surface, text, accent, radius, font_family, button_style), locale, wording (per-key overrides), wording_version, choices (offer_guided, offer_logs, offer_capture), privacy_url, terms_url, timeout_seconds, preview, server / embed_token / session_id (then the library shows who is waiting and posts the receipt), app_version, window_id, masks (as start's). The decision: { decision: "accepted" | "declined" | "timeout" | "unavailable", choices, consent_token, receipt }. With a receipt, start's capture and guided follow your customer's choices.
| the library's dialog → the decision; events |
|
|
| your own UI's answer made into a receipt ( |
| the |
|
|
start options | an accepted decision's |
Your name, colour and logo
company puts your name on the consent dialog and on the "Sharing with Acme · Stop sharing" indicator. Add your colour and logo in the start options, and pass an options object to requestConsent for the dialog in your look:
import { readFileSync } from "node:fs";
const brand = {
brandColor: "#0f766e",
logoPngBase64: readFileSync("logo.png").toString("base64"),
};
const agreed = GaiaDeskEmbed.requestConsent({ company: "Acme", capture: "window", ...brand });
// … then
GaiaDeskEmbed.start({ embedToken, company: "Acme", windowId: windowIdOf(win), ...brand }, { consentGranted: agreed === true });Option | |
|---|---|
| "Sharing with Acme". Required. |
| Accent colour, |
| A PNG, at most 256 KiB, as base64. |
A colour that is not #RRGGBB throws EmbedError (bad_config) before anything native runs; a logo the library refuses throws bad_config too, and is never read as a decline. Colour and logo need version 0.2.0 or later of the library; package 0.4.0 installs library 0.4.0.
The options object also takes masked: true (the dialog says private fields stay hidden; pass the masks too) and parentWindow (see below).
The indicator
The indicator starts top right, clear of the window that asked; indicatorPosition ("top-left", "top-right", "bottom-left", "bottom-right") picks another corner. When your customer drags it you get indicator_moved { x, y }: keep it (the library writes nothing to disk) and pass it back as indicatorOrigin next time; it is restored while it fits on a screen. parentWindow names the window that asked: the consent dialog becomes a sheet on it on macOS and is owned by it on Windows.
import { parentWindowOf } from "@gaiadesk/embed-native";
const parentWindow = parentWindowOf(win); // the HWND on Windows; undefined on macOS and Linux
GaiaDeskEmbed.requestConsent({ company: "Acme", masked: true, parentWindow });
GaiaDeskEmbed.start({ embedToken, company: "Acme", parentWindow, indicatorOrigin: saved }, { consentGranted: true },
(e) => { if (e.type === "indicator_moved") saved = { x: e.x, y: e.y }; });On macOS getNativeWindowHandle() is the window's NSView* and the library takes only an NSWindow*, so parentWindowOf returns undefined there and the library uses your app's key window (the one your user just clicked).
Until an agent is admitted the indicator offers Cancel. Cancel (or help.stop()) then ends the session with customer_cancelled, and the request leaves your support team's queue at once; it is also the session's end_reason in the API and in webhooks.
Guided sessions
By default your team can only look. To let them click and type, create the session as cobrowse (mode: "cobrowse") and pass guided: true in the start options — both ends must want it. Pass guided to requestConsent too, so the dialog says so. Their input is delivered inside your app's own process, only to your app's windows, only while your app is in front, never under a mask, and at most 20 actions a second. Your customer can pause it at any time from the indicator; your app can too (help.setPaused(true)). Every request arrives as an action event, with a reason when it was not applied (view_only, control_paused, rate_limited, not_focused, outside_app, masked, unsupported). Linux is view-only.
Keeping things private
Your app's window only. By default (
capture: "window") the library shares one window: the one you name withwindowId: windowIdOf(win), or your app's frontmost.capture: "app"shares your app's windows; other apps, notifications and the desktop are never captured, unless you choosecapture: "screen".Masks. Mark anything sensitive — card numbers, balances, passwords — as a masked rect. It is painted black before a frame is encoded. Pass the rects you already know as
masksin the start options: only start-time masks are guaranteed to cover the very first frame.help.setMaskedRects(rects)replaces them afterwards, and[]clears them. If the window cannot be located, the whole picture is blacked out.Consent every time. The library refuses to start without it; there is no setting that skips the dialog or hides the indicator.
Mask rects are { x, y, w, h }, relative to the top-left corner of the shared window's frame (title bar included): points on macOS, and on Windows and Linux pixels (Electron's DIPs times the display's scale factor). maskRectsFromContent converts rects measured in your page:
// preload.ts: CSS pixels × page zoom
import { ipcRenderer, webFrame } from "electron";
const z = webFrame.getZoomFactor();
const r = document.querySelector("#card")!.getBoundingClientRect();
ipcRenderer.send("masks", [{ x: r.left * z, y: r.top * z, width: r.width * z, height: r.height * z }]);// main.ts (win: the shared BrowserWindow, help: the running session)
import { screen } from "electron";
import { maskRectsFromContent } from "@gaiadesk/embed-native";
ipcMain.on("masks", (_e, boxes) => {
const scale = screen.getDisplayMatching(win.getBounds()).scaleFactor;
help?.setMaskedRects(maskRectsFromContent(win, boxes, scale));
});Send them again whenever the layout changes, the window is resized, or it moves to another display.
What each platform supports
Capture | Guided input | Consent dialog | |
|---|---|---|---|
macOS (Apple silicon and Intel) | window, app, screen | yes | native, branded |
Windows x64 | window, app, screen | yes | native, branded |
Linux x64 (glibc) | window, app, screen | view-only | the consent step (X11 or XWayland), else yours ( |
macOS: your app needs the Screen Recording permission; macOS asks your customer the first time a session starts.
Linux:
requestConsenthas no native dialog (it returnsnull). The consent step works:<gaiadesk-consent>in your page anywhere, orconsent()'s dialog on X11 or XWayland (unavailableon Wayland without XWayland). Or show your own — Electron'sdialog.showMessageBox, in your look — and pass its answer tostart.
What is and is not permitted
You may: ship the prebuilt library unmodified inside your app, with its licence in your app's notices; offer support sessions to your own customers; brand the dialog and indicator with your name, colour and logo.
You may not: modify, decompile or re-sign the library separately from your app; hide or imitate the indicator; start a session without your customer's agreement.
The package's TypeScript is MIT; the native library is under the GaiaDesk Native Binary Licence (LICENSE-BINARY in the package). See the package's README for every option, event and error code.