Webwright icon indicating copy to clipboard operation
Webwright copied to clipboard

fix(skill): force utf-8 stdout in playwright_patterns.md to prevent Windows cp1252 crash

Open raykuo998 opened this issue 6 months ago • 1 comments

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.

  1. Browser launch skeleton — add import sys and sys.stdout.reconfigure(encoding=\"utf-8\") near the top of the heredoc with an inline comment explaining why.
  2. Final-script instrumentation — same reconfigure at the top, plus pass encoding=\"utf-8\" explicitly to LOG.write_text(...) and LOG.open(\"a\", ...) so non-cp1252 glyphs landing in the log file cannot crash on Windows either.
  3. Rules section — added a short "Windows note" describing the line and the equivalent PYTHONIOENCODING=utf-8 environment 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.

raykuo998 avatar May 26 '26 21:05 raykuo998

@microsoft-github-policy-service agree

raykuo998 avatar May 26 '26 21:05 raykuo998