惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
B
Blog RSS Feed
博客园_首页
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Google DeepMind News
Google DeepMind News
D
Docker
Blog — PlanetScale
Blog — PlanetScale
M
MIT News - Artificial intelligence
C
Check Point Blog
The Cloudflare Blog
T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
量子位
The GitHub Blog
The GitHub Blog
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
T
The Blog of Author Tim Ferriss
博客园 - 【当耐特】
Vercel News
Vercel News
P
Proofpoint News Feed
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
博客园 - 司徒正美

alexwlchan’s notes

What is WS11 1DB? Blocking referrers with Caddy How to type a Spanish question mark (¿) on a Mac Non-overlapping type comparisons and Python type checkers Why does t.Setenv panic after t.Parallel? Use Path.glob() and Path.rglob() for typed versions of glob.glob() Curious clocks and colourful eyes Track which templates are used by Jinja2 Archeologists distinguish between “sherds” and “shards” A single command to test all my changed Go packages Disable the new message animations in WhatsApp Finding high-churn folders that bother Backblaze Always-on SSH agent forwarding with my Git pushes Managing the caption of a photo with AppleScript (but not PhotoKit) Goodhart’s and Campbell’s Law are different Notes from The Cornishman No. 176 (Spring 2026) Notes from The Cornishman No. 176 (Spring 2026) GitUp can’t diff text files larger than 8MB Home Disable AirPods charging notifications Start a Caddy server in a subprocess during a Python session Filter a list of JSON object based on a list of tags HOME_GET_ME_HOME is a Citymapper Shortcuts action The FileExistsError exception exposes a filename attribute The red-lined bubble snail Why can’t Python connect to example.com? Useful type hints for Python How to truncate the middle of long command output AirPlay Receiver can interfere with Flask apps What’s the main prefix in SQLite queries?
Testing the width of a page on a mobile device using Play...
2026-05-07 · via alexwlchan’s notes

Create a new browser context with a narrow screen, then get document.body.scrollWidth to get the width of the displayed page.

One perennial source of bugs on this site is incorrect page widths on mobile devices: something isn’t wrapping or cropping properly, and it forces the whole page to be too wide.

For a long time I’ve been playing whack-a-mole with these bugs, but after writing about using Playwright, I realised I could write a regression test.

Here’s the approximate test I came up with. It creates a new browser context with a mobile screen size, opens the page I’m interested in, then runs some JavaScript on the page to measure the scroll width:

def test_page_is_right_size_on_narrow_screens(browser: Browser, base_url: str) -> None:
    """
    Check that on narrow screens, pages size to fit the screen.

    This is a regression test for issues I've had in the past where
    some wide element breaks the page when the window is narrower than it.
    """
    width = 350
    height = 650

    context = browser.new_context(viewport={"width": width, "height": height})

    page = context.new_page()
    page.goto(base_url + "/computers-and-code/")

    scroll_width = page.evaluate("document.body.scrollWidth")

    assert scroll_width == width

I don’t think I’d want to write a regression test for every CSS change, but it’s cool I can do it for this class of especially annoying bugs.