PrintBase
  • Product
  • Pricing
  • Docs
  • Resources
PrintBase/Guides/Print from your language or framework

Silent printing from browser JavaScript, via your backend

Browsers will not silently print to a USB device from a public website. Call your backend, and let the backend call the print API.

For Frontend developers who need a receipt without window.print

Overview

window.print() always involves the browser's dialog and the user's printer choice. A page on https://shop.example cannot open a raw socket to a printer, and Chrome's private-network rules also block casual calls to localhost device services.

The pattern that works is: the button calls your backend; the backend holds the API key; the backend posts the job; the agent in the shop prints. The browser receives a job id, not a printer handle.

The agent's optional local port 127.0.0.1:17891 accepts the same JSON, but only from localhost or a printbase.cloud origin. Your shop's origin is rejected on purpose.

Integration steps

  1. 01

    Do not put the key in the bundle

    Search the built JavaScript. If the key is there, rotate it.

  2. 02

    Call your backend

    The button posts the order id, not the print payload, unless the backend trusts that user.

  3. 03

    Backend posts the job

    Authorization Bearer, printer_code from your database, content_type matching the device.

  4. 04

    Show queued, then poll

    The UI can poll your backend, which polls GET /v1/print-jobs/{id}.

  5. 05

    Do not point the browser at 127.0.0.1:17891 in production

    That origin check will fail, and it would only reach a printer on the visitor's laptop anyway.

Node.js

// Backend endpoint the browser calls: it then prints
const res = await fetch('https://api.printbase.cloud/v1/print-jobs', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.PRINTBASE_API_KEY}`,
    'Content-Type': 'application/json',
    'Idempotency-Key': orderId,
  },
  body: JSON.stringify({
    printer_code: Number(process.env.PRINTER_CODE),
    content_type: 'pdf',
    content: pdf.toString('base64'),
    copies: 1,
  }),
});
if (!res.ok) throw new Error(`PrintBase ${res.status}: ${await res.text()}`);
const job = await res.json();
// { id: "job_abc", status: "queued" }

Details for this setup

Why the dialog exists

The browser treats printing as a user decision. Silent print is a server-side job plus a local agent, not a hidden iframe.

Local port allow-list

Code in the agent allows an empty Origin, localhost, 127.0.0.1, ::1, and printbase.cloud hosts. Other origins get 403.

Questions

Can I hide the dialog with CSS?

No. That is not a supported browser feature, and it would still print on the visitor's machine.

What about QZ Tray or DYMO's local service?

Those are local agents the browser talks to, with their own certificates or ports. This design moves the call to your server. See the comparison pages.

A kiosk page on localhost?

The local agent port can accept that origin. A public kiosk URL should still use the cloud API so the key is not in the page.

How does the cashier know it failed?

Your UI reads the job status. The browser will not throw a printer error by itself.

Related guides

  • Print without a dialog in JavaScript

    Browsers will not silently print from a public page. The workable pattern is your backend plus the print API, not a hidden window.print.

  • Print labels from a React admin panel

    A React button calls your API. Your API prints the label. The React bundle does not contain the print key or a direct call to the printer.

  • How to auto-print receipts and labels from Bubble

    Call the print API from a Bubble backend workflow. Do not put the API key in a page workflow the browser can see. No Bubble plugin is included.

  • Print shipping labels from a Next.js route

    Print from a Next.js route handler on the server. Do not call the API from a client component. The key stays in the server environment.

Free plan: 100 jobs a month on one computer, no card.

Create a free accountRead the API docs
PrintBase

PrintBase connects your applications to physical printers anywhere - securely, reliably, and in real time.

Product
Receipt PrintingLabel PrintingDashboardDevicesWebhooks
Resources
DocsBlogStatusAPI ReferenceDownloadPrintBase vs PrintNodePrintNode PricingFAQ
Guides
All guidesIntegrationsPrintersCode samplesComparisonsUse casesTroubleshooting
Company
ContactSecurityPrivacy

© 2026 Aveniq Technologies OÜ. All rights reserved. PrintBase is a service of Aveniq Technologies OÜ.

PrivacyTermsRefunds