Skip to content

fix: force UTF-8 stdout in Playwright patterns to prevent UnicodeEncodeError on Windows#52

Open
C1-BA-B1-F3 wants to merge 1 commit into
microsoft:mainfrom
C1-BA-B1-F3:fix/unicode-stdout-error
Open

fix: force UTF-8 stdout in Playwright patterns to prevent UnicodeEncodeError on Windows#52
C1-BA-B1-F3 wants to merge 1 commit into
microsoft:mainfrom
C1-BA-B1-F3:fix/unicode-stdout-error

Conversation

@C1-BA-B1-F3

Copy link
Copy Markdown

Summary

Forces UTF-8 stdout encoding in the canonical Playwright code skeletons to prevent UnicodeEncodeError on Windows.

Problem

On Windows, Python defaults sys.stdout.encoding to cp1252. When aria_snapshot() returns characters outside that codepage (CJK, math symbols, typography glyphs like ▽), the print() call crashes:

UnicodeEncodeError: 'charmap' codec can't encode character '▽'

A Windows user copy-pasting the recommended skeleton from Webwright's own reference doc will hit this on the first non-trivial page.

Fix

Added sys.stdout.reconfigure(encoding="utf-8") to both code skeletons:

  • Browser launch skeleton (line ~18)
  • Final-script instrumentation example (line ~131)

This is a no-op on POSIX where stdout is already UTF-8, so it's fully portable.

Fixes #7

…deError on Windows

On Windows, Python defaults sys.stdout.encoding to cp1252, which crashes
when aria_snapshot() returns characters outside that codepage (e.g. CJK,
math symbols, typography glyphs). Adding sys.stdout.reconfigure(encoding='utf-8')
to the canonical code skeletons makes the patterns portable.

Fixes microsoft#7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants