Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: only install polyfill if there is no native support (#447) #449

Merged
merged 1 commit into from
Sep 6, 2024

Conversation

gruhn
Copy link
Owner

@gruhn gruhn commented Sep 2, 2024

  • feat: only install polyfill if there is no native support

  • Modified gitignore to ignore vitepress cache and dist

Copy link

github-actions bot commented Sep 2, 2024

PR Preview Action v1.4.7
🚀 Deployed preview to https://gruhn.github.io/vue-qrcode-reader/pr-preview/pr-449/
on branch gh-pages at 2024-09-02 11:39 UTC

@gruhn gruhn force-pushed the detector-polyfill-on-demand branch from 2bd4763 to 3765b94 Compare September 2, 2024 11:31
Copy link

cloudflare-workers-and-pages bot commented Sep 2, 2024

Deploying vue-qrcode-reader with  Cloudflare Pages  Cloudflare Pages

Latest commit: a5a0a2a
Status: ✅  Deploy successful!
Preview URL: https://5d0fcc19.vue-qrcode-reader.pages.dev
Branch Preview URL: https://detector-polyfill-on-demand.vue-qrcode-reader.pages.dev

View logs

@gruhn gruhn force-pushed the detector-polyfill-on-demand branch from 3765b94 to 5cdc631 Compare September 2, 2024 11:38
@gruhn
Copy link
Owner Author

gruhn commented Sep 3, 2024

@pastc it appears that Blob inputs to BarcodeDetector.detect are still not supported (at least) in Chrome on macOS. See this demo deployment:

https://53815a69.vue-qrcode-reader.pages.dev/demos/DragDrop.html

So this breaks QrcodeDropZone and QrcodeCapture. But can you confirm that QrcodeStream works? I only have devices without native BarcodeDetector support except a Mac (but that one doesn't have a camera).

@pastc
Copy link

pastc commented Sep 4, 2024

@gruhn I tested the demo on the link that you gave me on a macbook air on chrome and it worked fine. all QrcodeDropZone, QrcodeCapture, and QrcodeStream.

@gruhn
Copy link
Owner Author

gruhn commented Sep 4, 2024

Hmm, that's odd. I just checked on my Mac I have at work (which both has a camera and native BarcodeDetector support). I can confirm that QrcodeStream works but for QrcodeDropZone and QrcodeCapture I see the same error. Can you check your console? If you turn on verbose logging in Chrome DevTools, it should log one of these messages, once you upload/drop a file:

[vue-qrcode-reader] BarcodeDetector not available: will use polyfill.
[vue-qrcode-reader] BarcodeDetector available: will use native API.

Either way, its probably ok to always use the polyfill for QrcodeDropZone / QrcodeCapture and use it on demand for QrcodeStream.

@pastc
Copy link

pastc commented Sep 4, 2024

Screenshot 2024-09-04 at 20 18 16

@pastc
Copy link

pastc commented Sep 4, 2024

I don't know why it isn't working on your macbook.

Still using polyfill for `QrcodeDropZone` and `QrcodeCapture` even on
platforms with native `BarcodeDetector` is available, because on some
of them `BarcodeDetector.detect` does not support `Blob` / `File`
inputs.

See: #447
@gruhn gruhn force-pushed the detector-polyfill-on-demand branch from 5cdc631 to a5a0a2a Compare September 6, 2024 18:55
@gruhn gruhn merged commit aa7c5aa into master Sep 6, 2024
1 check passed
@gruhn gruhn deleted the detector-polyfill-on-demand branch September 6, 2024 18:59
Copy link

github-actions bot commented Sep 6, 2024

🎉 This PR is included in version 5.5.8 🎉

The release is available on:

Your semantic-release bot 📦🚀

@wosiwq
Copy link
Contributor

wosiwq commented Sep 18, 2024

@gruhn I think we need to check if the window.BarcodeDetector object supports formats by calling window.BarcodeDetector.getSupportedFormats() in the setScanningFormats method.

I'm running into a problem where some of the application's built-in browser, they have window.BarcodeDetector objects, but window.BarcodeDetector.getSupportedFormats() returns []

@gruhn
Copy link
Owner Author

gruhn commented Sep 18, 2024

Ok, that’s annoying. I think we should probably revert this change then. I mean we could detect this particular situation and take that into account when applying the polyfill, but who knows which other device/OS/browser combos are problematic.

@Sec-ant
Copy link
Contributor

Sec-ant commented Sep 18, 2024

Ok, that’s annoying. I think we should probably revert this change then.

Happened to notice this issue, it's probably better to provide a boolean prop (like native) to let the user decide whether to use the platform-native barcode detection API, and default to false for compatibility and out-of-box experience.

@wosiwq
Copy link
Contributor

wosiwq commented Sep 19, 2024

Happened to notice this issue, it's probably better to provide a boolean prop (like native) to let the user decide whether to use the platform-native barcode detection API, and default to false for compatibility and out-of-box experience.

I think providing a prop for the user to choose from is a good idea. Maybe we could also compare the formats passed in by setScanningFormats with the list of window.BarcodeDetector.getSupportedFormats() to more intelligently toggle the value of the native?

@gruhn
Copy link
Owner Author

gruhn commented Sep 19, 2024

Happened to notice this issue, it's probably better to provide a boolean prop (like native) to let the user decide whether to use the platform-native barcode detection API, and default to false for compatibility and out-of-box experience.

I'm worried that this has a hidden cost. There might be a ton of random device/OS/browser combos where the native API is not quite working as expected. If a native prop is available, users can work around that a la:

if (edgeCase1) {
  setNativeProp(true)
} else if (edgeCase2) {
  setNativeProp(false)
} else { 
  ... 
}

But then users are less likely to open an issue here and share that knowledge. Thus, everyone is left to re-discover these issues by themselves. On the other hand, if users open an issue, we can at least try to find a solution, that fixes the problem for everyone.

Maybe we could also compare the formats passed in by setScanningFormats with the list of window.BarcodeDetector.getSupportedFormats()

I'd prefer this approach then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants