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

bug: #88

Closed
4 of 10 tasks
LoranRendel opened this issue Oct 27, 2023 · 3 comments
Closed
4 of 10 tasks

bug: #88

LoranRendel opened this issue Oct 27, 2023 · 3 comments
Labels
bug/fix Something isn't working needs: triage

Comments

@LoranRendel
Copy link

LoranRendel commented Oct 27, 2023

Plugin(s)

  • Barcode Scanning
  • Face Detection
  • Face Mesh Detection
  • Selfie Segmentation
  • Translation

Did you test the latest version?

  • I use the latest version

Platform(s)

  • Android
  • iOS
  • Web

Current behavior

BarcodeScanner.isSupported() results in error Promise <rejected>: Error: This Barcode Scanner plugin method is not available on this platform.

Expected behavior

BarcodeScanner.isSupported() returns: Promise<IsSupportedResult> with {supported: false} as documentation says.

Reproduction

https://github.com/LoranRendel/temporary-mlkit-app

Steps to reproduce

npm start
open url
check devtools console

Other information

Promise<IsSupportedResult>

Capacitor doctor

[warn] The bundledWebRuntime configuration option has been deprecated. Can be safely deleted.
Capacitor Doctor

Latest Dependencies:

@capacitor/cli: 5.5.1
@capacitor/core: 5.5.1
@capacitor/android: 5.5.1
@capacitor/ios: 5.5.1

Installed Dependencies:

@capacitor/android: not installed
@capacitor/ios: not installed
@capacitor/core: 5.5.1
@capacitor/cli: 5.5.1

Before submitting

  • I understand that incomplete issues (e.g. without reproduction) are closed.
@LoranRendel LoranRendel added bug/fix Something isn't working needs: triage labels Oct 27, 2023
@robingenz
Copy link
Member

Available on Android and iOS.

The documentation says that this method is only available on Android and iOS. Therefore, this is not a bug.
I just updated the documentation of the isSupported method to be more clear about what exactly happens:

Whether the barcode scanner is available or not by checking if the device has a camera.

@LoranRendel
Copy link
Author

Thanks.
However this method is probably better to return value on all available platforms?

Now it is required to catch exception if platform is not supported and to validate value if device has no camera.

BarcodeScanner.isSupported().catch(function () { return { supported: false } })

@robingenz
Copy link
Member

I think there are arguments for both implementations. Since the plugin does not support the web platform at all, you should not call the plugin on the web. You could simply do it like this:

import { Capacitor } from '@capacitor/core';
import { BarcodeScanner } from '@capacitor-mlkit/barcode-scanning';

const isSupported = async () => {
  if (Capacitor.getPlatform() === 'web') {
    return false;
  }
  const result = await BarcodeScanner.isSupported();
  return result.supported;
};

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug/fix Something isn't working needs: triage
Projects
None yet
Development

No branches or pull requests

2 participants