Skip to content

fix(printing): resolve printWindow.onload race condition in browser thermal printing fallback #184

Closed

Description

@khaira777

Summary

Browser thermal receipt printing fails because printWindow.onload is assigned after document.close() on a synchronously constructed about:blank window, causing the onload handler and window.print() to never fire.

Root Cause

In frontend/src/lib/printer/PrinterService.ts, DOM nodes are inserted directly using replaceChildren(), followed by document.close(). The onload event handler is attached after document.close(). Because document.close() does not dispatch a load event when document.write() was not used, the onload event has already passed, so printWindow.print() is never called.

Why It Matters

When fallback browser printing is triggered, the receipt popup window remains open as a blank tab without bringing up the native print dialog.

Expected Behavior

printWindow.print() and printWindow.close() are called immediately after DOM manipulation and document.close() complete.

Actual Behavior

The onload callback never fires, leaving the popup open and failing to print the receipt.

Affected Files

  • frontend/src/lib/printer/PrinterService.ts

Suggested Implementation Direction

Call printWindow.print() and printWindow.close() directly after appending DOM nodes and calling document.close() instead of wrapping them in printWindow.onload.

Activity

  1. added theissue type on Jul 29, 2026
  2. removed theissue type on Jul 29, 2026
  3. itsbkm commented on Jul 29, 2026

    @itsbkm
    Contributor

    Fixed in a0b41f1: printWindow.print()/close() now run directly after document.close() instead of being wrapped in onload, which never fired since the window's DOM was populated via replaceChildren/importNode rather than document.write().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions