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

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
J
Java Code Geeks
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Last Week in AI
Last Week in AI
雷峰网
雷峰网
博客园_首页
小众软件
小众软件
美团技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
腾讯CDC
P
Proofpoint News Feed
MongoDB | Blog
MongoDB | Blog
Google DeepMind News
Google DeepMind News
MyScale Blog
MyScale Blog
U
Unit 42
The Cloudflare Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Security Blog
Microsoft Security Blog
大猫的无限游戏
大猫的无限游戏
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 叶小钗

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.