Of course. Here is a complete, single-file HTML script that does exactly what you asked for.
It will:
- Request access to your camera (and only the camera).
- Attempt to get the highest possible resolution from it.
- Display the feed in a large video player that fills most of the screen.
- Show you the actual resolution of the video stream being captured.
How to Use
- Copy the code below.
- Paste it into a new text file.
- Save the file with an
.html extension (e.g., cameratest.html).
- Open the file in Firefox (or any modern browser like Chrome, Edge, Safari).
- The browser will ask for permission to use your camera. Click "Allow".
The Script
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Browser Camera Quality Test</title>
<style>
body {
background-color: #1a1a1a;
color: #e0e0e0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
margin: 0;
padding: 2rem;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
box-sizing: border-box;
}
h1 {
color: #ffffff;
margin-bottom: 1rem;
}
#video-container {
width: 90vw;
max-width: 1280px; /* A sensible max width for ultra-wide screens */
background-color: #000;
border: 2px solid #333;
border-radius: 8px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
position: relative;
}
video {
display: block;
width: 100%;
height: auto;
border-radius: 6px;
/* Flip the video horizontally for a more natural "mirror" feel */
transform: scaleX(-1);
}
#status-info {
margin-top: 1.5rem;
padding: 0.75rem 1.25rem;
background-color: #2c2c2c;
border-radius: 6px;
font-size: 1.2rem;
font-family: "SF Mono", "Fira Code", "Source Code Pro", monospace;
text-align: center;
min-width: 400px;
}
</style>
</head>
<body>
<h1>Camera Quality Test</h1>
<div id="video-container">
<!-- The `autoplay` and `playsinline` attributes are crucial for the video to start automatically -->
<video id="camera-feed" autoplay playsinline></video>
</div>
<div id="status-info">
Requesting camera access...
</div>
<script>
const videoElement = document.getElementById('camera-feed');
const statusInfoElement = document.getElementById('status-info');
// --- Configuration ---
// We request video only, no audio.
// We use 'ideal' to ask for the highest resolution. The browser will try to match this
// but will fall back to the camera's best available resolution if 4K isn't supported.
const constraints = {
audio: false,
video: {
width: { ideal: 4096 }, // Request 4K width
height: { ideal: 2160 }, // Request 4K height
// To test a specific camera (e.g., on a phone with multiple cameras):
// facingMode: 'user' // 'user' for front camera, 'environment' for back camera
}
};
async function startCamera() {
try {
// Request access to the camera with our high-quality constraints
const stream = await navigator.mediaDevices.getUserMedia(constraints);
// Connect the camera stream to our video element
videoElement.srcObject = stream;
// When the video metadata is loaded, we can get the actual stream resolution
videoElement.onloadedmetadata = () => {
// Get the video track from the stream
const videoTrack = stream.getVideoTracks()[0];
const settings = videoTrack.getSettings();
const actualWidth = settings.width;
const actualHeight = settings.height;
console.log(`Stream active with resolution: ${actualWidth}x${actualHeight}`);
statusInfoElement.textContent = `✅ Stream Active | Resolution: ${actualWidth}x${actualHeight}`;
};
} catch (error) {
console.error("Error accessing the camera:", error);
let errorMessage = "An unknown error occurred.";
if (error.name === "NotAllowedError" || error.name === "PermissionDeniedError") {
errorMessage = "🚫 Camera access was denied. Please allow camera access in your browser settings.";
} else if (error.name === "NotFoundError" || error.name === "DevicesNotFoundError") {
errorMessage = "❌ No camera was found on this device.";
} else if (error.name === "NotReadableError" || error.name === "TrackStartError") {
errorMessage = "⚠️ Camera is already in use by another application.";
} else if (error.name === "OverconstrainedError" || error.name === "ConstraintNotSatisfiedError") {
errorMessage = "❌ Your camera does not support the requested resolution.";
}
statusInfoElement.textContent = errorMessage;
statusInfoElement.style.color = '#ff6b6b';
}
}
// Run the function to start the camera
startCamera();
</script>
</body>
</html>