4.9 KiB
4.9 KiB
Zoom Button Debug Guide
Problem
Zoom button code exists in CameraView.tsx (lines 136-154) but only renders when hasZoom={true}. Button not appearing indicates hasZoom is false.
Root Cause Investigation
The zoom detection logic is in Scanner.tsx lines 77-83:
const video = document.querySelector(`#${scannerId} video`) as HTMLVideoElement;
const track = (video?.srcObject as MediaStream)?.getVideoTracks()[0];
const caps = track?.getCapabilities() as any;
if (track && caps?.zoom) {
setHasZoom(true);
setMaxZoom(caps.zoom.max || 3);
}
Why it might fail:
videoelement not found in the DOM yetMediaStreamnot attached to video (srcObject is null/undefined)- Video track not initialized (getVideoTracks() returns empty array)
getCapabilities()returns empty object or doesn't expose zoom- Camera hardware doesn't support zoom capability
Debug Logging Added
Added comprehensive console logging at Scanner.tsx lines 80-97:
console.log('[Zoom Detection Debug]', {
videoFound: !!video,
trackFound: !!track,
trackState: track?.readyState,
capabilitiesExists: !!caps,
zoomCapability: caps?.zoom,
zoomMax: caps?.zoom?.max,
allCapabilities: Object.keys(caps || {}),
});
How to Diagnose
Step 1: Start the app
cd /data/programare_AI/tfm_ainventory
source backend/venv/bin/activate
python -m uvicorn backend.main:app --port 8916 &
cd frontend
NEXT_PUBLIC_API_URL=http://localhost:8916 npm run dev -- --port 8917 &
Step 2: Open browser and navigate to Scanner
- Go to
http://localhost:8917 - Navigate to the Scanner page
- Allow camera permissions
Step 3: Check browser console
- Open DevTools (F12)
- Go to Console tab
- Look for
[Zoom Detection Debug]log - If SUCCESS: see
[Zoom Detection SUCCESS]message - If FAILED: see
[Zoom Detection FAILED]message
Step 4: Interpret Results
If you see:
[Zoom Detection Debug] {
videoFound: true,
trackFound: true,
trackState: "live",
capabilitiesExists: true,
zoomCapability: {max: 8, min: 1, step: 1},
zoomMax: 8,
allCapabilities: ["width", "height", "aspectRatio", "zoom", ...]
}
[Zoom Detection SUCCESS] - hasZoom set to true, maxZoom: 8
✅ Zoom is supported! Button should appear. If it doesn't, issue is elsewhere.
If you see:
[Zoom Detection Debug] {
videoFound: true,
trackFound: true,
trackState: "live",
capabilitiesExists: true,
zoomCapability: undefined,
zoomMax: undefined,
allCapabilities: ["width", "height", "aspectRatio", ...]
}
[Zoom Detection FAILED] - Camera does not support zoom capability
❌ Zoom not supported! This is expected behavior - button correctly hidden.
If you see:
[Zoom Detection Debug] {
videoFound: false,
trackFound: false,
capabilitiesExists: false,
...
}
⚠️ Media not initialized! Camera permission likely denied or HTML5-QRCode not ready.
Next Steps Based on Findings
If zoom IS supported but button still not appearing:
- Check
CameraView.tsxprop passing - ishasZoombeing passed astrue? - Add debug log in CameraView to verify props:
console.log('CameraView props:', {hasZoom}) - Check for CSS issues - button might be rendered but invisible
If zoom NOT supported:
- Try different browser/device - some don't expose zoom via API
- Check browser console for permission errors
- Try HTTPS instead of HTTP (some APIs restricted to secure context)
- Test on mobile device - zoom support varies
Browser compatibility:
- Chrome/Chromium: Generally supports zoom (most reliable)
- Firefox: Limited zoom support via
applyConstraints() - Safari: Limited or no zoom support
- Mobile browsers: Varies significantly by platform and device
Implementation Details
Camera initialization flow:
Scanner.tsxuseEffect startshtml5-qrcode- After
start()completes, video element is in DOM - Query video element and get MediaStream track
- Call
track.getCapabilities()to check zoom support - If zoom available, enable button; if not, hide button
Zoom control (lines 219-226):
const handleZoomChange = async (nextZoom: number) => {
const video = document.querySelector(`#${scannerId} video`) as HTMLVideoElement;
const track = (video?.srcObject as MediaStream)?.getVideoTracks()[0];
if (track) {
await track.applyConstraints({ advanced: [{ zoom: nextZoom }] as any });
setZoom(nextZoom);
}
};
Zoom button logic (lines 139-143):
let nextZoom = 1;
if (zoom === 1) nextZoom = Math.min(2, maxZoom);
else if (zoom < maxZoom / 2) nextZoom = Math.floor(maxZoom / 2);
else if (zoom < maxZoom) nextZoom = maxZoom;
else nextZoom = 1;
Cycles: 1x → 2x → (max/2) → max → 1x
Files Modified
frontend/components/Scanner.tsx— Added debug logging (commit:2c711551)
Commit
2c711551 debug: add zoom capability detection logging to Scanner.tsx