From 00fa75ec9eaa8a9888ad124a0db7d21828f57546 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Mon, 25 Mar 2024 09:30:56 +0100 Subject: [PATCH] docs: mention issues with buffer encoding (#12141) --- docs/api/puppeteer.httpresponse.buffer.md | 4 ++++ docs/api/puppeteer.httpresponse.md | 2 +- docs/api/puppeteer.httpresponse.text.md | 2 +- packages/puppeteer-core/src/api/HTTPResponse.ts | 9 ++++++++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/api/puppeteer.httpresponse.buffer.md b/docs/api/puppeteer.httpresponse.buffer.md index 72c646b62a9..887fc6f024c 100644 --- a/docs/api/puppeteer.httpresponse.buffer.md +++ b/docs/api/puppeteer.httpresponse.buffer.md @@ -17,3 +17,7 @@ class HTTPResponse { **Returns:** Promise<Buffer> + +## Remarks + +The buffer might be re-encoded by the browser based on HTTP-headers or other heuristics. If the browser failed to detect the correct encoding, the buffer might be encoded incorrectly. See https://github.com/puppeteer/puppeteer/issues/6478. diff --git a/docs/api/puppeteer.httpresponse.md b/docs/api/puppeteer.httpresponse.md index 3e6b53d524b..f294b0dbdea 100644 --- a/docs/api/puppeteer.httpresponse.md +++ b/docs/api/puppeteer.httpresponse.md @@ -171,7 +171,7 @@ The status text of the response (e.g. usually an "OK" for a success). -Promise which resolves to a text representation of response body. +Promise which resolves to a text (utf8) representation of response body. diff --git a/docs/api/puppeteer.httpresponse.text.md b/docs/api/puppeteer.httpresponse.text.md index 9e040a3f0d5..88499b6d73f 100644 --- a/docs/api/puppeteer.httpresponse.text.md +++ b/docs/api/puppeteer.httpresponse.text.md @@ -4,7 +4,7 @@ sidebar_label: HTTPResponse.text # HTTPResponse.text() method -Promise which resolves to a text representation of response body. +Promise which resolves to a text (utf8) representation of response body. #### Signature: diff --git a/packages/puppeteer-core/src/api/HTTPResponse.ts b/packages/puppeteer-core/src/api/HTTPResponse.ts index 906479eb43a..f5ea35722e2 100644 --- a/packages/puppeteer-core/src/api/HTTPResponse.ts +++ b/packages/puppeteer-core/src/api/HTTPResponse.ts @@ -81,11 +81,18 @@ export abstract class HTTPResponse { /** * Promise which resolves to a buffer with response body. + * + * @remarks + * + * The buffer might be re-encoded by the browser + * based on HTTP-headers or other heuristics. If the browser + * failed to detect the correct encoding, the buffer might + * be encoded incorrectly. See https://github.com/puppeteer/puppeteer/issues/6478. */ abstract buffer(): Promise; /** - * Promise which resolves to a text representation of response body. + * Promise which resolves to a text (utf8) representation of response body. */ async text(): Promise { const content = await this.buffer();