fix(skill): force utf-8 stdout in playwright_patterns.md to prevent Windows cp1252 crash
Summary
Fixes #7 — the canonical Python skeletons in skills/webwright/reference/playwright_patterns.md crash with UnicodeEncodeError on Windows the moment aria_snapshot() (or any other page text passed to print()) contains a glyph outside cp1252.
Two real-world cases that already trigger it:
- arxiv search results page — the "▽ More" abstract toggle is
U+25BD - Any page with typography symbols, emoji, CJK characters, math symbols, etc.
A Windows user copy-pasting the recommended explore skeleton from the doc hits the crash on the first non-trivial page. See issue #7 for the verbatim repro + traceback.
Changes
Single file: skills/webwright/reference/playwright_patterns.md.
- Browser launch skeleton — add
import sysandsys.stdout.reconfigure(encoding=\"utf-8\")near the top of the heredoc with an inline comment explaining why. - Final-script instrumentation — same reconfigure at the top, plus pass
encoding=\"utf-8\"explicitly toLOG.write_text(...)andLOG.open(\"a\", ...)so non-cp1252 glyphs landing in the log file cannot crash on Windows either. - Rules section — added a short "Windows note" describing the line and the equivalent
PYTHONIOENCODING=utf-8environment override.
The reconfigure is a no-op on POSIX where stdout is already utf-8, so the skeletons keep working unchanged on Linux/macOS.
Verification
Without the fix (verbatim heredoc from the doc, default Windows cp1252 stdout):
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]
With the fix on the same arxiv search results page:
ARIA: <full accessibility tree printed cleanly, U+25BD included>
exit code: 0
Test plan
- [x] Confirmed verbatim heredoc from the pre-fix doc crashes on Windows 11 + Python 3.12 + Playwright Firefox.
- [x] Confirmed the patched skeleton runs clean on the same machine, same page.
- [x] Verified the change is a no-op on POSIX (reconfigure to utf-8 when already utf-8 changes nothing).
- [x] Ran the full Webwright arxiv-search task end-to-end with the patched Final-script skeleton — all critical points verified, no encoding errors in log or stdout.
@microsoft-github-policy-service agree