Skip to content

Commit

Permalink
Support for webp and optimizeForSpeed
Browse files Browse the repository at this point in the history
  • Loading branch information
nesty92 authored Dec 7, 2023
1 parent cc6726d commit aa793dc
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,15 +624,15 @@ public function screenshot(array $options = []): PageScreenshot
}

// make sure format is valid
if (!\in_array($screenshotOptions['format'], ['png', 'jpeg'])) {
throw new \InvalidArgumentException('Invalid options "format" for page screenshot. Format must be "png" or "jpeg".');
if (!\in_array($screenshotOptions['format'], ['png', 'jpeg', 'webp'])) {
throw new \InvalidArgumentException('Invalid options "format" for page screenshot. Format must be "png", "jpeg" or "webp".');
}

// get quality
if (\array_key_exists('quality', $options)) {
// quality requires type to be jpeg
if ('jpeg' !== $screenshotOptions['format']) {
throw new \InvalidArgumentException('Invalid options "quality" for page screenshot. Quality requires the image format to be "jpeg".');
// quality requires type to be jpeg or webp
if (!\in_array($screenshotOptions['format'], ['jpeg', 'webp'])) {
throw new \InvalidArgumentException('Invalid options "quality" for page screenshot. Quality requires the image format to be "jpeg" or "webp".');
}

// quality must be an integer
Expand Down Expand Up @@ -666,6 +666,15 @@ public function screenshot(array $options = []): PageScreenshot
];
}

// optimize for speed
if (\array_key_exists('optimizeForSpeed', $options)) {
if (!\is_bool($options['optimizeForSpeed'])) {
throw new \InvalidArgumentException('Invalid options "optimizeForSpeed" for page screenshot. OptimizeForSpeed must be a boolean value.');
}

$screenshotOptions['optimizeForSpeed'] = $options['optimizeForSpeed'];
}

// request screenshot
$responseReader = $this->getSession()
->sendMessage(new Message('Page.captureScreenshot', $screenshotOptions));
Expand Down

0 comments on commit aa793dc

Please sign in to comment.