A "Get help" button for your Electron (or Node) desktop app: in-app remote support and a screen sharing SDK for Electron, for customer support with optional guided control. Your customer clicks it and agrees; your app's window is shared with your support team, who see it in the GaiaDesk console's Support page and, if you allow it, guide it: click and type inside your app only, while it is in front.
- TypeScript, typed events, no runtime dependencies besides the prebuilt native library for your platform.
- A built-in consent step: a live preview of what support will see, your customer's choices, who
is waiting, localized, with a stored receipt; in your page (
<gaiadesk-consent>+consentBridge) or as the library's own dialog. - A visible "Sharing with Acme" indicator, owned by the library, for as long as anything is shared.
- Only your app's window by default. Rects you mask (card numbers, balances) are painted out of every frame before it is encoded.
- View-only unless you opt in; guided input is delivered inside your app's own process, never through the operating system's input stream.
npm install @gaiadesk/embed-nativenpm installs the native library for your platform as an optional dependency
(@gaiadesk/embed-native-<platform>): macOS (Apple silicon and Intel), Windows x64, and Linux x64
(glibc). Keep optional dependencies on (--include=optional), and when you package with
electron-builder or Forge, unpack *.node files from the asar archive (asarUnpack).
Your server creates a support session with a secret API key (scope support) and hands the app 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"}}'
# → {"id": "ss_…", "join_code": "123456789", "embed_token": "gdemb_…", …}Then, in the main process (the library's indicator lives on Electron's main thread):
import { dialog, type BrowserWindow } from "electron";
import { GaiaDeskEmbed, EmbedError, windowIdOf } from "@gaiadesk/embed-native";
async function getHelp(win: BrowserWindow, embedToken: string) {
// 1. Ask. The library's dialog where there is one, Electron's elsewhere (Linux).
const agreed =
GaiaDeskEmbed.requestConsent("Acme", "window") ??
(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,
})).response === 0;
if (!agreed) return;
// 2. Start, with the answer.
try {
const help = GaiaDeskEmbed.start(
{ embedToken, company: "Acme", windowId: windowIdOf(win) },
{ consentGranted: agreed },
(e) => {
if (e.type === "code") console.log("support code", e.code);
if (e.type === "joined") console.log(e.agent ?? "an agent", "is viewing");
},
);
console.log("ended:", await help.ended);
} catch (e) {
if (e instanceof EmbedError) console.error(e.code, e.message); // bad_token, consent_required, …
else throw e;
}
}examples/electron-help-desk is a complete app ("Acme Desk"): a masked card number, a Buy
button, a token field and Get help.
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, is localized (14 languages, right to left
included) and themed to your app, and leaves a receipt (when, which words — version and hash —,
what was chosen, the OS user and app version) that is stored on the session and shown in the
console. A decline or timeout ends the waiting request at once (customer_declined /
consent_timeout). Needs the 0.4.0 binaries (libgaiadesk_embed 0.4.0).
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);consentBridge posts an accepted receipt with start. When your backend already created the
session, expose createConsentBridge({ embedToken, sessionId }) instead: 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.
start refuses (EmbedError with code consent_required) without the consent step's
consentToken / consentReceipt (above) or consentGranted literally true, and that must be
your user's answer to a consent dialog: GaiaDeskEmbed.requestConsent
(the library's own, modal, on macOS and Windows) or your own. requestConsent returns true or
false, or null where the platform has no native dialog (Linux): show your own, e.g. Electron's
dialog.showMessageBox. Say who will see what, and whether they can act.
Your customer sees your brand, not ours: company on the consent dialog and the indicator, plus
(libgaiadesk_embed 0.2.0) your colour and logo.
import { readFileSync } from "node:fs";
const brand = {
brandColor: "#0f766e", // "#RRGGBB": accent, stripe, Stop button
logoPngBase64: readFileSync("logo.png").toString("base64"), // a PNG, at most 256 KiB
};
const agreed = GaiaDeskEmbed.requestConsent({ company: "Acme", capture: "window", ...brand });
// … then
GaiaDeskEmbed.start({ embedToken, company: "Acme", windowId: windowIdOf(win), ...brand }, { consentGranted: agreed === true });A colour that is not #RRGGBB throws EmbedError (bad_config) before anything native runs; a
logo the library refuses (not a PNG, over 256 KiB) throws bad_config from requestConsent or
start, never reads as a decline. Linux has no native consent dialog (null): show your own, in
your look.
Pass the regions you already know as masks in the start options: an agent can join straight
away, and only start-time masks are guaranteed to cover the first frame. setMaskedRects
replaces them afterwards. Mask rects are relative to the top-left corner of the shared window's frame (title bar
included): points on macOS, physical pixels (GetWindowRect) on Windows. From a web page, measure
in the renderer and convert in the main process:
// preload.ts (contextIsolation): CSS pixels × page zoom
const z = webFrame.getZoomFactor();
const r = el.getBoundingClientRect();
ipcRenderer.send("masks", [{ x: r.left * z, y: r.top * z, width: r.width * z, height: r.height * z }]);
// main.ts
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));
});maskRectsFromContent moves page rects by the content area's offset in the frame
(getContentBounds() minus getBounds()), and on Windows only multiplies by the display's
scale factor (Electron is per-monitor DPI aware; the library takes physical pixels there). Send the
masks again whenever the layout changes, the window is resized, or it moves to another display.
setMaskedRects([]) clears them. Masks fail closed: if the window cannot be located, the whole
picture is painted out.
Sessions are view-only by default. Guided input (the agent clicks, scrolls, types and presses a few keys) needs both:
guided: truein your options, and- a
"cobrowse"support session (your backend'smode).
Even then, a request is applied only when it lands on your app's own windows while your app is
focused, not under a mask, at most 20 a second. Your customer can Pause control (and allow it
again) on the indicator; you can too, with setPaused(true). Every request is reported as an
action event with applied and a reason (view_only, control_paused, rate_limited,
not_focused, outside_app, masked, unsupported).
Linux is view-only in this release: X11 has no way to deliver input to one app only.
While anything is shared the library shows its own "Sharing with " panel with Stop
sharing (and, in guided sessions, Pause / Allow control). Frames are sent only while it is up.
Stop ends everything; you get ended with reason stopped. Cancel on the indicator (or stop())
before any agent was admitted ends with customer_cancelled, and the request leaves your support
team's queue at once.
Placement (libgaiadesk_embed 0.3.0): the indicator starts top right, clear of the window that
asked. indicatorPosition 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. parentWindow names the window that asked (the consent dialog
becomes a sheet on it on macOS, owned by it on Windows):
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). If you have the NSWindow* from your own native code,
pass it as parentWindow directly.
GaiaDeskEmbed.start(options, { consentGranted }?, onEvent?) |
start sharing; throws EmbedError (.code) |
consent(options?, onEvent?) |
the consent step's dialog → the decision (see The consent step); events consent_shown { locale, wording_version }, consent_accepted { choices }, consent_declined { reason } |
preview(request?) |
{ png_base64, width, height, masked_count }: one frame of what support would see (capture_unavailable without permission) |
recordConsent(input) |
your own UI's answer made a receipt (surface: "embedded") → the decision |
consentBridge, createConsentBridge(session?) |
the <gaiadesk-consent> bridge (preview, recordConsent; with a session also waitInfo) |
waitInfo({ embedToken, sessionId, server? }) |
{ team_name, team_avatar_url, estimated_wait_seconds } |
help.on(listener) |
listen to events; returns an unsubscribe function |
help.stop() |
end the session (safe to call again); ended follows with app_stopped (customer_cancelled before any agent was admitted) |
help.setMaskedRects(rects) |
replace the masked rects ({ x, y, w, h }[]) |
help.setPaused(paused) |
pause or resume guided input |
help.ended |
a promise of the end reason, resolved exactly once |
GaiaDeskEmbed.requestConsent(company, capture?, guided?) |
true / false, or null with no native dialog |
GaiaDeskEmbed.requestConsent({ company, capture?, guided?, brandColor?, logoPngBase64?, masked?, parentWindow? }) |
the same dialog in your look (see Branding); masked says private fields stay hidden |
GaiaDeskEmbed.buildInfo() |
{ version, testSource, codec, os, arch } of the native library |
windowIdOf(win) |
a BrowserWindow's CGWindowID (macOS) / HWND (Windows), for windowId |
maskRectsFromContent(win, rects, scaleFactor) |
page rects → mask rects (see Masking) |
parentWindowOf(win) |
a BrowserWindow's HWND (Windows) for parentWindow; undefined on macOS and Linux (see The indicator) |
| Option | |
|---|---|
embedToken |
gdemb_…, from your backend |
company |
shown on the consent dialog and the indicator |
server |
the GaiaDesk server (default https://gaiadesk.net) |
capture |
"window" (default): one window of your app; "app": all of its windows; "screen": the display it is on (opt-in) |
windowId |
the window to share (windowIdOf(win)); default: your app's frontmost |
guided |
allow guided input (default false; see Guided mode) |
fps |
1 to 30 (default 15) |
masks |
rects painted out from the first frame (see Masking) |
brandColor |
"#RRGGBB", the indicator's accent (see Branding) |
logoPngBase64 |
a PNG (at most 256 KiB) as base64, shown small on the indicator |
parentWindow |
the window that asked (parentWindowOf(win)); default: your app's focused window |
indicatorPosition |
"top-left", "top-right" (default), "bottom-left" or "bottom-right" |
indicatorOrigin |
{ x, y } from an indicator_moved event you kept: restored while it fits on a screen |
consentToken, consentReceipt |
an accepted decision's consent_token and receipt (see The consent step) |
| Event | |
|---|---|
state |
{ state, choices? }: starting, waiting (with choices: what the session runs with), connected, ended |
code |
{ code, sessionId, mode, expiresAt }: the session is up; code is the support code your customer reads to the agent |
joined / left |
{ agent } (the agent's email, or null) / {} |
control |
{ allowed }: guided input paused (false) or allowed again |
action |
{ action, applied, reason }: an agent's request and what became of it |
indicator_moved |
{ x, y }: your customer dragged the indicator; keep it for indicatorOrigin |
error |
{ code, message } |
ended |
{ reason }: stopped, app_stopped, customer_cancelled, customer_declined / consent_timeout (the consent receipt said no, or the dialog timed out), disconnected, expired or error. Always last, exactly once |
Events arrive on the JS thread, in order. Types this version does not know are ignored.
Refusal codes include consent_required, bad_token, bad_server, bad_config, bad_rects,
wrong_thread, capture_unavailable and unsupported (the consent step on a binary before 0.4.0).
$GAIADESK_EMBED_NATIVE_BINARY (a path to a .node file), then a
gaiadesk-embed.<platform>.node beside this package, then the @gaiadesk/embed-native-<platform>
package. If none loads, the error says what was tried.
npm ci
npm test # build, then the tests (a fake native binding)
GAIADESK_EMBED_NATIVE_BINARY=/path/to/gaiadesk-embed.darwin-arm64.node npm test # + live testsThe live tests only check refusals the library makes before touching the network; they never start a session. The example:
cd examples/electron-help-desk && npm install && GAIADESK_EMBED_TOKEN=gdemb_… npm startIt prints one JSON line per event; GAIADESK_DEMO_AUTOSTART=1, GAIADESK_DEMO_GUIDED=1,
GAIADESK_SERVER and (for automated tests only) GAIADESK_DEMO_TEST_CONSENT=1 drive it, and
stdin stop / pause / resume control the session.
- npm: @gaiadesk/embed-native
- Guide: Embedding GaiaDesk on gaiadesk.net
- Embed SDKs: Web · Electron · macOS (Swift) · C/C++ and Qt · .NET · iOS · Android · React Native · Flutter
- Changelog · Security policy
- This package's TypeScript (the facade, the helpers and the example): MIT (
LICENSE). - The native library it loads (
gaiadesk-embed.<platform>.node, from the@gaiadesk/embed-native-<platform>packages): closed source, under the GaiaDesk Native Binary Licence (LICENSE-BINARY).