Repository navigation
fix(printer): allow about:blank popups and auto-fallback to browser print when no hardware printer is configured - #418
Merged
Conversation
Contributor
Greptile SummaryThe PR enables secure blank print popups and falls back to browser/system printing when no usable hardware printer is configured.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| frontend/src/hooks/usePrinter.ts | Adds browser-print fallback while preserving connected WebUSB and configured backend printer paths. |
| main/index.ts | Allows blank print popups with constrained Electron window settings while retaining URL checks. |
| main/printers/thermal.ts | Resolves usable non-WebUSB printers consistently and separates preview fallback formatting from physical dispatch. |
| main/routes/printers.ts | Aligns bill-printer resolution with frontend ordering and permits hardware-free 80 mm previews. |
| main/security/url-allowlist.ts | Extends the local-window allowlist to blank URLs used by browser printing. |
| tests/printer-fallback-and-popup-verification.ts | Exercises popup handling, printer fallback, fast rejection, and receipt formatting behavior. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Bill print requested] --> B{Print method}
B -->|Browser| E[Open browser print popup]
B -->|ESC/POS| C{Usable non-WebUSB printer configured?}
C -->|Yes| D[Dispatch through backend printer]
C -->|No| F[Show fallback notification]
F --> E
G[Preview requested] --> H{Usable printer configured?}
H -->|Yes| I[Format using selected printer profile]
H -->|No| J[Format with default 80 mm profile]
Reviews (3): Last reviewed commit: "Merge branch 'main' into fix/printer-aut..." | Re-trigger Greptile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
fix(printer): allow about:blank popups and auto-fallback to browser print when no hardware printer is configured
What Changed
about:blankand empty window URLs in the URL allowlist and Electron window opener handler with tailored popup dimensions (800x600) and menu bar settings for browser print popups.usePrinterwhen ESC/POS printing is requested without a configured or connected hardware printer.Risk Assessment
✅ Low: The changes cleanly allow about:blank popups in Electron for browser printing and provide safe fallback to browser print dialogs when no thermal hardware printer is configured.
Testing
Exercised URL allowlist popup permissions ('about:blank' and empty URL), Electron window open handler for print popups, zero-printer backend receipt preview fallback and hardware failure fast-rejection, frontend store auto-fallback to browser printing with toast notifications when no thermal printer is configured, and captured full visual screenshots and rendered HTML artifacts across 80mm/58mm formats.
/Users/gurkiratkhaira/.no-mistakes/evidence/01M0EKM3F11WJKFGM6FVP4QF3B/popup_window_simulation.png)Evidence: Print Receipt popup window HTML
/Users/gurkiratkhaira/.no-mistakes/evidence/01M0EKM3F11WJKFGM6FVP4QF3B/fallback_receipt_80mm_preview.png)Evidence: Fallback 80mm thermal receipt HTML
/Users/gurkiratkhaira/.no-mistakes/evidence/01M0EKM3F11WJKFGM6FVP4QF3B/fallback_receipt_58mm_preview.png)Evidence: Fallback 58mm thermal receipt HTML
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 2 issues found → auto-fixed ✅
frontend/src/hooks/usePrinter.ts:156- The fallback check on line 156 matches all cases where 'hw' is falsy under 'escpos' mode, making lines 163-196 unreachable dead code and causing active WebUSB printer connections to be bypassed in favor of browser print dialogs.main/printers/thermal.ts:796- prepareReceipt injects a dummy network printer (127.0.0.1:9100) when no printer is configured; direct callers of printReceipt without an explicit printer check will attempt a TCP connection to localhost instead of failing fast like printKOT.🔧 Fix: Fix WebUSB fallback check and unconfigured printer dispatch
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
npm run test:url-allowlistnpm run test:printer-apinpm run test:bills-print-apinpm run test:printerNODE_PATH=./frontend/node_modules npx tsx tests/browser-receipts.test.tsNODE_PATH=./frontend/node_modules npx tsx tests/printer-fallback-and-popup-verification.ts✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.