diff --git a/static/src/js/pos_receipt_printer.js b/static/src/js/pos_receipt_printer.js index 025df02..4fb5ad2 100755 --- a/static/src/js/pos_receipt_printer.js +++ b/static/src/js/pos_receipt_printer.js @@ -70,14 +70,6 @@ patch(PosPrinterService.prototype, { console.log('[BluetoothPrint] Element tag:', el?.tagName); console.log('[BluetoothPrint] Element classes:', el?.className); - // Check if Web Bluetooth API is available - if (!navigator.bluetooth) { - console.log('[BluetoothPrint] Web Bluetooth API not available, using browser print dialog'); - await this._printViaBrowserDialog(el); - return true; - } - console.log('[BluetoothPrint] Web Bluetooth API available'); - // Check if a Bluetooth printer is configured (from localStorage) const storage = new BluetoothPrinterStorage(); @@ -101,6 +93,14 @@ patch(PosPrinterService.prototype, { } } + // Check if Web Bluetooth API is available + if (!navigator.bluetooth) { + console.log('[BluetoothPrint] Web Bluetooth API not available, using browser print dialog'); + await this._printViaBrowserDialog(el); + return true; + } + console.log('[BluetoothPrint] Web Bluetooth API available'); + const config = storage.loadConfiguration(posConfigId); if (!config || !config.deviceId) { @@ -196,6 +196,21 @@ patch(PosPrinterService.prototype, { async _printViaBrowserDialog(el) { console.log('[BluetoothPrint] Opening browser print dialog...'); + // Detect if mobile OS (Android, iOS, etc.) or WebView where iframe printing doesn't work + const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); + + if (isMobile) { + console.log('[BluetoothPrint] Mobile or WebView environment detected. Falling back to native printWeb on main window.'); + try { + this.printWeb(el); + return true; + } catch (e) { + console.error('[BluetoothPrint] printWeb failed, calling window.print directly:', e); + window.print(el); + return true; + } + } + return new Promise((resolve) => { // Create a hidden iframe for printing const printFrame = document.createElement('iframe');