playwright_patterns.md 'Browser launch skeleton' crashes with UnicodeEncodeError on Windows when aria_snapshot output contains non-cp1252 characters

オープン 初心者向け
#7 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
ドキュメント
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
playwright, python
領域
documentation

調査の方向性

skills/webwright/reference/playwright_patterns.md から始め、16–46 行目の Browser 起動スケルトン、65 行目の対応するパターン、129–166 行目の Final-script のインストルメンテーションを確認します。cp1252 を使用しない aria_snapshot 出力で Windows 上の再現を実行し、その後、例がクラッシュしなくなったことと、追加された Windows に関する注記で stdout のエンコーディング問題が説明されていることを確認します。

索引モデルが issue の本文から書いたものです。

説明

Environment

  • OS: Windows 11 Home 10.0.26200
  • Python: 3.12.10 (Windows Store distribution)
  • Default sys.stdout.encoding: cp1252
  • Playwright: Firefox 146.0.1 (playwright firefox v1509)
  • Webwright commit: 29fc4b4

Summary

The canonical "Browser launch skeleton" code block in skills/webwright/reference/playwright_patterns.md (lines 16–46) and the sibling pattern on line 65 both end with print(...aria_snapshot()). On any page whose accessibility tree contains characters outside cp1252 — for example an arxiv search results page, which carries U+25BD WHITE DOWN-POINTING TRIANGLE inside the "▽ More" abstract toggle — the print call crashes with UnicodeEncodeError under Windows's default cp1252 stdout encoding.

A Windows user who copy-pastes the recommended explore skeleton from Webwright's own reference doc will hit this on the very first non-trivial page they look at. The "Final-script instrumentation" example on lines 129–166 is affected at line 143's print(line, end="") for the same reason (the file write uses open(..., encoding="utf-8") so the log file itself is fine, but the mirror print to stdout still hits cp1252).

Reproduction

# Windows PowerShell, Python 3.12 default install, no PYTHONIOENCODING set
python - <<'PY'
import asyncio
from playwright.async_api import async_playwright

async def main():
    async with async_playwright() as pw:
        browser = await pw.firefox.launch(headless=True)
        ctx = await browser.new_context(viewport={"width": 1280, "height": 1800})
        page = await ctx.new_page()
        await page.goto(
            "https://arxiv.org/search/?query=browser+agent&searchtype=all",
            wait_until="domcontentloaded",
        )
        snapshot = await page.locator("body").aria_snapshot()
        print("ARIA:", snapshot)
        await browser.close()

asyncio.run(main())
PY

Expected

ARIA snapshot prints to stdout without crashing.

Actual

UnicodeEncodeError: 'charmap' codec can't encode character '▽' in position 4958: character maps to <undefined>
  File ".../Lib/encodings/cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]

Root cause

Python on Windows defaults sys.stdout.encoding to cp1252 unless PYTHONIOENCODING=utf-8 is set in the environment or the script explicitly reconfigures stdout. Playwright's aria_snapshot() returns the full accessibility tree as a string that frequently contains non-cp1252 glyphs from the page (typography symbols, emoji, CJK characters, math symbols).

Suggested fix

At the top of every code skeleton in skills/webwright/reference/playwright_patterns.md (the "Browser launch skeleton" example and the "Final-script instrumentation" example), force utf-8 stdout:

import sys
sys.stdout.reconfigure(encoding="utf-8")

Add a short "Windows note" callout next to the skeleton explaining why this line is needed. The fix is portable (no-op on POSIX where stdout is already utf-8) and keeps the patterns reliable on the platform where the bug bites hardest.

Happy to send a PR.

主要言語
Python
スター
6k
フォーク
385
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/Webwright のほかの issue

microsoft/Webwright の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。