Skip to content

[Bug]: APIResponse body/text/json don’t handle zstd #37032

Closed

Description

Version

1.54.0

Steps to reproduce

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch()
    context = browser.new_context()
    r = context.request.get("https://httpbin.dev/zstd")
    r.text()  # <-- raises UnicodeDecodeError

Expected behavior

API responses returned by APIRequestContext should transparently handle Content-Encoding:

  • body() returns decompressed bytes (same behavior as for gzip/br).
  • text() returns decoded text (respecting charset from Content-Type).
  • json() returns parsed JSON when applicable.

Actual behavior

  • body() returns compressed bytes for zstd.
  • text() attempts to decode compressed bytes and raises UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb5 in position 1: invalid start byte.

Additional context

Contrast with Page API, which returns decompressed content correctly:

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page()
    page.goto("https://httpbin.dev/zstd")
    print(page.content())
    browser.close()

Questions / request for guidance

  • What’s the recommended workaround to handle zstd for APIRequestContext?
    • Is there a built-in or recommended way to enable auto-decompression for zstd in APIRequestContext, similar to gzip/br?
    • Should users manually detect and decompress with the zstandard package before calling text()/json()?
  • Would you consider adding zstd auto-decompression to APIRequestContext or providing a hook to register custom decoders?

Environment

- Operating System: [Ubuntu 24.04]
- CPU: [x86_64]
- Browser: [All, Chromium, Firefox, WebKit]
- Python Version: [3.12]
- Other info:

Activity

  1. mxschmitt commented on Aug 14, 2025

    @mxschmitt
    Contributor
      pw:api => apiRequest.newContext started +0ms
      pw:api <= apiRequest.newContext succeeded +36ms
      pw:api => apiRequestContext.get started +2ms
      pw:api → GET https://httpbin.dev/zstd +5ms
      pw:api   user-agent: Playwright/1.55.0-next (arm64; macOS 15.6) node/22.15 +0ms
      pw:api   accept: */* +0ms
      pw:api   accept-encoding: gzip,deflate,br +0ms
      pw:api ← 200 OK +697ms
      pw:api   access-control-allow-credentials: true +1ms
      pw:api   access-control-allow-origin: * +0ms
      pw:api   alt-svc: h3=":443"; ma=2592000 +0ms
      pw:api   content-encoding: zstd +0ms
      pw:api   content-length: 231 +0ms
      pw:api   content-security-policy: frame-ancestors 'self' *.httpbin.dev; font-src 'self' *.httpbin.dev; default-src 'self' *.httpbin.dev; img-src 'self' *.httpbin.dev https://cdn.scrapfly.io; media-src 'self' *.httpbin.dev; object-src 'self' *.httpbin.dev https://web-scraping.dev; script-src 'self' 'unsafe-inline' 'unsafe-eval' *.httpbin.dev; style-src 'self' 'unsafe-inline' *.httpbin.dev https://unpkg.com; frame-src 'self' *.httpbin.dev https://web-scraping.dev; worker-src 'self' *.httpbin.dev; connect-src 'self' *.httpbin.dev +0ms
      pw:api   content-type: application/json; encoding=utf-8 +0ms
      pw:api   date: Thu, 14 Aug 2025 08:31:09 GMT +0ms
      pw:api   permissions-policy: fullscreen=(self), autoplay=*, geolocation=(), camera=() +0ms
      pw:api   referrer-policy: strict-origin-when-cross-origin +0ms
      pw:api   strict-transport-security: max-age=31536000; includeSubDomains; preload +0ms
      pw:api   x-content-type-options: nosniff +0ms
      pw:api   x-xss-protection: 1; mode=block +0ms
      pw:api <= apiRequestContext.get succeeded +3ms
    

    Strictly speaking the client does not announce that it supports zstd (Accept-Encoding header) and the server still responds with it. This doesn't seem right but we can make a feature request out of it to support it.

  2. dvukolovAC commented on Aug 14, 2025

    @dvukolovAC
    Author

    Thank you, it would be great to have support for zstd-compressed response out of the box. This particular endpoint is forcefully returning ztd-compressed content for testing purposes. I encountered the original issue with a regular website and the client announcing support for zstd.

  3. pavelfeldman commented on Apr 28, 2026

    @pavelfeldman
    Member

    Why was this issue closed?

    Thank you for your contribution to our project. This issue has been closed due to its limited upvotes and recent activity, and insufficient feedback for us to effectively act upon. Our priority is to focus on bugs that reflect higher user engagement and have actionable feedback, to ensure our bug database stays manageable.

    Should you feel this closure was in error, please create a new issue and reference this one. We're open to revisiting it given increased support or additional clarity. Your understanding and cooperation are greatly appreciated.

  4. pavelfeldman commented on May 4, 2026

    @pavelfeldman
    Member

    Why was this issue closed?

    Thank you for your contribution to our project. This issue has been closed due to its limited upvotes and recent activity, and insufficient feedback for us to effectively act upon. Our priority is to focus on bugs that reflect higher user engagement and have actionable feedback, to ensure our bug database stays manageable.

    Should you feel this closure was in error, please create a new issue and reference this one. We're open to revisiting it given increased support or additional clarity. Your understanding and cooperation are greatly appreciated.

  5. cooper667 commented on Jul 27, 2026

    @cooper667

    Is it documented zstd isn't supported?

    i'm intercepting on firefox (which sends Accept-Encoding: zstd) and await response.text() is (�/��X\���c7o��%� ���긌�=U�... (no UnicodeDecodeError) rather than the expected text (which actual firefox decodes).

    Currently handled by removing zstd in the request headers before fetching, but would rather not have to

    Playwright version: 1.61.1
      Browsers:
        ms-playwright/chromium-1228
        ms-playwright/chromium_headless_shell-1228
        ms-playwright/ffmpeg-1011
        ms-playwright/firefox-1532
        ms-playwright/webkit-2311
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions