A Capacitor plugin for embedding a live camera feed directly into your app.
- πΉ Embed a live camera feed directly into your app.
- πΈ Capture photos or frames from the camera preview.
- π Barcode detection support.
- π± Virtual device support for automatic lens selection based on zoom level and focus (iOS only).
- π¦ Control zoom, flash and torch modes programmatically.
- β‘ High performance with optimized native implementations.
- π― Simple to use with a clean and intuitive API.
- π Works seamlessly on iOS, Android, and Web.

Install the plugin using npm:
npm install capacitor-camera-view
npx cap sync
Add the following keys to your app's Info.plist
file:
<key>NSCameraUsageDescription</key>
<string>To capture photos and videos</string>
The CAMERA
permission is automatically added by Capacitor. Ensure your AndroidManifest.xml
includes it if needed for specific configurations:
<uses-permission android:name="android.permission.CAMERA" />
import { CameraView } from 'capacitor-camera-view';
// Start the camera preview
const startCamera = async () => {
try {
await CameraView.start();
console.log('Camera started');
// Add the CSS class to make the WebView transparent
document.body.classList.add('camera-running');
} catch (e) {
console.error('Error starting camera:', e);
}
};
// Stop the camera preview
const stopCamera = async () => {
try {
document.body.classList.remove('camera-running');
await CameraView.stop();
console.log('Camera stopped');
} catch (e) {
console.error('Error stopping camera:', e);
}
};
// Capture a photo
const capturePhoto = async () => {
try {
const result = await CameraView.capture();
console.log('Photo captured:', result.photo); // Base64 encoded string
} catch (e) {
console.error('Error capturing photo:', e);
}
};
To display the camera view through your app, you need to ensure that the WebView is made transparent. For Ionic applications, this can be done by adding the following styles to your global CSS file and applying the respective class to the body element as soon as you start the camera (see example app on how to do this in Angular):
body.camera-running {
visibility: hidden;
--background: transparent;
--ion-background-color: transparent;
}
.camera-modal {
visibility: visible;
}
On supported iPhone models (like the Pro series), this plugin can utilize the virtual triple camera. This feature combines the ultra-wide, wide, and telephoto cameras into a single virtual device. iOS will then automatically switch between the physical cameras based on factors like zoom level and lighting conditions, providing seamless transitions and optimal image quality across a wider zoom range. You can enable this by setting the useTripleCameraIfAvailable
option to true
when calling start()
.
Pros:
- Smoother zooming experience across different focal lengths.
- Automatic selection of the best lens for the current scene and zoom factor.
Cons:
- Slightly higher resource usage compared to using a single physical camera (the camera view will take a little longer until initialized).
- Only available on specific iPhone models with triple camera systems.
For more details on the underlying technology, refer to Apple's documentation on AVCaptureDevice.builtInTripleCamera.
Alternatively, you can specify the preferredCameraDeviceTypes
option in the CameraSessionConfiguration
to prioritize specific virtual cameras, such as the dual camera system. While this provides similar functionality, the useTripleCameraIfAvailable
option offers the advantage of a smoother transition during camera initialization and lens switching (blurred overlay).
This plugin supports real-time barcode detection directly from the live camera feed.
How it works:
- iOS: Utilizes the native
AVCaptureMetadataOutput
. - Android: Utilizes Google's ML Kit Barcode Scanning.
- Web: Uses the Barcode Detection API where available in the browser.
Enabling Barcode Detection:
To enable this feature, set the enableBarcodeDetection
option to true
when calling the start()
method:
await CameraView.start({ enableBarcodeDetection: true });
Listening for Barcodes:
Once enabled, you can listen for the barcodeDetected
event to receive data about scanned barcodes:
import { CameraView } from 'capacitor-camera-view';
CameraView.addListener('barcodeDetected', (data) => {
console.log('Barcode detected:', data.value, data.type);
// Handle the detected barcode data (e.g., display it, navigate)
});
See the BarcodeDetectionData
interface for details on the event payload.
To see the plugin in action, check out the example app in the example-app
folder. The app demonstrates how to integrate and use the Capacitor Camera View plugin in an Ionic Angular project.
This project uses semantic-release for automated versioning and changelog generation based on conventional commits.
Follow the Conventional Commits specification for your commit messages. Example:
feat(camera): add autofocus support
fix(android): resolve crash on startup
chore: update dependencies
start(...)
stop()
isRunning()
capture(...)
captureSample(...)
flipCamera()
getAvailableDevices()
getZoom()
setZoom(...)
getFlashMode()
getSupportedFlashModes()
setFlashMode(...)
isTorchAvailable()
getTorchMode()
setTorchMode(...)
checkPermissions()
requestPermissions()
addListener('barcodeDetected', ...)
removeAllListeners(...)
- Interfaces
- Type Aliases
Main plugin interface for Capacitor Camera View functionality.
start(options?: CameraSessionConfiguration | undefined) => Promise<void>
Start the camera view with optional configuration.
Param | Type | Description |
---|---|---|
options |
CameraSessionConfiguration |
- Configuration options for the camera session |
Since: 1.0.0
stop() => Promise<void>
Stop the camera view and release resources.
Since: 1.0.0
isRunning() => Promise<IsRunningResponse>
Check if the camera view is currently running.
Returns: Promise<IsRunningResponse>
Since: 1.0.0
capture<T extends CaptureOptions>(options: T) => Promise<CaptureResponse<T>>
Capture a photo using the current camera configuration.
Param | Type | Description |
---|---|---|
options |
T |
- Capture configuration options |
Returns: Promise<CaptureResponse<T>>
Since: 1.0.0
captureSample<T extends CaptureOptions>(options: T) => Promise<CaptureResponse<T>>
Captures a frame from the current camera preview without using the full camera capture pipeline.
Unlike capture()
which may trigger hardware-level photo capture on native platforms,
this method quickly samples the current video stream. This is suitable computer vision or
simple snapshots where high fidelity is not required.
On web this method does exactly the same as capture()
as it only captures a frame from the video stream
because unfortunately ImageCapture API is
not yet well supported on the web.
Param | Type | Description |
---|---|---|
options |
T |
- Capture configuration options |
Returns: Promise<CaptureResponse<T>>
Since: 1.0.0
flipCamera() => Promise<void>
Switch between front and back camera.
Since: 1.0.0
getAvailableDevices() => Promise<GetAvailableDevicesResponse>
Get available camera devices for capturing photos.
Returns: Promise<GetAvailableDevicesResponse>
Since: 1.0.0
getZoom() => Promise<GetZoomResponse>
Get current zoom level information and available range.
Returns: Promise<GetZoomResponse>
Since: 1.0.0
setZoom(options: { level: number; ramp?: boolean; }) => Promise<void>
Set the camera zoom level.
Param | Type | Description |
---|---|---|
options |
{ level: number; ramp?: boolean; } |
- Zoom configuration options |
Since: 1.0.0
getFlashMode() => Promise<GetFlashModeResponse>
Get current flash mode setting.
Returns: Promise<GetFlashModeResponse>
Since: 1.0.0
getSupportedFlashModes() => Promise<GetSupportedFlashModesResponse>
Get supported flash modes for the current camera.
Returns: Promise<GetSupportedFlashModesResponse>
Since: 1.0.0
setFlashMode(options: { mode: FlashMode; }) => Promise<void>
Set the camera flash mode.
Param | Type | Description |
---|---|---|
options |
{ mode: FlashMode; } |
- Flash mode configuration options |
Since: 1.0.0
isTorchAvailable() => Promise<IsTorchAvailableResponse>
Check if the device supports torch (flashlight) functionality.
Returns: Promise<IsTorchAvailableResponse>
Since: 1.2.0
getTorchMode() => Promise<GetTorchModeResponse>
Get the current torch (flashlight) state.
Returns: Promise<GetTorchModeResponse>
Since: 1.2.0
setTorchMode(options: { enabled: boolean; level?: number; }) => Promise<void>
Set the torch (flashlight) mode and intensity.
Param | Type | Description |
---|---|---|
options |
{ enabled: boolean; level?: number; } |
- Torch configuration options |
Since: 1.2.0
checkPermissions() => Promise<PermissionStatus>
Check camera permission status without requesting permissions.
Returns: Promise<PermissionStatus>
Since: 1.0.0
requestPermissions() => Promise<PermissionStatus>
Request camera permission from the user.
Returns: Promise<PermissionStatus>
Since: 1.0.0
addListener(eventName: 'barcodeDetected', listenerFunc: (data: BarcodeDetectionData) => void) => Promise<PluginListenerHandle>
Listen for barcode detection events. This event is emitted when a barcode is detected in the camera preview.
Param | Type | Description |
---|---|---|
eventName |
'barcodeDetected' |
- The name of the event to listen for ('barcodeDetected') |
listenerFunc |
(data: BarcodeDetectionData) => void |
- The callback function to execute when a barcode is detected |
Returns: Promise<PluginListenerHandle>
Since: 1.0.0
removeAllListeners(eventName?: string | undefined) => Promise<void>
Remove all listeners for this plugin.
Param | Type | Description |
---|---|---|
eventName |
string |
- Optional event name to remove listeners for |
Since: 1.0.0
Configuration options for starting a camera session.
Prop | Type | Description | Default |
---|---|---|---|
enableBarcodeDetection |
boolean |
Enables the barcode detection functionality | false |
position |
CameraPosition |
Position of the camera to use | 'back' |
deviceId |
string |
Specific device ID of the camera to use If provided, takes precedence over position | |
useTripleCameraIfAvailable |
boolean |
Whether to use the triple camera if available (iPhone Pro models only) | false |
preferredCameraDeviceTypes |
CameraDeviceType[] |
Ordered list of preferred camera device types to use (iOS only). The system will attempt to use the first available camera type in the list. If position is also provided, the system will use the first available camera type that matches the position and is in the list. This will fallback to the default camera type if none of the preferred types are available. | undefined - system will decide based on position/deviceId |
zoomFactor |
number |
The initial zoom factor to use | 1.0 |
containerElementId |
string |
Optional HTML ID of the container element where the camera view should be rendered. If not provided, the camera view will be appended to the document body. Web only. |
Response for checking if the camera view is running.
Prop | Type | Description |
---|---|---|
isRunning |
boolean |
Indicates if the camera view is currently active and running |
Configuration options for capturing photos and samples.
Prop | Type | Description | Default | Since |
---|---|---|---|---|
quality |
number |
The JPEG quality of the captured photo/sample on a scale of 0-100 | 1.1.0 | |
saveToFile |
boolean |
If true, saves to a temporary file and returns the web path instead of base64. The web path can be used to set the src attribute of an image for efficient loading and rendering. This reduces the data that needs to be transferred over the bridge, which can improve performance especially for high-resolution images. | false |
1.1.0 |
Response for getting available camera devices.
Prop | Type | Description |
---|---|---|
devices |
CameraDevice[] |
An array of available camera devices |
Represents a physical camera device on the device.
Prop | Type | Description |
---|---|---|
id |
string |
The unique identifier of the camera device |
name |
string |
The human-readable name of the camera device |
position |
CameraPosition |
The position of the camera device (front or back) |
deviceType |
CameraDeviceType |
The type of the camera device (e.g., wide, ultra-wide, telephoto) - iOS only |
Response for getting zoom level information.
Prop | Type | Description |
---|---|---|
min |
number |
The minimum zoom level supported |
max |
number |
The maximum zoom level supported |
current |
number |
The current zoom level |
Response for getting the current flash mode.
Prop | Type | Description |
---|---|---|
flashMode |
FlashMode |
The current flash mode setting |
Response for getting supported flash modes.
Prop | Type | Description |
---|---|---|
flashModes |
FlashMode[] |
An array of flash modes supported by the current camera |
Response for checking torch availability.
Prop | Type | Description |
---|---|---|
available |
boolean |
Indicates if the device supports torch (flashlight) functionality |
Response for getting the current torch mode.
Prop | Type | Description |
---|---|---|
enabled |
boolean |
Indicates if the torch is currently enabled |
level |
number |
The current torch intensity level (0.0 to 1.0, iOS only). Always 1.0 on Android when enabled |
Response for the camera permission status.
Prop | Type | Description |
---|---|---|
camera |
PermissionState |
The state of the camera permission |
Prop | Type |
---|---|
remove |
() => Promise<void> |
Data for a detected barcode.
Prop | Type | Description |
---|---|---|
value |
string |
The decoded string value of the barcode |
displayValue |
string |
The display value of the barcode (may differ from the raw value) |
type |
string |
The type/format of the barcode (e.g., 'qr', 'code128', etc.) |
boundingRect |
BoundingRect |
The bounding rectangle of the barcode in the camera frame. |
Rectangle defining the boundary of the barcode in the camera frame. Coordinates are normalized between 0 and 1 relative to the camera frame.
Prop | Type | Description |
---|---|---|
x |
number |
X-coordinate of the top-left corner |
y |
number |
Y-coordinate of the top-left corner |
width |
number |
Width of the bounding rectangle (should match the actual width of the barcode) |
height |
number |
Height of the bounding rectangle (should match the actual height of the barcode) |
Position options for the camera.
- 'front': Front-facing camera
- 'back': Rear-facing camera
'front' | 'back'
Available camera device types for iOS. Maps to AVCaptureDevice DeviceTypes in iOS.
'wideAngle' | 'ultraWide' | 'telephoto' | 'dual' | 'dualWide' | 'triple' | 'trueDepth'
Response for capturing a photo
This will contain either a base64 encoded string or a web path to the captured photo,
depending on the saveToFile
option in the CaptureOptions.
T['saveToFile'] extends true ? { /** The web path to the captured photo that can be used to set the src attribute of an image for efficient loading and rendering (when saveToFile is true) / webPath: string; } : { /* The base64 encoded string of the captured photo (when saveToFile is false or undefined) */ photo: string; }
Flash mode options for the camera.
- 'off': Flash disabled
- 'on': Flash always on
- 'auto': Flash automatically enabled in low-light conditions
'off' | 'on' | 'auto'
'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'