Skip to content

Camera Capture ​

A live camera view that takes photos with the Media Capture and Streams API, to build into your own components.

Type: Building Block

Available in: Not exposed in the Lightning App Builder - intended to be embedded in other components.

Attributes ​

NameTypeDefaultDescription
camerastring'front'The camera to ask for, front or back. Devices with only one camera use that one.
hide-controlsbooleanfalseIf present, the buttons are hidden, so that a parent can use its own with the start, stop and capture methods.
startmethodStarts the camera. A running camera is stopped first.
stopmethodStops the camera. Does nothing if it isn't running.
capturemethodTakes a photo and fires the capture event. Does nothing if the camera isn't running.

Events ​

NameDetailDescription
capture{ dataUrl }Fired when a photo was taken. dataUrl contains the photo as a PNG data URL.

Usage ​

html
<c-camera-capture camera="back" oncapture={handleCapture}></c-camera-capture>

What happens with the photo is up to you. Take User Profile Picture uses it for the profile of the current user, and the camera stops by itself when the component is removed or hidden, for example when the user moves on to another page in Lightning.

Custom Labels ​

The texts users see are Custom Labels, so they can be translated in Setup with the Translation Workbench. Copy them together with the component.

NameValue
CameraCapture_CapturePhotoCapture Photo
CameraCapture_ErrorError
CameraCapture_ErrorAccessingCameraError accessing camera
CameraCapture_NotSupportedgetUserMedia is not supported in this browser
CameraCapture_StartCameraStart Camera
CameraCapture_StopCameraStop Camera
ErrorUtils_UnknownErrorUnknown error

Component Dependencies ​

NameTypeDescription
errorUtilsLWCShared functions to read error messages and show error toasts.

Released under the MIT License. · llms.txt for AI agents