Skip to content

Fix: modal dont close when user denied the camera permission on Web - #132

Open
Gkreischer wants to merge 6 commits into
ionic-team:mainfrom
Gkreischer:fix-and-features
Open

Fix: modal dont close when user denied the camera permission on Web#132
Gkreischer wants to merge 6 commits into
ionic-team:mainfrom
Gkreischer:fix-and-features

Conversation

@Gkreischer

Copy link
Copy Markdown

Description

This PR improves error handling in the Web implementation of the barcode scanner.

When camera permission was denied by the user, the scanner modal could remain open and fail to close properly. Although the errors were displayed, the modal stayed visible in the interface, preventing the user from continuing to use the application.

Errors showed:

Error getting userMedia, error = NotAllowedError: Permission denied
Cannot stop, scanner is not running or paused.

This change improves the error handling flow by properly handling camera permission failures, preventing invalid scanner state operations, and allowing the modal to close correctly.

The PR also adds typed error definitions to make scanner failures easier to identify and handle by library consumers.

Change Type

  • Fix
  • Feature
  • Refactor
  • Breaking Change
  • Documentation
  • Other (CI, chores, etc.)

Rationale / Problems Fixed

When using the Web implementation, with Ionic and Angular, denying camera permission caused an inconsistent scanner state.

The user could not properly dismiss the scanner modal, and attempting to stop the scanner after a failed getUserMedia request resulted in additional errors.

This PR fixes this behavior by:

  • Handling NotAllowedError from getUserMedia properly.
  • Avoiding calls to stop the scanner when it is not running.
  • Providing typed error information through CapacitorBarcodeScannerError.

This makes permission denial and other scanner failures easier for applications to handle.

Tests or Reproductions

Tested on the Web implementation.

Steps to reproduce before this change:

  1. Open the barcode scanner.
  2. Deny camera permission.
  3. Try to close the scanner modal.
  4. Observe that the modal does not close correctly and errors are logged.

After this change:

  1. Open the barcode scanner.
  2. Deny camera permission.
  3. The scanner handles the failure correctly and the modal can be closed without additional errors.

Screenshots / Media

Before fix:
image

After fixed:
image

Platforms Affected

  • Android
  • iOS
  • Web

Notes / Comments

This change is intended to be backward compatible.

Existing scanner behavior remains unchanged for successful scans; this only improves failure handling and error reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant