Web AR 上線前檢查清單:8 項需要量度的瀏覽器數據
Web AR Checklist: 8 Browser Numbers I Measure Before Launch
Dave Gordon 整理了一份 Web AR 上線前檢查清單,列出 8 項應在目標瀏覽器及裝置上核對的數據。檢查包括 WebGL 2.0、攝影機安全環境與實際設定、每幀時間預算、像素量、WASM 傳輸大小及實際載入的二進位檔;他亦建議在較舊裝置連續測試數分鐘。
TL;DR
- WebGL 2.0 and a secure context are hard stops. Check them against your own analytics browser list, not a support badge.
- Constraints are requests. Read
track.getSettings()back instead of trusting what you asked for. - Your frame budget is arithmetic, not measurement: 33 ms at 30 fps, 16.7 ms at 60.
- Device pixel ratio is the multiplier nobody writes down. 1280x720 at ratio 2 is twelve times the pixels of 640x480.
- The transfer size of the WASM module is the number that reaches users, not the file size.
- Handle
NotFoundError, not justNotAllowedError, or desktop users with no webcam get told they denied permission. - MediaPipe dropped its non-SIMD build in November 2026. TensorFlow.js still ships three binaries and picks at load time. Check which one your page actually fetched.
- Measure for minutes on your oldest phone, not seconds on your laptop.
Every web AR page I have shipped failed in the same place. The demo ran on my laptop and fell over on somebody's two-year-old Android.
The fix was never a better runtime. It was having eight numbers written down before launch instead of after. This is that list, in the order I run it.
What this web AR checklist measures, and what it does not
This is a harness. There are no frame rates from my own devices in this post, because the numbers that matter are the ones your effect produces on your device list, and mine would only tell you about my hardware.
So: specified here, all eight checks, the arithmetic you can redo on paper, and the browser behaviour each one depends on, with a link to the documentation that defines it. Produced here, nothing. You run it.
Check 1. Is WebGL 2.0 really present on every browser in your target list?
Face AR in a browser composites through WebGL, so WebGL 2.0 is the floor. Everything else here is pointless if this one fails.
The headline number looks safe. caniuse puts WebGL 2.0 at 97.29% global support, with no partial-support asterisk. The gap sits where you would expect: iOS Safari had it disabled by default from version 12 through 14.8, and only shipped it on by default in iOS 15. If your analytics still show a tail of old iPhones, that tail is the 2.7%.
How to run it: take your own analytics browser list, not a generic support claim, and check each entry against that table. Then feature-detect at runtime rather than trusting the user agent string.
const probe = document.createElement("canvas")
const hasWebGL2 = probe.getContext("webgl2") !== null
Use a throwaway canvas, as above. getContext() returns null both when the context type is unsupported and when the canvas has already been set to a different context mode, so running the probe on a canvas that something already called getContext("2d") on reports WebGL 2.0 as missing on a browser that supports it fine. That one cost me an afternoon.
Good answer: every browser in your top 95% of sessions returns a context. Bad answer: a tail of old iPhones and in-app webviews that you find out about from support tickets. caniuse does not break webviews out, so that one you have to test yourself.
Check 2. Does the page run in a secure context on every route that opens the camera?
getUserMedia() is a secure-context feature, and MDN states the consequence plainly: "in insecure contexts, navigator.mediaDevices is undefined, preventing access to getUserMedia()". The call is not available at all, so you get a TypeError on property access rather than a rejected promise.
Secure context is not the same as HTTPS. MDN counts HTTPS, file:/// and localhost, which is exactly why this breaks after dev and not during it.
How to run it: load every route that opens a camera over the real scheme users will get, including any embedded frame. A frame needs allow="camera", and the Permissions-Policy header has to permit the origin.
Good answer: the permission prompt appears on every route, first try. Bad answer: it works on your dev machine over localhost, which is a secure context, and dies on a staging host that is not.
Check 3. What does the camera hand you, versus what you asked for?
Constraints are requests. The browser honours them when hardware allows and quietly gives you something else when it does not, so read the track back instead of assuming.
How to run it: after the stream resolves, log track.getSettings() and compare width, height and frameRate against what you requested. Treat them as possibly absent rather than destructuring blind, because MDN notes that listed properties may be missing when the browser does not support them or the context does not provide them.
Use min, max or exact only when you genuinely want the call to fail instead of degrade. Those three are inherently mandatory, and MDN is specific about what failure looks like: the promise rejects with OverconstrainedError "and the user will not be prompted". No permission dialog, no camera, no obvious reason. Plain values and ideal are the ones that degrade.
Good answer: settings match the request on your low-end reference phone. Bad answer: you asked for 1280x720, you got 640x480, and your effect placement was tuned for the first one.
The exact errors worth catching by name
Not a numbered check, but it belongs here, because three of these come straight out of check 3.
Developers search error names verbatim, and these are specified rather than invented. Six of the seven below are DOMException rejections from getUserMedia(). TypeError is the JavaScript built-in, not a DOMException, so a handler that switches on instanceof DOMException misses it entirely.
NotAllowedError
The user denied access, or a permissions policy blocks the input. Treat it as a user-facing state with a retry path, never as a crash.
MDN's entry for this one also still says it covers an insecure browsing context. That half is stale: in an insecure context navigator.mediaDevices is undefined, so you never reach a rejection. Do not write your insecure-context handling against this error.
NotFoundError
No media tracks of the type you asked for exist. This is the desktop user with no webcam, and it is the one I see omitted most often. A page that handles NotAllowedError and not this one tells someone who has no camera that they denied permission, and then sends them into their browser settings to look for a toggle that will not help.
OverconstrainedError
No device met the constraints you marked mandatory. It carries a constraint property naming the one that could not be met, so log that property rather than the message. Note that this can fire before any permission grant, which makes it a fingerprinting surface as well as an error.
NotReadableError
Permission was granted, then a hardware error at the operating system, browser or page level blocked the device. On laptops this is usually another application holding the camera.
TypeError
Your constraints object was empty or every member was false, or you called the method in an insecure context where navigator.mediaDevices does not exist. The second cause is the common one, and see the note under NotAllowedError.
AbortError and SecurityError
The two I catch generically. AbortError is "permission and hardware were both fine, and it still did not work". SecurityError is user media support disabled on the document, by a mechanism each browser decides for itself. Neither has a useful retry path, so both go to the same fallback as NotReadableError.
Check 4. What is your per-frame budget in milliseconds?
This is the number most teams never write down, and it is arithmetic rather than measurement. At 30 frames per second the whole pipeline gets 1000 / 30, which is 33 ms per frame. At 60 frames per second it is 1000 / 60, or 16.7 ms. That budget covers capture, inference, effect rendering and compositing, not only the part you wrote.
How to run it: hang the timing off requestVideoFrameCallback so you time against delivered video frames instead of animation ticks. It is on HTMLVideoElement, it is in all three engines, and Firefox only shipped it in 132, so feature-detect:
if (!("requestVideoFrameCallback" in HTMLVideoElement.prototype)) {
// fall back to requestAnimationFrame and accept the mismatch
}
Two things about the timing itself that I got wrong for longer than I would like.
First, the callback already hands you now and a metadata object, so you do not need performance.now() on the entry side. That metadata carries presentedFrames, which is a far better dropped-frame detector than inferring drops from timing deltas, and processingDuration, which is decode time rather than your time.
Second, performance.now() is coarsened. MDN gives 5 microseconds when the document is cross-origin isolated and 100 microseconds when it is not. A rolling median is still worth keeping, because it rejects the frame that collided with a GC pause or a layout, but it does not buy you resolution below that floor. Quantisation is a deterministic floor on the clock, not zero-mean noise, so the median lands on the same grid every sample did. If your per-frame work is near a tenth of a millisecond, time across N frames and divide, or turn on cross-origin isolation and check crossOriginIsolated.
Good answer: a median well inside the budget, with headroom for the render. Bad answer: a median at 31 ms, which looks fine in a spreadsheet and stutters the moment a background task takes the GPU.
Check 5. How many pixels are you processing?
Resolution choices scale geometrically, and two of them compound.
| What you set | Pixels per frame | Relative cost |
|---|---|---|
| 640x480 | 307,200 | 1x |
| 1280x720 | 921,600 | 3x |
| 1280x720 at device pixel ratio 2 | 3,686,400 | 12x |
640x480 is 307,200 pixels a frame. Moving to 1280x720 makes it 921,600, which is three times the work. Rendering that at a device pixel ratio of 2 doubles each axis again, so the processed area reaches 3,686,400 pixels, twelve times the cheapest setting.
The ratio is the one people forget, because the display applies it and your code never mentions it.
How to run it: log window.devicePixelRatio on your reference devices, then log the real canvas backing-store size. Cap the ratio at 1 where effect detail is not the point.
Good answer: you chose a number. Bad answer: the ratio chose it for you on a high-density phone.
Check 6. What does the runtime weigh over the wire, not on disk?
Browser face tracking ships a WebAssembly module, and those files are large uncompressed. The current MediaPipe vision build is a fraction under 15 MB on disk. The figure that reaches your users is the transfer size, which is the compressed one.
How to run it: open the network panel, load the page cold with the cache disabled, and read the transferred column next to the resource size for the .wasm file, and for any .data companion file if your runtime still ships one, plus the Content-Encoding response header. If that header is missing on either, your host is serving it raw, and fixing that is the highest-return change available to you.
Purely as illustrative arithmetic, so you can see the shape: a 12 MB module at a compression ratio of 3.4 transfers as roughly 3.5 MB. Measure your own ratio. Do not borrow mine or anyone else's.
Good answer: Content-Encoding present, transfer size a fraction of file size. Bad answer: a multi-megabyte raw download in front of the first camera frame.
Check 7. Which WASM binary did this browser actually fetch?
This check changed under me while I was writing, which is the best argument for running it yourself rather than reading about it.
The shape used to be simple: browser CV runtimes shipped a baseline WASM binary and a SIMD one, detected support at load time, and picked. That is still exactly what TensorFlow.js does, and it ships three, not two. Its README says it loads "the appropriate WASM binary" after "testing the capabilities of your runtime", across tfjs-backend-wasm.wasm, tfjs-backend-wasm-simd.wasm and tfjs-backend-wasm-threaded-simd.wasm. The threaded one needs cross-origin isolation, and without it you silently fall back to SIMD-only.
MediaPipe no longer does this. Up to and including @mediapipe/tasks-vision 1.2.0 the package shipped a vision_wasm_nosimd_internal binary and selected against it at load time. From 1.2.2, published 3 November 2026, that file is gone and the SIMD detection with it. Current builds assume SIMD. I found this by diffing the published packages, because the MediaPipe documentation does not mention SIMD at all, before or after.
So the check is no longer "did it get the fast one". It is: which files does your runtime expect, and did your bundler actually serve them?
How to run it: load the page cold and read the network panel for every .wasm request, including the ones that 404. If you want to branch yourself, wasm-feature-detect is the small way to do it, and it is live again after a quiet stretch, at 1.10.1 in November 2026:
import { simd, threads } from "wasm-feature-detect"
if (await simd()) { /* ... */ }
Two bundler traps worth knowing. The runtime fetches its .wasm relative to the JavaScript file, so your bundler has to serve it as a static asset at a predictable path, and the failure mode is a 404 rather than a build error. And TensorFlow.js documents a second one: if your minifier rewrites typeof foo == "undefined" into foo === void 0, which terser does under its typeofs option, you get "_scriptDir is not defined" thrown from a web worker, but only in browsers that qualified for the SIMD plus threading build. A failure that appears on fast machines only is a bad afternoon.
Good answer: every .wasm your runtime asks for returns 200, and you know which one. Bad answer: one 404 on a binary, a silent fallback, and a performance mystery you chase for a day.
Check 8. What happens in minute three, not second one?
The first frames after model load are always slower, and sustained load behaves differently from a cold start as the device heats up. A reading taken over two seconds tells you about neither.
How to run it: run the effect continuously for several minutes on your oldest supported device, sample the frame time throughout, and keep the distribution rather than one average. If you are in requestVideoFrameCallback, keep presentedFrames alongside it, because a thermal throttle shows up as dropped frames before it shows up in a median. Record the discarded runs too, including the one where you had a video call open in another tab, because that is a real user condition.
Good answer: the median holds across the window and you know the shape of the tail. Bad answer: a single screenshot of a good second.
Why I stopped writing the tracking layer myself
Face tracking has to keep working across browser releases nobody on your team controls, and that maintenance has no end date. Check 7 is the small version of the argument: a dependency I do not maintain changed its binary layout three weeks ago, and the only way I learned was by diffing packages. Multiply that by every browser release.
I spent a long time on my own tracking layer before I accepted that, and I wrote up what moved me off it at more length.
The eight checks apply either way. They measure the page, not the runtime underneath it.
What I would do with one afternoon
Pick your oldest supported phone. Run checks 1, 2 and 6 first, because each one is a hard stop rather than a slow page. Then write down your frame budget from check 4 and measure against it for five minutes rather than five seconds.
Keep the numbers in the repository next to the integration code, so the next person to touch it starts from a baseline instead of an opinion. And put a date on them. Mine from a month ago would already be wrong about check 7.
來源:DEV Community · dev.to