DEV Community

Vladimir Elchinov for Session Replay

Posted on

Your Bug Report Says "iPhone". The Screen Is 448 by 364.

Last Friday Safari arrived on a new device: Apple HomeView, which has a square 7-inch display that people mostly use with their voice. WebKit's announcement includes a line that will produce a particular kind of bug report for the next year:

Safari on HomeView also reports an iOS user agent.

So the report will say "iOS Safari". You will pick up an iPhone, open the page, and it will be fine. Not because the bug is not real, but because the report described the wrong thing. It classified the device, and the device class is the one fact that does not decide how a page renders.

A user agent is a claim. A viewport is a measurement.

Everything about how your layout behaves is decided by a handful of numbers the browser can measure directly: the width and height of the viewport, whether the primary pointer is precise, whether it can hover. The user agent is a string that a vendor chose, and on HomeView it says iOS.

WebKit is specific about what that hides. The screen is square, and "Some sites assume the viewport is always taller than 600px, while on HomeView it’s shorter." Its suggested test size is 448 by 364. Put a sticky header and a sticky footer on that and there is very little page left between them. Put a newsletter modal on it that is taller than the viewport, and its close button can sit below the bottom of the screen with no way to scroll to it.

None of that is in the words "iOS Safari".

Record the screen, not the category

The fix for the report is small. Capture what the page actually had to work with, at the moment it went wrong:

function describeScreen() {
  const vv = window.visualViewport
  return {
    viewport: `${window.innerWidth}x${window.innerHeight}`,
    visualViewport: vv ? `${Math.round(vv.width)}x${Math.round(vv.height)} @ ${vv.scale}` : null,
    devicePixelRatio: window.devicePixelRatio,
    pointer: matchMedia('(pointer: fine)').matches ? 'fine'
           : matchMedia('(pointer: coarse)').matches ? 'coarse' : 'none',
    hover: matchMedia('(hover: hover)').matches,
    orientation: screen.orientation ? screen.orientation.type : null,
    userAgent: navigator.userAgent,  // still worth keeping, just not trusting
  }
}
Enter fullscreen mode Exit fullscreen mode

The media features are not guesses. The Media Queries specification defines pointer as reflecting "the characteristics of the “primary” pointing device, as determined by the user agent", and coarse as "a pointing device of limited accuracy. Examples include touchscreens". hover is defined the same way, for the ability to hover over elements with that primary pointer. They answer the question your CSS is actually asking, which is why they are the thing to log.

Do not assume what any of them will say on HomeView. WebKit's post does not tell you, and the point of measuring is that you no longer need to be told.

Reproduce with the numbers, not the device

Once a report carries 448x364, you do not need the device. Responsive design mode in any browser will give you that viewport, and WebKit's own advice for anybody without the hardware is the same idea: "test your site on a phone in landscape orientation", which is short in the same way.

Without the numbers, you are guessing at a device from a string that, on this device, names the wrong one.

The general version

HomeView is just the cleanest recent example of an old problem. Device names are categories, and categories are how people describe what they were holding. Layout bugs live in the dimensions, the input method and the zoom level, and none of those survive the trip into "it's broken on my iPhone" unless something captured them before the person started typing.

Ask for the numbers, or collect them. Treat "iPhone" in a report as the beginning of a question, not the answer to one.

Top comments (0)