playwright_patterns.md 'Browser launch skeleton' crashes with UnicodeEncodeError on Windows when aria_snapshot output contains non-cp1252 characters
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 72/100
- issue の種類
- ドキュメント
- 明瞭さ
- 明確に書かれている
- 活発さ
- 静か
- 技術スタック
- playwright, python
調査の方向性
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 はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/Webwright のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
persistent_local_browser broken on Windows: signal.SIGTERM and start_new_session are POSIX-only オープン
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
microsoft/Webwright の issue をすべて見る
似ている issue
-
triage/confirmed
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
agentscope-ai/agentscope#2775 ·
-
comp/desktop P3 type/bug
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
NousResearch/hermes-agent#118866 ·
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
apache/cloudstack#14222 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100