diff --git a/packages/playwright-core/src/server/registry/download.ts b/packages/playwright-core/src/server/registry/download.ts index 0aba083619..d4c2065aab 100644 --- a/packages/playwright-core/src/server/registry/download.ts +++ b/packages/playwright-core/src/server/registry/download.ts @@ -48,10 +48,17 @@ function downloadFile(url: string, destinationPath: string, options: DownloadFil }, response => { log(`-- response status code: ${response.statusCode}`); if (response.statusCode !== 200) { - const error = new Error(`Download failed: server returned code ${response.statusCode}. URL: ${url}`); - // consume response data to free up memory - response.resume(); - fulfill({ error }); + let content = ''; + const handleError = () => { + const error = new Error(`Download failed: server returned code ${response.statusCode} body '${content}'. URL: ${url}`); + // consume response data to free up memory + response.resume(); + fulfill({ error }); + }; + response + .on('data', chunk => content += chunk) + .on('end', handleError) + .on('error', handleError); return; } const file = fs.createWriteStream(destinationPath);