Skip to content
11 linesCodeBlameRaw
1/**
2 * Whether a request comes from a phone, for the pages that open on a list
3 * there and on its first item on a wider screen (Chat). The client hint
4 * when the browser sends it, else the user agent. A wrong guess costs a
5 * click: the page corrects itself once it knows its width.
6 */
7export function isPhone(headers: { get(name: string): string | null }): boolean {
8 const hint = headers.get("sec-ch-ua-mobile");
9 if (hint != null) return hint.trim() === "?1";
10 return /iPhone|iPod|Android.+Mobile|Mobile.+Firefox|Windows Phone/i.test(headers.get("user-agent") ?? "");
11}