From e7d1eb6bb4aeb799c8a657c07d6d889295fba787 Mon Sep 17 00:00:00 2001 From: Georgy Date: Wed, 2 Sep 2026 00:03:40 +0300 Subject: [PATCH 1/5] fix: support Firefox QR scanning and camera frames --- .ai/ARCHITECTURE.md | 8 ++ .ai/FEATURES.md | 6 + .ai/FIXES.md | 9 +- .ai/HANDOFF.md | 29 ++--- .ai/PERFORMANCE.md | 7 ++ .ai/TODO.md | 17 ++- package.json | 2 + pnpm-lock.yaml | 88 ++++++++------ .../barcode-generator-reader.e2e.spec.ts | 23 ++++ .../barcode-generator-reader.vue | 14 +-- .../barcode-reader.service.test.ts | 26 +++- .../barcode-reader.service.ts | 114 ++++++++++++++---- .../qr-decoder-otp-import.e2e.spec.ts | 66 ++++++++++ .../qr-decoder-otp-import.service.ts | 51 ++------ .../qr-decoder-otp-import.vue | 26 ++-- 15 files changed, 349 insertions(+), 137 deletions(-) diff --git a/.ai/ARCHITECTURE.md b/.ai/ARCHITECTURE.md index a82fb0cc76..7c06fad1cd 100644 --- a/.ai/ARCHITECTURE.md +++ b/.ai/ARCHITECTURE.md @@ -28,6 +28,14 @@ workers stay route-owned and demand-loaded. Large or attacker-controlled work uses explicit actions or bounded debounce, input/output limits, timeout, cancellation, stale-result protection, and disposal on route teardown. +Shared QR recognition lives in the barcode reader service. Normal builds +prefer the browser `BarcodeDetector` and lazily use the local `qr-scanner` +worker only when native QR detection is unavailable. OTP camera capture keeps +permission explicit, validates frame dimensions, decodes one requested frame, +and stops every media track on request, timeout, failure, or unmount. +Standalone compiles this fallback out because its DataLens CSP sets +`worker-src 'none'`; it must never attempt a blob worker there. + The common worker lifecycle is implemented by `src/utils/worker-protocol.ts`, `src/utils/worker-task.ts`, and `src/utils/bounded-text-task.ts`. Workers validate both request and response envelopes; replacement, cancellation, timeout, and diff --git a/.ai/FEATURES.md b/.ai/FEATURES.md index ff9b567f52..a5ad30258c 100644 --- a/.ai/FEATURES.md +++ b/.ai/FEATURES.md @@ -10,6 +10,12 @@ cron schedules, barcode workflows, JWK/JWKS and asymmetric JWT verification, OpenAPI inspection, PKCS#12/public PEM inspection, offline GeoIP, and the local encrypted OTP vault. +QR Decoder & OTP Import and Barcode Generator/Reader share cross-browser local +QR recognition in the normal build: native detection is preferred and Firefox +uses a lazy worker fallback for files and explicit camera frames. The +single-file DataLens build remains native-only because its CSP denies workers; +manual OTP payload parsing remains available there. + Local LLM Playground is the only model-inference tool. It offers fixed text-only Qwen3.5 Lite 0.8B, Standard 2B, and Quality 4B tiers through local WebGPU inference with explicit same-origin downloads, per-file parallel diff --git a/.ai/FIXES.md b/.ai/FIXES.md index ac129d3b54..f3d684d39d 100644 --- a/.ai/FIXES.md +++ b/.ai/FIXES.md @@ -1,7 +1,7 @@ # Resolved Engineering State The approved correctness, security, delivery, persistence, and performance -work is complete as of 2026-08-27. +work is complete as of 2026-09-02. - Production dependency audit has no known advisory in the approved graph. - Scoped transitive overrides keep the browser-only Transformers dependency's @@ -16,6 +16,13 @@ work is complete as of 2026-08-27. interleaving aggregate and per-file percentages. Its pinned q4 artifacts are served same-origin only; Transformers.js remote fallback is disabled and a focused browser regression rejects Hugging Face runtime traffic. +- QR image reading and OTP camera-frame decoding prefer the native + `BarcodeDetector` where available and use a bounded, lazy local worker + fallback in Firefox. The shared reader retains file, pixel, payload, result, + explicit-permission, five-minute teardown, and media-track cleanup bounds. + Standalone remains native-only because its target CSP denies workers. +- The release dependency graph pins `browserslist` 4.28.7 so the production + audit remains free of the advisories affecting earlier transitive versions. - Root, subpath, reverse-proxy, security-header, PWA, Firefox, WebKit, Chromium, and Long Task coverage exists in the repository. - Storage migrations, quota failure, rollback, and stale-cache cleanup are diff --git a/.ai/HANDOFF.md b/.ai/HANDOFF.md index 3c14377403..7a9f275d3e 100644 --- a/.ai/HANDOFF.md +++ b/.ai/HANDOFF.md @@ -11,11 +11,12 @@ The repository may be intentionally dirty; inspect `git status` and never overwrite unrelated local-fork work. Do not merge, rebase, or cherry-pick upstream automatically. -Current checkpoint: branch `feat/ai-tools-local-llm-1842`, based on commit -`5395615c0c9537ebf78b20e6c7b275f4ab3fa794`. The branch tip packages the final -approved browser-tool catalog, persistence/UI/performance work, standalone -delivery, and the 2026-08-27 Local LLM same-origin model mirror. Keep the whole -branch together when reviewing or transferring it. +Current checkpoint: the 2026-09-02 Firefox QR maintenance release adds a shared +native-first, local worker fallback for QR files and explicit OTP camera frames +in the normal build. It retains the final approved browser-tool catalog, +persistence/UI/performance work, standalone delivery, and the Local LLM +same-origin model mirror. Standalone deliberately compiles the QR fallback out +because the DataLens CSP denies workers. ## Resume @@ -39,8 +40,8 @@ the touched surface. ## Standalone/DataLens -The final artifact is `dist-standalone/it-tools.html`: one 7,994,866-byte file -(7.62 MiB; 7,996,917-byte JSON upload envelope) with 126 tools and no runtime +The final artifact is `dist-standalone/it-tools.html`: one 7,996,206-byte file +(7.63 MiB) with 126 tools and no runtime network resources. `pnpm test:standalone` rebuilds it from current sources and runs Chromium, Firefox, and WebKit serially. @@ -74,13 +75,13 @@ mirror is intentionally untracked: run `pnpm models:download`, then `pnpm models:check`, before publishing the normal build. Actual GPU/model acceptance remains a hardware-manual non-claim. -Green focused gates on 2026-08-27: lint, typecheck, 267 Vitest files / 1,482 -tests, production build, all 430 build budgets, 28-file / 4.98 GiB model mirror -completeness check, and four Chromium Local LLM route/privacy/same-origin -smokes. The 2026-08-25 release gates also include a clean production dependency -audit, Docker converter compatibility after security overrides, Firefox/WebKit -route coverage, strict dev runtime, and standalone (4 Node + 6 browser tests; -48/48 included worker paths). +Green focused gates on 2026-09-02: lint, typecheck, 267 Vitest files / 1,484 +tests, production build, all 432 build budgets, a clean production dependency +audit, Chromium/Firefox QR file and OTP camera regressions, WebKit QR file +coverage, and standalone (4 Node + 6 browser tests; 48/48 included worker +paths). The 28-file / 4.98 GiB model mirror completeness check and four +Chromium Local LLM route/privacy/same-origin smokes remain the accepted model +release evidence. The Orca desktop runtime was unavailable after the documented open retry, so interactive visual/model acceptance was not claimed. diff --git a/.ai/PERFORMANCE.md b/.ai/PERFORMANCE.md index 157bf28d51..b6f14845de 100644 --- a/.ai/PERFORMANCE.md +++ b/.ai/PERFORMANCE.md @@ -34,6 +34,13 @@ excluded from JS/shell build statistics. On the 2026-08-25 production Chromium run, first client-side route readiness was 171 ms with a 0.0 ms longest observed task and no worker/model request before Load. +Firefox QR compatibility is route-owned and demand-loaded. The accepted normal +build adds a 18,129-byte raw / 6.39 kB gzip shared reader module and a +43,954-byte raw / 10.46 kB gzip QR worker; neither enters the 719,149-byte shell +or the 53-file Workbox precache. The standalone compile removes the fallback +entirely and remains a 7,996,206-byte single HTML artifact under the 10 MiB +limit. + ## Gates `.ai/baselines/build-budgets.json` is the sole detailed budget source. It diff --git a/.ai/TODO.md b/.ai/TODO.md index 9907b8e6cb..f1109d705b 100644 --- a/.ai/TODO.md +++ b/.ai/TODO.md @@ -2,11 +2,15 @@ ## Active approved work -There is no active feature backlog. The approved Local LLM Playground is -implemented in the normal build with Lite 0.8B, Standard 2B, and Quality 4B; -Max, vision, automatic downloads, PWA precaching, and standalone inclusion are -deliberately absent. The three approved q4 tiers are mirrored same-origin from -pinned revisions; runtime Hugging Face fallback is prohibited. +There is no active feature or maintenance backlog. Firefox QR decoding and +explicit camera-frame capture were completed with a shared native-first local +fallback and regression coverage. No unrelated feature work is approved. + +The approved Local LLM Playground remains implemented in the normal build with +Lite 0.8B, Standard 2B, and Quality 4B; Max, vision, automatic downloads, PWA +precaching, and standalone inclusion are deliberately absent. The three +approved q4 tiers are mirrored same-origin from pinned revisions; runtime +Hugging Face fallback is prohibited. Do not invent additional tools or revive removed upstream lists. @@ -34,4 +38,5 @@ privacy defaults, worker limits/cancellation, and build budgets intact. No upstream application code or design is approved for adaptation. The local implementation consumes exact Apache-2.0 `@huggingface/transformers` 4.2.0 and the three fixed Qwen3.5 ONNX model repositories; integration code and UI remain -local-fork work. +local-fork work. Firefox QR compatibility uses exact MIT `qr-scanner` 1.4.2 as +a lazy normal-build dependency; the integration and UI remain local-fork work. diff --git a/package.json b/package.json index 7eb256025b..7199769cb3 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "@babel/runtime": "7.29.7", "@huggingface/transformers>sharp": "0.35.0", "brace-expansion": "1.1.18", + "browserslist": "4.28.7", "composerize-ts>deepmerge-ts": "8.0.2", "fast-uri": "3.1.5", "ip-address": "10.5.0", @@ -134,6 +135,7 @@ "pinia": "^2.0.34", "pkijs": "3.4.0", "plausible-tracker": "^0.3.8", + "qr-scanner": "1.4.2", "qrcode": "^1.5.1", "randexp": "^0.5.3", "saxen": "11.1.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0de1579e09..3c1eceb426 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10,6 +10,7 @@ overrides: '@babel/runtime': 7.29.7 '@huggingface/transformers>sharp': 0.35.0 brace-expansion: 1.1.18 + browserslist: 4.28.7 composerize-ts>deepmerge-ts: 8.0.2 fast-uri: 3.1.5 ip-address: 10.5.0 @@ -186,6 +187,9 @@ importers: plausible-tracker: specifier: ^0.3.8 version: 0.3.8 + qr-scanner: + specifier: 1.4.2 + version: 1.4.2 qrcode: specifier: ^1.5.1 version: 1.5.1 @@ -2183,6 +2187,9 @@ packages: '@types/object.pick@1.3.2': resolution: {integrity: sha512-sn7L+qQ6RLPdXRoiaE7bZ/Ek+o4uICma/lBFPyJEKDTPTBP1W8u0c4baj3EiS4DiqLs+Hk+KUGvMVJtAw3ePJg==} + '@types/offscreencanvas@2019.7.3': + resolution: {integrity: sha512-ieXiYmgSRXUDeOntE1InxjWyvEelZGP63M+cGuquuRLuIKKT1osnkXjxev9B7d1nXSug5vpunx+gNlbVxMlC9A==} + '@types/ps-tree@1.1.2': resolution: {integrity: sha512-ZREFYlpUmPQJ0esjxoG1fMvB2HNaD3z+mjqdSosZvd3RalncI9NEur73P8ZJz4YQdL64CmV1w0RuqoRUlhQRBw==} @@ -2736,6 +2743,11 @@ packages: base64-js@1.5.1: resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} + baseline-browser-mapping@2.11.20: + resolution: {integrity: sha512-H0ulySigv6icDJ1F7SjtdCD6PrhTpdYCmP0CactWy1+ekh0AFd0o1Wn5T8b+hnTmdBx19u9yhL6wvCylXMY7zw==} + engines: {node: '>=6.0.0'} + hasBin: true + bcryptjs@2.4.3: resolution: {integrity: sha512-V/Hy/X9Vt7f3BbPJEi8BdVFMByHi+jNXrYkW3huaybV/kQ0KJg0Y6PkEMbn+zeT+i+SiKZ/HMqJGIIt4LZDqNQ==} @@ -2764,8 +2776,8 @@ packages: resolution: {integrity: sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==} engines: {node: '>=8'} - browserslist@4.24.3: - resolution: {integrity: sha512-1CPmv8iobE2fyRMV97dAcMVegvvWKxmq94hkLiAkUGwKVTyDLw33K+ZxiFrREKmmps4rIw6grcCFCnTMSZ/YiA==} + browserslist@4.28.7: + resolution: {integrity: sha512-JxV13hNrFxqjOc8alRbq9dK1MM79NEXYpma2B2J4wAtpWS5zIEIKqWPGCl7N4o7Uc7B7itylh7SuDujATRyyTw==} engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} hasBin: true @@ -2826,8 +2838,8 @@ packages: resolution: {integrity: sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==} engines: {node: '>=10'} - caniuse-lite@1.0.30001688: - resolution: {integrity: sha512-Nmqpru91cuABu/DTCXbM2NSRHzM2uVHfPnhJ/1zEAJx/ILBRVmz3pzH4N7DZqbdG0gWClsCC05Oj0mJ/1AWMbA==} + caniuse-lite@1.0.30001810: + resolution: {integrity: sha512-TITQPUkaz+aVk5GL6NhOdwk1aEaNTSDPsGFWrTuhKGtjTF70jL/Oht2W4c6rXUe5fu7Ie19VIahAXHIIiWWNeg==} capital-case@1.0.4: resolution: {integrity: sha512-ds37W8CytHgwnhGGTi88pcPyR15qoNkOpYwmMMfnWqqWgESapLqvDx6huFjQ5vqWSn2Z06173XNA7LtMOeUh1A==} @@ -3426,8 +3438,8 @@ packages: engines: {node: '>=0.10.0'} hasBin: true - electron-to-chromium@1.5.73: - resolution: {integrity: sha512-8wGNxG9tAG5KhGd3eeA0o6ixhiNdgr0DcHWm85XPCphwZgD1lIEoi6t3VERayWao7SF7AAZTw6oARGJeVjH8Kg==} + electron-to-chromium@1.5.419: + resolution: {integrity: sha512-nHMPn8x4yCxCI0iSnL+LlHL5sUoUfjLXkcRIagZ4GBdrfFLFaiLNvzJWbJqZhFT9IAhw5tUSNlhggWN+otvp/A==} elkjs@0.9.3: resolution: {integrity: sha512-f/ZeWvW/BCXbhGEf1Ujp29EASo/lk1FDnETgNKwJrsVvGZhUWCZyg3xLJjAsxfOmt8KjswHmI5EwCQcPMpOYhQ==} @@ -4834,8 +4846,9 @@ packages: resolution: {integrity: sha512-LarFH0+6VfriEhqMMcLX2F7SwSXeWwnEAJEsYm5QKWchiVYVvJyV9v7UDvUv+w5HO23ZpQTXDv/GxdDdMyOuoQ==} engines: {node: '>= 6.13.0'} - node-releases@2.0.19: - resolution: {integrity: sha512-xxOWJsBKtzAq7DY0J+DTzuz58K8e7sJbdgwkbMWQe8UYB6ekmsQ45q0M/tJDsGaZmbC+l7n57UV8Hl5tHxO9uw==} + node-releases@2.0.54: + resolution: {integrity: sha512-YHs7BmmcsdAI5Ozuf8JZo6PT0mv2GIWC9vMfvUC3dp65M8hn7Ux8CPL+2oBI7juNuj9d0ndhTcznq2ODBps9cQ==} + engines: {node: '>=18'} non-layered-tidy-tree-layout@2.0.2: resolution: {integrity: sha512-gkXMxRzUH+PB0ax9dUN0yYF0S25BqeAYqhgMaLUFmpXLEk7Fcu8f4emJuOAY0V8kjDICxROIKsTAKsV/v355xw==} @@ -5230,6 +5243,9 @@ packages: resolution: {integrity: sha512-BbubeCEyTuQjVMakvJQ/Sxbc93F2pwmbsxONT/ZRrwU7Ua38d8unYTwXpTVLAKJ4BDuH9IGztCjQcd/N/39Dvg==} engines: {node: '>=16.0.0'} + qr-scanner@1.4.2: + resolution: {integrity: sha512-kV1yQUe2FENvn59tMZW6mOVfpq9mGxGf8l6+EGaXUOd4RBOLg7tRC83OrirM5AtDvZRpdjdlXURsHreAOSPOUw==} + qrcode@1.5.1: resolution: {integrity: sha512-nS8NJ1Z3md8uTjKtP+SGGhfqmTCs5flU/xR623oI0JX+Wepz9R8UrRVCTBTJm3qGw3rH6jJ6MUHjkDx15cxSSg==} engines: {node: '>=10.13.0'} @@ -5457,11 +5473,6 @@ packages: engines: {node: '>=10'} hasBin: true - semver@7.6.3: - resolution: {integrity: sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==} - engines: {node: '>=10'} - hasBin: true - semver@7.8.5: resolution: {integrity: sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==} engines: {node: '>=10'} @@ -6059,11 +6070,11 @@ packages: resolution: {integrity: sha512-aZwGpamFO61g3OlfT7OQCHqhGnW43ieH9WZeP7QxN/G/jS4jfqUkZxoryvJgVPEcrl5NL/ggHsSmLMHuH64Lhg==} engines: {node: '>=4'} - update-browserslist-db@1.1.1: - resolution: {integrity: sha512-R8UzCaa9Az+38REPiJ1tXlImTJXlVfgHZsglwBD/k6nj76ctsH1E3q4doGrukiLQd3sGQYu56r5+lo5r94l29A==} + update-browserslist-db@1.3.2: + resolution: {integrity: sha512-UQ+MSxlhRm1bzjhU+DcuXfjFO1FzNtqhK5+9Yvlp90ItDLk5vT932A0rFu619nf7RVS+Y/VeaUW1jaRDqZ8VJw==} hasBin: true peerDependencies: - browserslist: '>= 4.21.0' + browserslist: 4.28.7 upper-case-first@1.1.2: resolution: {integrity: sha512-wINKYvI3Db8dtjikdAqoBbZoP6Q+PZUyfMR7pmwHzjC2quzSkUq5DmPrTtPEqHaz8AGtmsB4TqwapMTM1QAQOQ==} @@ -6671,7 +6682,7 @@ snapshots: dependencies: '@babel/compat-data': 7.29.7 '@babel/helper-validator-option': 7.29.7 - browserslist: 4.24.3 + browserslist: 4.28.7 lru-cache: 5.1.1 semver: 6.3.1 @@ -8438,6 +8449,8 @@ snapshots: '@types/object.pick@1.3.2': {} + '@types/offscreencanvas@2019.7.3': {} + '@types/ps-tree@1.1.2': {} '@types/qrcode@1.5.0': @@ -8551,7 +8564,7 @@ snapshots: debug: 4.4.0 globby: 11.1.0 is-glob: 4.0.3 - semver: 7.6.3 + semver: 7.8.5 ts-api-utils: 1.0.1(typescript@5.2.2) optionalDependencies: typescript: 5.2.2 @@ -8596,7 +8609,7 @@ snapshots: '@typescript-eslint/types': 6.4.1 '@typescript-eslint/typescript-estree': 6.4.1(typescript@5.2.2) eslint: 8.47.0 - semver: 7.6.3 + semver: 7.8.5 transitivePeerDependencies: - supports-color - typescript @@ -8610,7 +8623,7 @@ snapshots: '@typescript-eslint/types': 6.9.1 '@typescript-eslint/typescript-estree': 6.9.1(typescript@5.2.2) eslint: 8.47.0 - semver: 7.6.3 + semver: 7.8.5 transitivePeerDependencies: - supports-color - typescript @@ -9227,6 +9240,8 @@ snapshots: base64-js@1.5.1: {} + baseline-browser-mapping@2.11.20: {} + bcryptjs@2.4.3: {} binary-extensions@2.2.0: {} @@ -9254,12 +9269,13 @@ snapshots: dependencies: fill-range: 7.1.1 - browserslist@4.24.3: + browserslist@4.28.7: dependencies: - caniuse-lite: 1.0.30001688 - electron-to-chromium: 1.5.73 - node-releases: 2.0.19 - update-browserslist-db: 1.1.1(browserslist@4.24.3) + baseline-browser-mapping: 2.11.20 + caniuse-lite: 1.0.30001810 + electron-to-chromium: 1.5.419 + node-releases: 2.0.54 + update-browserslist-db: 1.3.2(browserslist@4.28.7) buffer-from@1.1.2: {} @@ -9272,7 +9288,7 @@ snapshots: builtins@5.0.1: dependencies: - semver: 7.6.3 + semver: 7.8.5 bundle-require@5.0.0(esbuild@0.23.1): dependencies: @@ -9316,7 +9332,7 @@ snapshots: camelcase@6.3.0: {} - caniuse-lite@1.0.30001688: {} + caniuse-lite@1.0.30001810: {} capital-case@1.0.4: dependencies: @@ -9512,7 +9528,7 @@ snapshots: core-js-compat@3.39.0: dependencies: - browserslist: 4.24.3 + browserslist: 4.28.7 cose-base@1.0.3: dependencies: @@ -9951,7 +9967,7 @@ snapshots: dependencies: jake: 10.8.7 - electron-to-chromium@1.5.73: {} + electron-to-chromium@1.5.419: {} elkjs@0.9.3: {} @@ -11638,7 +11654,7 @@ snapshots: node-forge@1.4.0: {} - node-releases@2.0.19: {} + node-releases@2.0.54: {} non-layered-tidy-tree-layout@2.0.2: {} @@ -12091,6 +12107,10 @@ snapshots: pvutils@1.2.0: {} + qr-scanner@1.4.2: + dependencies: + '@types/offscreencanvas': 2019.7.3 + qrcode@1.5.1: dependencies: dijkstrajs: 1.0.2 @@ -12321,8 +12341,6 @@ snapshots: dependencies: lru-cache: 6.0.0 - semver@7.6.3: {} - semver@7.8.5: {} sentence-case@2.1.1: @@ -12994,9 +13012,9 @@ snapshots: upath@1.2.0: {} - update-browserslist-db@1.1.1(browserslist@4.24.3): + update-browserslist-db@1.3.2(browserslist@4.28.7): dependencies: - browserslist: 4.24.3 + browserslist: 4.28.7 escalade: 3.2.0 picocolors: 1.1.1 @@ -13149,7 +13167,7 @@ snapshots: espree: 9.6.1 esquery: 1.5.0 lodash: 4.18.1 - semver: 7.6.3 + semver: 7.8.5 transitivePeerDependencies: - supports-color diff --git a/src/tools/barcode-generator-reader/barcode-generator-reader.e2e.spec.ts b/src/tools/barcode-generator-reader/barcode-generator-reader.e2e.spec.ts index 3f824526d3..e944e31560 100644 --- a/src/tools/barcode-generator-reader/barcode-generator-reader.e2e.spec.ts +++ b/src/tools/barcode-generator-reader/barcode-generator-reader.e2e.spec.ts @@ -1,4 +1,7 @@ +import { Buffer } from 'node:buffer'; + import { expect, test } from '@playwright/test'; +import QRCode from 'qrcode'; test.describe('Tool - Barcode generator and reader', () => { test.beforeEach(async ({ page }) => { @@ -34,4 +37,24 @@ test.describe('Tool - Barcode generator and reader', () => { const status = await page.getByTestId('barcode-reader-status').textContent(); expect(status).toMatch(/Reader available|not available/); }); + + test('uses the local QR fallback when native BarcodeDetector is absent', async ({ page }) => { + await page.addInitScript(() => { + Reflect.deleteProperty(globalThis, 'BarcodeDetector'); + }); + await page.goto('/barcode-generator-reader'); + + const value = 'firefox-local-qr'; + const qrDataUrl = await QRCode.toDataURL(value, { margin: 4, width: 512 }); + await page.locator('input[type="file"]').setInputFiles({ + buffer: Buffer.from(qrDataUrl.slice(qrDataUrl.indexOf(',') + 1), 'base64'), + mimeType: 'image/png', + name: 'firefox-barcode.png', + }); + + await expect(page.getByTestId('barcode-read')).toBeEnabled(); + await page.getByTestId('barcode-read').click(); + await expect(page.getByTestId('barcode-results')).toContainText('qr_code'); + await expect(page.getByTestId('barcode-results')).toContainText(value); + }); }); diff --git a/src/tools/barcode-generator-reader/barcode-generator-reader.vue b/src/tools/barcode-generator-reader/barcode-generator-reader.vue index 0ddbc509ce..6838df162e 100644 --- a/src/tools/barcode-generator-reader/barcode-generator-reader.vue +++ b/src/tools/barcode-generator-reader/barcode-generator-reader.vue @@ -7,7 +7,7 @@ import { import { BARCODE_MAX_FILE_BYTES, type BarcodeReaderResult, - getBarcodeDetectorFormats, + getBarcodeReaderFormats, readBarcodesFromFile, } from './barcode-reader.service'; import { downloadTextFile } from '@/composable/downloadText'; @@ -40,12 +40,12 @@ const isReading = ref(false); const signature = computed(() => `${format.value}\0${value.value}`); const generatorIsStale = computed(() => Boolean(svg.value && generatedSignature.value !== signature.value)); const svgDataUrl = computed(() => svg.value ? `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg.value)}` : ''); -const detectorAvailable = computed(() => readerFormats.value.length > 0); +const readerAvailable = computed(() => readerFormats.value.length > 0); const canRead = computed(() => Boolean( selectedFile.value && selectedFile.value.size > 0 && selectedFile.value.size <= BARCODE_MAX_FILE_BYTES - && detectorAvailable.value + && readerAvailable.value && !isReading.value, )); @@ -96,7 +96,7 @@ async function readFile() { } isReading.value = true; readerError.value = ''; - readerStatus.value = 'Reading barcodes locally with the browser image detector…'; + readerStatus.value = 'Reading barcodes locally…'; try { detected.value = await readBarcodesFromFile(file, readerFormats.value); readerStatus.value = detected.value.length === 0 @@ -114,7 +114,7 @@ async function readFile() { const { copy } = useCopy({ createToast: true }); onMounted(async () => { - readerFormats.value = await getBarcodeDetectorFormats(); + readerFormats.value = await getBarcodeReaderFormats(); readerStatus.value = readerFormats.value.length > 0 ? `Reader available for: ${readerFormats.value.join(', ')}.` : 'BarcodeDetector is not available in this browser. Barcode generation still works.'; @@ -170,9 +170,9 @@ generate(); {{ selectedFile.name }} — {{ formatBytes(selectedFile.size) }}
- The image is processed only after you select Read barcodes. Nothing is uploaded or stored. Reader format support depends on this browser. + The image is processed only after you select Read barcodes. Nothing is uploaded or stored. Native formats are used when available; QR has a local worker fallback.
-