Testing mobile-friendliness of client sites with Playwright
Google retired its Mobile-Friendly Test tool in December 2023, but "does the site work on a phone?" is still the first question to ask about a small business website. It's also the easiest problem to show an owner. This
Google retired its Mobile-Friendly Test tool in December 2023, but "does the site work on a phone?" is still the first question to ask about a small business website. It's also the easiest problem to show an owner. This post builds a short Playwright script that loads a page as an iPhone, checks five things an owner would notice, and saves a screenshot you can attach to a message or a report.
Short answer: use Playwright's built-in device profiles to load the page with a phone's screen size, user agent and touch support, then check in the page: is there a viewport meta tag, does the content fit the screen width, is any body text under 12px, are tap targets at least 24 by 24 CSS pixels, and is there a tappable phone number. Compare overflow against screen.width, not innerWidth, or you'll miss the most common problem.
Why not just resize the browser window?
A narrow desktop window isn't a phone. Phones report a different user agent, use touch, and apply the viewport meta tag. Playwright's device descriptors set all of that in one line, so the page behaves the way it would on a real device:
const context = await browser.newContext({ ...devices['iPhone 13'] });
Setup
mkdir mobile-check && cd mobile-check
npm init -y
npm i playwright
npx playwright install chromium
The script
// mobile-check.mjs: check how a page behaves on a phone with Playwright.
// Usage: node mobile-check.mjs https://example.com
import { chromium, devices } from 'playwright';
const url = process.argv[2];
if (!url) {
console.error('Usage: node mobile-check.mjs <url>');
process.exit(1);
}
const browser = await chromium.launch();
const context = await browser.newContext({ ...devices['iPhone 13'] });
const page = await context.newPage();
await page.goto(url, { waitUntil: 'load', timeout: 30000 });
const result = await page.evaluate(() => {
// Compare against the phone's screen width, not innerWidth: mobile browsers
// widen the layout viewport when content overflows, which hides the problem.
const vw = screen.width;
const viewport = document.querySelector('meta[name="viewport"]')?.content || null;
const overflow = document.documentElement.scrollWidth > vw + 1;
// Text smaller than 12px is hard to read on a phone.
const small = [...document.querySelectorAll('p, li, a, span, td')]
.filter((el) => el.offsetParent && el.textContent.trim().length > 20)
.filter((el) => parseFloat(getComputedStyle(el).fontSize) < 12).length;
// Tap targets smaller than 24x24 CSS px (WCAG 2.2 minimum target size).
const tiny = [...document.querySelectorAll('a, button, input, select')]
.filter((el) => el.offsetParent)
.filter((el) => {
const r = el.getBoundingClientRect();
return r.width > 0 && (r.width < 24 || r.height < 24);
}).length;
const tel = !!document.querySelector('a[href^="tel:"]');
return { vw, viewport, overflow, small, tiny, tel };
});
await page.screenshot({ path: 'mobile.png', fullPage: false });
await browser.close();
const rows = [
['Viewport meta tag', result.viewport ? 'OK' : 'Missing'],
['Fits the screen (no sideways scroll)', result.overflow ? 'No' : 'OK'],
['Text smaller than 12px', result.small ? `${result.small} elements` : 'None'],
['Tap targets under 24x24px', result.tiny ? `${result.tiny} elements` : 'None'],
['Tappable phone number', result.tel ? 'OK' : 'Missing'],
];
console.log(`Mobile check for ${url} (${result.vw}px wide)`);
for (const [k, v] of rows) console.log(`- ${k}: ${v}`);
console.log('Screenshot saved to mobile.png');
What each check means for the owner
- Viewport meta tag. Without it, phones render the page at a desktop width (usually 980px) and shrink it. Everything looks tiny.
- Fits the screen. If something is wider than the screen, people scroll sideways to read. Very common with fixed-width images, tables and embedded maps.
- Small text. Body text under 12px is hard to read on a phone. It's a simple threshold, not a standard, so read the screenshot before quoting it.
- Tap targets. WCAG 2.2 sets a minimum size for things you tap:
"The size of the target for pointer inputs is at least 24 by 24 CSS pixels"
W3C, WCAG 2.2, Success Criterion 2.5.8 Target Size (Minimum)
The criterion has exceptions, such as links inside a sentence, so treat the count as a prompt to look, not a verdict.
-
Tappable phone number. For a plumber or a dentist, the most important button on the page is a
tel:link.
The innerWidth trap
The first version of this script compared scrollWidth to window.innerWidth. On a test page with a 900px-wide block, it reported no overflow. The reason: when content is wider than the screen, mobile browsers widen the layout viewport to fit it, so innerWidth grew to match. Comparing against screen.width (390px for the iPhone 13 profile) catches it.
Here's the output on a deliberately broken local test page, with a viewport tag but a 900px-wide block, 10px text, a tiny link and no tel: link:
Mobile check for http://localhost:8766/ (390px wide)
- Viewport meta tag: OK
- Fits the screen (no sideways scroll): No
- Text smaller than 12px: 1 elements
- Tap targets under 24x24px: 1 elements
- Tappable phone number: Missing
Screenshot saved to mobile.png
And after fixing the page:
Mobile check for http://localhost:8766/ (390px wide)
- Viewport meta tag: OK
- Fits the screen (no sideways scroll): OK
- Text smaller than 12px: None
- Tap targets under 24x24px: None
- Tappable phone number: OK
Screenshot saved to mobile.png
Using it on prospects
Run it on a short list of local business sites before you reach out:
while read -r url; do
echo "== $url"
node mobile-check.mjs "$url"
done < urls.txt
Then lead with one finding the owner can check on their own phone in ten seconds, like "the phone number on your homepage isn't tappable," and attach the screenshot. If you're still building the list, search one trade in your city and open each site on your phone. A lead tool like LeadReef can also list local businesses whose websites are outdated, broken on mobile or missing, by city and trade, and the first search is free.
Limitations
-
One page, one device. Check the homepage and the contact page; add a second profile like
devices['Pixel 7']if you want. - Cookie banners and pop-ups can cover content and add tap targets. Look at the screenshot.
- Thresholds are rules of thumb, except the WCAG target size, which still has exceptions.
- Be gentle with other people's servers. A couple of pages per site is plenty.
Quick reference
-
devices['iPhone 13']sets viewport, user agent, touch and pixel ratio. - Check overflow with
scrollWidth > screen.width, notinnerWidth. - WCAG 2.2 minimum target size is 24 by 24 CSS pixels, with exceptions.
- A missing viewport tag makes phones render at desktop width.
- Always look at the screenshot before you send anything.
Sources (checked November 2026): Playwright docs, "Emulation" (playwright.dev/docs/emulation); W3C, WCAG 2.2, Success Criterion 2.5.8; Search Engine Land, "Google officially drops Mobile Usability report, Mobile-Friendly Test tool and Mobile-Friendly Test API" (December 2023).
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.
