Using in an iframe
If your camera component is rendered inside an <iframe>, you need to explicitly grant camera permissions.
Allowing Camera Access
Add the allow attribute to your iframe:
<iframe
src="https://your-camera-app.com"
allow="camera;"
width="640"
height="480"
/>
Without the allow="camera;" attribute, the browser will block getUserMedia inside the iframe, even if the parent page has camera access.
Permissions Policy
Modern browsers use the Permissions Policy (formerly Feature Policy) to control which features iframes can use.
For the camera to work in an iframe, the camera feature must be allowed:
<!-- Allow camera for same-origin iframes -->
<iframe src="/camera-view" allow="camera;"></iframe>
<!-- Allow camera for specific origin -->
<iframe src="https://camera.example.com" allow="camera https://camera.example.com;"></iframe>
<!-- Allow camera for any origin (use with caution) -->
<iframe src="https://third-party.com" allow="camera *;"></iframe>
Cross-Origin Considerations
If the iframe loads content from a different origin, you also need:
- The parent page must allow the
camerafeature in the iframe via theallowattribute. - The iframe content must be served over HTTPS.
- The user will still see the browser's camera permission prompt.
Common Issues
Camera Not Working in iframe
If the camera doesn't work inside an iframe:
- ✅ Check that
allow="camera;"is set on the<iframe>tag - ✅ Ensure the iframe content is served over HTTPS
- ✅ Verify that no
Permissions-PolicyHTTP header is blocking camera access - ✅ Check browser dev tools console for permission errors
Safari-Specific Notes
Safari has stricter iframe permission policies:
- Camera access in cross-origin iframes may require user gesture
- The
allowattribute must explicitly includecamera - Safari may block camera access in iframes that aren't visible