Version
main branch as of 2026-06-09
Steps to reproduce
Send a request with binary bytes that are not valid UTF-8, then read request.post_data:
async with page.expect_request("**/upload") as request_info:
await page.evaluate("""
() => fetch('/upload', {
method: 'POST',
body: new Uint8Array([255, 254])
})
""")
request = await request_info.value
print(request.post_data)
Expected behavior
request.post_data should not crash. It can return a best-effort UTF-8 string, while request.post_data_buffer remains the exact binary-safe API.
This would match JavaScript behavior, where Buffer.toString("utf-8") replaces invalid bytes instead of throwing.
Actual behavior
Python decodes request body bytes with strict UTF-8 decoding, so request.post_data can raise:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff ...
Potential fix direction
Decode text post data with replacement, for example decode("utf-8", errors="replace"), and add a regression test that verifies:
request.post_data does not raise for invalid UTF-8 bytes
request.post_data_buffer still returns the exact original bytes
Version
main branch as of 2026-06-09
Steps to reproduce
Send a request with binary bytes that are not valid UTF-8, then read
request.post_data:Expected behavior
request.post_datashould not crash. It can return a best-effort UTF-8 string, whilerequest.post_data_bufferremains the exact binary-safe API.This would match JavaScript behavior, where
Buffer.toString("utf-8")replaces invalid bytes instead of throwing.Actual behavior
Python decodes request body bytes with strict UTF-8 decoding, so
request.post_datacan raise:Potential fix direction
Decode text post data with replacement, for example
decode("utf-8", errors="replace"), and add a regression test that verifies:request.post_datadoes not raise for invalid UTF-8 bytesrequest.post_data_bufferstill returns the exact original bytes