Bug 1441585 manual verification
by Andreas Pehrson
HTML
<button onclick="test()">Start</button>
<div id="log"></div>
JavaScript
function logOk(msg) {
let p = document.createElement("p");
p.style = "color:green;margin:0;";
p.textContent = msg;
log.appendChild(p);
}
function logErr(msg) {
let p = document.createElement("p");
p.style = "color:red;margin:0;";
p.textContent = msg;
log.appendChild(p);
}
async function testAll(widths) {
for (let width of widths) {
let v = document.createElement("video");
v.setAttribute("autoplay", "autoplay");
let stream = null;
try {
stream = await navigator.mediaDevices.getUserMedia({video: {width: width}});
v.srcObject = stream;
await new Promise(r => v.onloadedmetadata = r);
logOk(`OK success for width ${width}, got ${v.videoWidth}x${v.videoHeight}`);
} catch(e) {
if (e.name == "OverconstrainedError") {
logOk(`OK OverconstrainedError for width ${width}`);
} else {
throw new Error(`${e.name} for width ${width}: ${e.message}`);
}
} finally {
if (stream) {
stream.getTracks().forEach(t => t.stop());
}
}
}
}
function test() {
while (log.lastChild) { log.removeChild(log.lastChild); }
const widths = [60, 120, 176, 240,
320, 400, 500, 640,
700, 800, 960, 1080,
1156, 1280, 1400, 1500,
1600, 1700, 1800, 1920,
2200, 2400, 2600, 3000,
3400, 3700, 4000];
testAll(widths).then(() => {
logOk(`DONE All ${widths.length} cases tested`);
}, (e) => {
logErr(`FAILED ${e.message}`);
});
}