Emda

Page API (window.Emda)

For your website running in the kiosk: print, print receipts, open the cash drawer and read the scale from the page’s own JavaScript. To control kiosks from a server, see the Remote API. Working with an AI coding agent? See AI agents.

Emda adds a window.Emda object to pages when page integration or the receipt printer is on. It’s set up before the page’s own scripts run; to be safe, wait for it:

function start() {
  /* use Emda */
}
if (window.Emda) start();
else window.addEventListener('emda:ready', start, { once: true });

The @emda/web package

Optional helpers and types for the page API (coming soon to npm). The kiosk provides window.Emda itself; the package just makes it easier to use, and adds a fake kiosk for development:

npm install @emda/web
import { whenReady, printReceipt, waitForStableWeight } from '@emda/web';
import { installMock } from '@emda/web/mock';

// On your computer there's no kiosk: show receipts in a preview and fake the scale.
if (import.meta.env.DEV) installMock({ receipt: 80, scale: 0 });

const emda = await whenReady(); // the kiosk's API, or null in a normal browser
const result = await printReceipt('<h1>Thank you</h1>', { cut: true });
if (!result.ok) showError(result.error); // 'unavailable' outside Emda, or the printer's error

Without the package, use window.Emda directly as below; the types are at emda.io/emda.d.ts.

Page integration

With Settings → Remote API → Allow page integration on, every page in the kiosk gets:

Emda.version; // "0.1.0"
await Emda.getDeviceInfo(); // { deviceId, appVersion, platform }
Emda.print(); // same as window.print(): follows the printing settings
await Emda.printUrl('https://shop.example/invoice/7'); // that page on the normal printer → { ok } / { ok:false, error }
Emda.home();
Emda.reload();
Emda.back();
Emda.forward();

It’s off by default: any page shown in the kiosk can read the device ID while it’s on.

Receipt printer (Emda.receipt)

With Settings → Devices → Use a receipt printer on, pages get Emda.receipt (whether or not page integration is on). Receipts are HTML: Emda draws them at the printer’s width (58 mm paper = 384 px, 80 mm = 576 px; 1 CSS pixel = 1 printer dot), in black on white, and prints the result as an ESC/POS raster image. Hebrew, fonts, tables and images print exactly as they look. Scripts in the receipt HTML don’t run; use inline styles and inline (data:) or web images.

const result = await Emda.receipt.print(
  `
  <div style="text-align:center;font-size:40px;font-weight:bold">Emda Café</div>
  <div dir="rtl">קפה הפוך — ₪14.00</div>
`,
  { cut: true, openDrawer: false },
); // options override the settings; both optional
// → { ok: true } or { ok: false, error: 'receipt-disabled' | 'printer-unreachable' | 'printer-failed' | 'render-failed' }

// Or a receipt page by address: loaded at paper width with the kiosk's cookies (signed-in
// pages work) and its own scripts; it must be allowed by the kiosk's site rules.
await Emda.receipt.printUrl('https://pos.example/order/42/receipt', { cut: true });

await Emda.receipt.openDrawer(); // cash drawer on the printer's drawer port

Connections: a network printer by address (raw TCP, port 9100 unless set), or a USB printer installed in Windows (sent raw through its print queue; a “Generic / Text Only” or the vendor’s driver works). Tip: design for the width — e.g. font-size: 24px is a normal receipt line, 40px a heading.

Scale (Emda.scale)

With Settings → Devices → Use a scale on, pages get Emda.scale (whether or not page integration is on). Emda talks to the scale itself — SHEKEL scales (Beaver protocol: Basic, Advanced 1, Advanced 2) and Wintec S373 boards — so no separate scale service is needed. How the scale connects depends on the device: on Windows a serial / USB COM port or the network; on Android a USB-to-serial adapter (OTG), a built-in serial port or the network; on iPad the network only (the scale itself, or a serial-to-network adapter such as USR-TCP232 or Moxa NPort, since iPads can’t open serial adapters). It has the same shape as maxshop’s ScaleService, and readings have the same fields as shekel-scaled’s GET /api/v1/weight:

const r = await Emda.scale.getWeight();
// { status: 'stable' | 'unstable' | 'zero' | 'negative' | 'overweight' | …, statusRaw, weight: 1.234,
//   hasWeight: true, stable: true, overweight: false, underweight: false, raw: 'WGT:1 1.234P 0.000' }

Emda.scale.isUsableReading(r); // stable && hasWeight && in range && weight > 0

const { promise, cancel } = Emda.scale.waitForStable({
  timeoutMs: 30000,
  intervalMs: 400,
  onReading: (reading, errorCode) => showLive(reading, errorCode), // every poll
});
const stable = await promise;

await Emda.scale.zero();
await Emda.scale.setTare(0.28); // kg; Emda.scale.clearTare()
await Emda.scale.setUnitPrice(12.9);
await Emda.scale.getTotal(); // SHEKEL only
await Emda.scale.getFirmware();

Failures reject with { code, status, message }, codes as in shekel-scaled: not_connected (503), timeout (504), bad_response (502), bad_request (400), not_supported (501 — Wintec has no price / total / checksum / reboot), and cancelled from waitForStable(...).cancel().

For a page that also runs outside Emda: const scale = window.Emda?.scale ?? ScaleService;

Docs