From f8a77d13ab50c7808ef98e0096d6af4bf0ce73dc Mon Sep 17 00:00:00 2001 From: "Felipe M." Date: Sat, 23 May 2026 08:33:31 +0200 Subject: [PATCH] Gate Bluetooth and USB transports independently Previously the compatibility check disabled all printing when Web Bluetooth was missing, even if WebUSB was available. Browsers that ship only one of the two device APIs (e.g. privacy-focused Chromium forks) couldn't reach the working transport. Changes: - checkCompatibility() now keeps state.canPrint true when at least one transport is available, and warns about each missing one individually instead of blocking everything. - The connection-type whose underlying transport + * (Web Bluetooth / WebUSB) isn't exposed by this browser. + * @param {HTMLSelectElement|null} selectEl + */ +function disableUnsupportedConnOptions(selectEl) { + if (!selectEl) return; + const hasBluetooth = 'bluetooth' in navigator; + const hasUsb = 'usb' in navigator; + for (const opt of selectEl.options) { + if (opt.value === 'ble' && !hasBluetooth) { + opt.disabled = true; + opt.title = 'Bluetooth printing isn\'t supported in this browser'; + } else if (opt.value === 'usb' && !hasUsb) { + opt.disabled = true; + opt.title = 'USB printing isn\'t supported in this browser'; + } + } +} + /** * Check browser compatibility */ @@ -5545,13 +5569,19 @@ function checkCompatibility() { canPrint = false; } - if (!('bluetooth' in navigator)) { - warnings.push('Web Bluetooth not supported - printing requires Chrome, Edge, or Opera'); - canPrint = false; + const hasBluetooth = 'bluetooth' in navigator; + const hasUsb = 'usb' in navigator; + + if (!hasBluetooth) { + warnings.push('Bluetooth printing isn\'t supported in this browser'); + } + if (!hasUsb) { + warnings.push('USB printing isn\'t supported in this browser'); } - if (!('usb' in navigator)) { - console.warn('WebUSB not supported - USB printing will not be available'); + // Need at least one transport to print at all + if (!hasBluetooth && !hasUsb) { + canPrint = false; } // Store print capability in state for disabling print buttons @@ -5571,7 +5601,7 @@ function checkCompatibility() {

Limited Browser Support

-

Printing requires Chrome, Edge, or Opera

+

Printing requires Chrome, Edge, Opera or another Chromium-based browser

@@ -5860,6 +5890,7 @@ function initMobileUI() { const mobileConnType = $('#mobile-conn-type'); const desktopConnType = $('#conn-type'); if (mobileConnType && desktopConnType) { + disableUnsupportedConnOptions(mobileConnType); mobileConnType.value = desktopConnType.value; mobileConnType.addEventListener('change', (e) => { desktopConnType.value = e.target.value; @@ -6739,11 +6770,13 @@ function init() { setTapeWidth(parseInt(e.target.value, 10)); }); - // Connection type + // Connection type — disable options whose underlying transport is missing const connType = $('#conn-type'); - if (!('usb' in navigator)) { - const usbOption = connType.querySelector('option[value="usb"]'); - if (usbOption) usbOption.remove(); + disableUnsupportedConnOptions(connType); + // If default ('ble') isn't supported, fall back to USB when available + if (!('bluetooth' in navigator) && 'usb' in navigator) { + state.connectionType = 'usb'; + if (connType) connType.value = 'usb'; } connType.addEventListener('change', (e) => { state.connectionType = e.target.value; diff --git a/src/web/index.html b/src/web/index.html index ede48ce..c869d79 100644 --- a/src/web/index.html +++ b/src/web/index.html @@ -1513,7 +1513,7 @@

Multi-Label Rolls

-

Requires Chrome, Edge, or Chromium-based browser with Web Bluetooth.

+

Requires Chrome, Edge or another Chromium-based browser.

diff --git a/src/web/usb.js b/src/web/usb.js index 3884d07..6237e0d 100644 --- a/src/web/usb.js +++ b/src/web/usb.js @@ -90,7 +90,7 @@ export class USBTransport { */ async connect(options = {}) { if (!USBTransport.isAvailable()) { - throw new Error('WebUSB is not supported in this browser'); + throw new Error('USB printing isn\'t supported in this browser'); } // Try to reconnect to existing device first