Skip to content

Commit

Permalink
Update handling of browser output for Puppeteer ^23.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
anders-itpilot authored and freekmurze committed Aug 20, 2024
1 parent 1ff65aa commit dbc8c71
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions bin/browser.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ const getOutput = async (request, page = null) => {
output.result = await page.evaluate(request.options.pageFunction);
} else {
const result = await page[request.action](request.options);
const resultBuffer = Buffer.from(result);

// Ignore output result when saving to a file
output.result = request.options.path ? '' : result.toString('base64');
if (request.action === 'screenshot') {
output.result = resultBuffer.toString('base64');
} else {
// Ignore output result when saving to a file
output.result = request.options.path ? '' : resultBuffer.toString();
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Browsershot.php
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ public function pdf(): string

$this->cleanupTemporaryHtmlFile();

return base64_decode($encodedPdf);
return $encodedPdf;
}

public function savePdf(string $targetPath)
Expand All @@ -694,11 +694,11 @@ public function base64pdf(): string
{
$command = $this->createPdfCommand();

$encodedPdf = $this->callBrowser($command);
$pdf = $this->callBrowser($command);

$this->cleanupTemporaryHtmlFile();

return $encodedPdf;
return base64_encode($pdf);
}

public function evaluate(string $pageFunction): string
Expand Down

0 comments on commit dbc8c71

Please sign in to comment.