Skip to content

[Bug]: APIRequestContext ignores charset parameter when detecting JSON content type #43388

Closed

Description

@alok-108

Version

Playwright 1.65.0-next, commit 4357c237c.

Steps to reproduce

Using APIRequestContext, send a string with a JSON content type that includes a standard charset parameter:

const [serverRequest] = await Promise.all([
  server.waitForRequest('/echo'),
  request.post(server.EMPTY_PAGE, {
    headers: { 'content-type': 'application/json; charset=utf-8' },
    data: 'hello',
  }),
]);
console.log((await serverRequest.postBody).toString());

Expected behavior

The body is JSON-serialized as it is when the content type is exactly application/json: "hello".

Actual behavior

The body is sent as the raw string hello. In packages/playwright-core/src/client/fetch.ts, isJsonContentType checks for an exact value of application/json, so it does not recognize application/json; charset=utf-8. The string then takes the non-JSON branch instead of being JSON-serialized.

Environment

Node.js v22.14.0; Windows. I executed the current isJsonContentType source helper directly and confirmed that it returns false for application/json; charset=utf-8 and true for application/json. I have not run the request through a live APIRequestContext integration test.

Activity

  1. alok-108 commented on Oct 14, 2026

    @alok-108
    ContributorAuthor

    I traced this through the APIRequestContext body handling. With data: 'hello', the JSON path is selected only when the Content-Type value is exactly application/json. I checked the helper with both application/json and application/json; charset=utf-8: the first is recognized, but the second is not, so it takes the raw-string path instead of JSON serialization.

    I have verified the branch selection in the current source, but have not run this through a live APIRequestContext request yet.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions