fix: use local zxing-wasm file to resolve CSP issues in QrScanner

This commit is contained in:
2026-02-28 17:21:29 +00:00
parent 1c4bdeff0e
commit 90dc663393
4 changed files with 84 additions and 10 deletions

View File

@@ -3,6 +3,27 @@ import './style.css'
import App from './App.vue'
import router from './router'
import Ripple from './directives/ripple'
import { BarcodeDetector, prepareZXingModule } from 'barcode-detector/ponyfill'
// Configure BarcodeDetector polyfill to use local WASM file
try {
prepareZXingModule({
overrides: {
locateFile: (path, prefix) => {
if (path.endsWith('.wasm')) {
return '/wasm/zxing_reader.wasm'
}
return prefix + path
}
}
})
// Force usage of polyfill to avoid CSP issues and ensure consistent behavior
// Native implementation might fail or be missing in some browsers
window.BarcodeDetector = BarcodeDetector
} catch (e) {
console.error('Failed to initialize BarcodeDetector polyfill', e)
}
const app = createApp(App)