[Regression]: APIRequestContext JSON-encodes string data for "application/json;charset=UTF-8" since 1.65 (not in release notes)

Cerrado Apto para principiantes
#43,937 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@microsoft-playwright-automation ya está trabajando en esto.

Desde el 5/11/2026.

  • #43945 de @microsoft-playwright-automation — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
74/100
Tipo de issue
Documentación
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
node.js, playwright, typescript

Línea de trabajo

Empieza por la documentación de APIRequestContext sobre la opción data y las notas de la versión 1.65; el issue menciona ambas actualizaciones solicitadas, pero no indica rutas de archivos. Comprueba cómo describen la documentación los cuerpos de tipo string y las notas de la versión los breaking changes; después, aclara el comportamiento del tipo de contenido JSON y menciona Buffer para obtener los bytes exactos. La tarea estará terminada cuando ambas actualizaciones reflejen con precisión el comportamiento notificado.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

needs-triage
Version

1.65.0 (same in 1.66.0-alpha-2026-11-05). Different in 1.64.1.

Steps to reproduce
// repro.mjs — "type": "module", @playwright/test installed
import http from 'node:http';
import { request } from '@playwright/test';

const srv = http.createServer((req, res) => { let b = ''; req.on('data', c => b += c); req.on('end', () => res.end(b)); });
await new Promise(r => srv.listen(0, r));
const url = `http://127.0.0.1:${srv.address().port}/`;
const ctx = await request.newContext();

for (const ct of ['application/json', 'application/json;charset=UTF-8', 'application/json; charset=utf-8', 'Application/JSON', 'application/problem+json']) {
  const r = await ctx.post(url, { data: 'plain text', headers: { 'content-type': ct } });
  console.log(ct, '->', JSON.stringify(await r.text()));
}
await ctx.dispose(); srv.close();
Expected behavior

Either the 1.64 behavior, or the change to be listed in the release notes. In 1.64.1 only an exact application/json header made Playwright JSON-encode a string data that is not valid JSON:

application/json                -> "\"plain text\""
application/json;charset=UTF-8  -> "plain text"
application/json; charset=utf-8 -> "plain text"
Application/JSON                -> "plain text"
application/problem+json        -> "plain text"
Actual behavior

In 1.65.0 the JSON content type is matched with parameters and case-insensitively, so the string is now JSON-encoded for these headers too:

application/json                -> "\"plain text\""
application/json;charset=UTF-8  -> "\"plain text\""
application/json; charset=utf-8 -> "\"plain text\""
Application/JSON                -> "\"plain text\""
application/problem+json        -> "plain text"

A string that parses as JSON ('{"a":1}') and a Buffer are sent as is in both versions.

Additional context

The new matching looks more correct, but it silently changes the request body. It is not mentioned in the 1.65 release notes.

What broke for us:

  • Negative API tests that send a deliberately malformed JSON body as a string (data: '{"a": ' with content-type: application/json;charset=UTF-8). The server now receives a valid JSON string literal instead of a malformed document, so the test checks something else (400 "Syntax error" becomes a different response).
  • Requests signed with HMAC over the raw body string: the signature is computed over {"a": , but "{\"a\": " is sent, so the server answers 401.

Our workaround is data: Buffer.from(body).

Requests:

  1. Please add this to the 1.65 breaking changes.
  2. Please document in APIRequestContext data that a string with a JSON content type is sent as is only when it parses as JSON, and is JSON-encoded otherwise. The docs currently read as if strings are always sent as is. Buffer is the way to send exact bytes.
Environment
OS: Linux (mcr.microsoft.com/playwright:v1.65.0-noble)
Node.js: 26.13.0
@playwright/test: 1.65.0
Lenguaje dominante
TypeScript
Estrellas
99.1k
Forks
6.8k
Merge medio
17 h 6 min
PR fusionados (30 d)
306

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/playwright

Todos los issues de microsoft/playwright

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.